@agent-deck/backend 1.10.6 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/data/oauth-provider-guides.js +1 -1
- package/dist/data/oauth-provider-guides.js.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +27 -2
- package/dist/mcp-server.js.map +1 -1
- package/dist/mcp-session-binding.d.ts +18 -0
- package/dist/mcp-session-binding.d.ts.map +1 -1
- package/dist/mcp-session-binding.js +25 -0
- package/dist/mcp-session-binding.js.map +1 -1
- package/dist/mcp-tools/elicitation.d.ts +129 -0
- package/dist/mcp-tools/elicitation.d.ts.map +1 -0
- package/dist/mcp-tools/elicitation.js +231 -0
- package/dist/mcp-tools/elicitation.js.map +1 -0
- package/dist/mcp-tools/policy.d.ts.map +1 -1
- package/dist/mcp-tools/policy.js +2 -0
- package/dist/mcp-tools/policy.js.map +1 -1
- package/dist/mcp-tools/register.d.ts +14 -0
- package/dist/mcp-tools/register.d.ts.map +1 -1
- package/dist/mcp-tools/register.js +109 -129
- package/dist/mcp-tools/register.js.map +1 -1
- package/dist/playbooks/stub-sync.d.ts +55 -12
- package/dist/playbooks/stub-sync.d.ts.map +1 -1
- package/dist/playbooks/stub-sync.js +136 -197
- package/dist/playbooks/stub-sync.js.map +1 -1
- package/dist/routes/trusted-session.d.ts.map +1 -1
- package/dist/routes/trusted-session.js +240 -6
- package/dist/routes/trusted-session.js.map +1 -1
- package/dist/trusted-session/route-policy-registry.d.ts.map +1 -1
- package/dist/trusted-session/route-policy-registry.js +22 -0
- package/dist/trusted-session/route-policy-registry.js.map +1 -1
- package/dist/trusted-session/store.d.ts +174 -2
- package/dist/trusted-session/store.d.ts.map +1 -1
- package/dist/trusted-session/store.js +459 -2
- package/dist/trusted-session/store.js.map +1 -1
- package/package.json +2 -2
- package/static-ui/assets/{index-BArFQUL8.js → index-B86VjIYT.js} +4 -4
- package/static-ui/assets/index-DlL_F4GS.css +1 -0
- package/static-ui/index.html +2 -2
- package/static-ui/assets/index-CbccleVj.css +0 -1
|
@@ -27,7 +27,7 @@ Error generating stack: `+e.message+`
|
|
|
27
27
|
relative overflow-hidden
|
|
28
28
|
${Bl(t)}
|
|
29
29
|
${r?`hover:scale-110 hover:rotate-0`:`hover:scale-105`}
|
|
30
|
-
`,style:{borderColor:f,boxShadow:`0 0 20px ${f}20`},children:[(0,V.jsx)(Il,{warnings:l}),t&&(0,V.jsx)(Vl,{}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:f},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:f},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200 z-10`,children:(0,V.jsx)(G,{size:`sm`,variant:`destructive`,className:`h-5 w-5 p-0 bg-red-500/80 hover:bg-red-500 border-red-400`,onClick:t=>{t.stopPropagation(),window.confirm(`Delete playbook "${e.title}"?`)&&h.mutate()},title:`Delete ${e.title}`,children:(0,V.jsx)(Hi,{className:`w-3 h-3`})})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:f},children:(0,V.jsx)(fi,{className:`h-7 w-7`,strokeWidth:2.25})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:f},children:e.title}),(0,V.jsxs)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:f,borderColor:f},children:[`Playbook`,p>0?` · ${p} deps`:``]})]}),(0,V.jsx)(`div`,{className:`absolute bottom-6 inset-x-1`,children:(0,V.jsx)(G,{size:`sm`,className:`w-full text-[8px] px-1 py-1 h-5 bg-black/20 hover:bg-black/40 border`,style:{color:f,borderColor:f},onClick:e=>{e.stopPropagation(),m.mutate()},disabled:t||m.isPending||!n,children:t?`IN DECK`:`ADD`})}),(0,V.jsx)(`div`,{className:`absolute inset-0 rounded-lg bg-gradient-to-br from-transparent via-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-500 pointer-events-none`})]})})}var Yl=(0,b.memo)(Jl),Xl=64,Zl=4,Ql=12,$l=1.08;function eu(e=Ql,t=$l){let n=e*Math.PI/180,r=128*Math.sin(n)+192*Math.cos(n);return Math.ceil(r*t)+8}var tu=eu();function nu(e,t=48){return e===0?0:128+Math.max(0,e-1)*(128-t)}function ru(e=10,t=48,n=12){return nu(e,t)+2*n}function iu(e,t=48){return nu(e,t)+24}var au=ru();function ou(e,t,n,r=Ql){let i=t+n/2,a=n/2;if(a<=0)return 0;let o=(e-i)/a;return Math.max(-r,Math.min(r,o*r))}function su(e){return{flexShrink:0,marginLeft:e===0?0:`-48px`}}function cu(e,t,n){return n===e?999999:t-e}function lu({cardCount:e,children:t}){let n=(0,b.useRef)(null),r=(0,b.useRef)([]),i=(0,b.useRef)(0),a=(0,b.useRef)(void 0),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(!1),g=(0,b.useRef)(!1),_=(0,b.useRef)(!1),[v,y]=(0,b.useState)(null),x=(0,b.useRef)(null);x.current=v;let S=(0,b.useCallback)(()=>{let t=n.current;if(!t)return;let i=t.getBoundingClientRect(),a=x.current;r.current.forEach((t,n)=>{if(!t)return;let r=t.getBoundingClientRect(),o=r.left+r.width/2,s=a===n?0:ou(o,i.left,i.width),c=a===n?$l:1;t.style.transform=`rotate(${s}deg) scale(${c})`,t.style.transformOrigin=`center center`,t.style.zIndex=String(cu(n,e,a))})},[e]),C=(0,b.useCallback)(e=>{let t=n.current;t&&t.scrollBy({left:e===`left`?-80:80,behavior:`smooth`})},[]),w=(0,b.useCallback)(()=>{let t=n.current;if(!t)return;let r=iu(e,48)>t.clientWidth+2;s(r),l(r&&t.scrollLeft>4),d(r&&t.scrollLeft+t.clientWidth<t.scrollWidth-4),S()},[e,S]);(0,b.useLayoutEffect)(()=>{let e=n.current;if(!e)return;w();let t=new ResizeObserver(w);return t.observe(e),e.addEventListener(`scroll`,w,{passive:!0}),()=>{t.disconnect(),e.removeEventListener(`scroll`,w)}},[e,w]),(0,b.useEffect)(()=>{let e=()=>{let t=n.current,r=i.current;if(t&&r!==0){t.scrollLeft+=r,S();let e=t.scrollLeft>4,n=t.scrollLeft+t.clientWidth<t.scrollWidth-4;l(e),d(n)}let o=r<0,s=r>0;o!==g.current&&(g.current=o,p(o)),s!==_.current&&(_.current=s,h(s)),a.current=requestAnimationFrame(e)};return a.current=requestAnimationFrame(e),()=>{a.current!==void 0&&cancelAnimationFrame(a.current)}},[S]);let T=e=>{let t=n.current;if(!t||!o){i.current=0;return}let r=t.getBoundingClientRect(),a=e.clientX-r.left;if(a<Xl&&c){let e=1-a/Xl;i.current=-(Zl+e*10)}else if(a>r.width-Xl&&u){let e=1-(r.width-a)/Xl;i.current=Zl+e*10}else i.current=0;S()},E=()=>{i.current=0,g.current=!1,_.current=!1,p(!1),h(!1)};if((0,b.useLayoutEffect)(()=>{r.current.length=e,S()},[e,v,S]),e===0)return(0,V.jsx)(V.Fragment,{children:t});let D=(e,t)=>`absolute ${e===`left`?`left-2`:`right-2`} top-1/2 z-30 -translate-y-1/2 rounded-full bg-gray-950/90 p-1.5 text-yellow-300 shadow-lg ring-1 ring-black/50 transition-all duration-150 hover:bg-gray-950 hover:ring-yellow-300/40 ${t?`scale-110`:`scale-100`}`;return(0,V.jsxs)(`div`,{className:`relative flex h-full w-full min-w-0 max-w-full items-center justify-center overflow-hidden`,"data-testid":`deck-fan`,onMouseMove:T,onMouseLeave:E,children:[o&&c&&(0,V.jsx)(`button`,{type:`button`,className:D(`left`,f),"aria-label":`Scroll deck left`,"data-testid":`deck-scroll-left`,onClick:()=>C(`left`),children:(0,V.jsx)(_i,{className:`h-6 w-6`,strokeWidth:2.5})}),o&&u&&(0,V.jsx)(`button`,{type:`button`,className:D(`right`,m),"aria-label":`Scroll deck right`,"data-testid":`deck-scroll-right`,onClick:()=>C(`right`),children:(0,V.jsx)(vi,{className:`h-6 w-6`,strokeWidth:2.5})}),(0,V.jsx)(`div`,{ref:n,className:`max-w-full overflow-x-auto overflow-y-visible [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,style:{width:au,maxWidth:`100%`},children:(0,V.jsx)(`div`,{className:`flex items-center justify-start isolate group/fan`,style:{minHeight:tu,paddingLeft:12,paddingRight:12},children:b.Children.map(t,(e,t)=>(0,V.jsx)(`div`,{ref:e=>{r.current[t]=e},className:`relative flex items-center justify-center transition-[transform,box-shadow] duration-500 will-change-transform`,style:{...su(t),minHeight:tu},onMouseEnter:()=>y(t),onMouseLeave:()=>y(null),children:e},e&&typeof e==`object`&&`key`in e?e.key:t))})})]})}var uu=b.forwardRef(({className:e,type:t,...n},r)=>(0,V.jsx)(`input`,{type:t,className:W(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,e),ref:r,...n}));uu.displayName=`Input`;function du({deck:e,services:t,credentials:n=[],playbooks:r=[],collectionWarnings:i,onDrop:a,onDragStart:o,onCredentialDragStart:s,onPlaybookDragStart:c,onDragEnd:l,onCardClick:u,onPlaybookClick:d,onCredentialClick:f}){let[p,m]=(0,b.useState)(!1),[h,g]=(0,b.useState)(e.name),_=(0,b.useRef)(null),v=Et(),{toast:y}=on();(0,b.useEffect)(()=>{g(e.name),m(!1)},[e.id,e.name]),(0,b.useEffect)(()=>{p&&(_.current?.focus(),_.current?.select())},[p]);let x=Ht({mutationFn:async t=>(await H(`PUT`,`/api/decks/${e.id}`,{name:t})).json(),onSuccess:e=>{if(!e.success)throw Error(e.error||`Rename failed`);v.invalidateQueries({queryKey:[`/api/decks`]}),m(!1)},onError:t=>{g(e.name),m(!1),y({title:`Could not rename deck`,description:t.message,variant:`destructive`})}}),S=()=>{let t=h.trim();if(!t||t===e.name){g(e.name),m(!1);return}x.mutate(t)},C=e=>{e.preventDefault(),a(e)},w=e=>{e.preventDefault()},T=t.length+n.length+r.length;return(0,V.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col overflow-hidden`,children:[(0,V.jsxs)(`h3`,{className:`mb-4 flex min-w-0 shrink-0 items-center text-lg font-bold`,children:[(0,V.jsx)(`i`,{className:`fas fa-layer-group mr-2 text-blue-400`}),`Deck`,p?(0,V.jsx)(uu,{ref:_,value:h,disabled:x.isPending,onChange:e=>g(e.target.value),onBlur:S,onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),S()):t.key===`Escape`&&(t.preventDefault(),g(e.name),m(!1))},className:`ml-2 h-7 max-w-[12rem] border-white/20 bg-white/10 px-2 text-sm font-normal text-white sm:max-w-[16rem]`,"data-testid":`input-deck-name`,"aria-label":`Deck name`}):(0,V.jsx)(`button`,{type:`button`,className:`ml-2 min-w-0 truncate text-left text-sm font-normal text-gray-400 hover:text-white hover:underline`,title:`Click to rename`,onClick:()=>m(!0),"data-testid":`button-rename-deck`,children:e.name}),(0,V.jsxs)(`span`,{className:`ml-2 shrink-0 text-sm font-normal text-gray-400`,children:[`(`,T,` cards)`]})]}),(0,V.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden rounded-xl border-2 border-dashed px-4 py-2 min-w-0`,onDrop:C,onDragOver:w,style:{background:`linear-gradient(135deg, rgba(196, 182, 67, 0.1), rgba(212, 199, 96, 0.1))`,borderColor:`rgba(196, 182, 67, 0.3)`},"data-testid":`deck-drop-zone`,children:(0,V.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden min-w-0`,children:T===0?(0,V.jsx)(`div`,{className:`flex items-center justify-center`,style:{minHeight:tu},children:(0,V.jsx)(`div`,{className:`flex items-center justify-center rounded-lg border-2 border-dashed border-gray-500 opacity-50 transition-opacity hover:opacity-75`,style:{width:128,height:192},"data-testid":`deck-empty-placeholder`,children:(0,V.jsx)(Ii,{className:`h-8 w-8 text-gray-500`})})}):(0,V.jsxs)(lu,{cardCount:T,children:[n.map((e,t)=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:Al,boxShadow:`0 0 20px ${Al}20`},draggable:!0,onDragStart:t=>s(t,e,!0),onDragEnd:l,onClick:()=>f?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.credentialWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Al},children:`AK`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Al},children:`AK`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:Al},children:(0,V.jsx)(Gl,{credential:e,color:Al})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:Al},children:e.label}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:Al,borderColor:Al},children:e.hasSecret?`API Key`:`Missing key`})]})]},e.id)),r.map((e,t)=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:jl,boxShadow:`0 0 20px ${jl}20`},draggable:!0,onDragStart:t=>c(t,e,!0),onDragEnd:l,onClick:()=>d?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.playbookWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:jl},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:jl},children:`PB`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:jl},children:(0,V.jsx)(fi,{className:`h-7 w-7`,strokeWidth:2.25})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:jl},children:e.title}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:jl,borderColor:jl},children:`Playbook`})]})]},e.id)),t.map(e=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:Nl(e),boxShadow:`0 0 20px ${Nl(e)}20`},draggable:!0,onDragStart:t=>o(t,e,!0),onDragEnd:l,onClick:()=>u?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.serviceWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Nl(e)},children:e.type===`mcp`?`RM`:e.type===`local-mcp`?`LM`:`A`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Nl(e)},children:e.type===`mcp`?`RM`:e.type===`local-mcp`?`LM`:`A`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:Nl(e)},children:(0,V.jsx)(zl,{service:e})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:Nl(e)},children:e.name}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:Nl(e),borderColor:Nl(e)},children:e.type===`mcp`?`Remote MCP`:e.type===`local-mcp`?`Local MCP`:`A2A`})]})]},e.id))]})})})]})}var fu=0;function pu(){b.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??mu()),document.body.insertAdjacentElement(`beforeend`,e[1]??mu()),fu++,()=>{fu===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),fu--}},[])}function mu(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var hu=`focusScope.autoFocusOnMount`,gu=`focusScope.autoFocusOnUnmount`,_u={bubbles:!1,cancelable:!0},vu=`FocusScope`,yu=b.forwardRef((e,t)=>{let{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...o}=e,[s,c]=b.useState(null),l=Tn(i),u=Tn(a),d=b.useRef(null),f=un(t,e=>c(e)),p=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(r){let e=function(e){if(p.paused||!s)return;let t=e.target;s.contains(t)?d.current=t:Eu(d.current,{select:!0})},t=function(e){if(p.paused||!s)return;let t=e.relatedTarget;t!==null&&(s.contains(t)||Eu(d.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&Eu(s)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return s&&r.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,s,p.paused]),b.useEffect(()=>{if(s){Du.add(p);let e=document.activeElement;if(!s.contains(e)){let t=new CustomEvent(hu,_u);s.addEventListener(hu,l),s.dispatchEvent(t),t.defaultPrevented||(bu(Au(Su(s)),{select:!0}),document.activeElement===e&&Eu(s))}return()=>{s.removeEventListener(hu,l),setTimeout(()=>{let t=new CustomEvent(gu,_u);s.addEventListener(gu,u),s.dispatchEvent(t),t.defaultPrevented||Eu(e??document.body,{select:!0}),s.removeEventListener(gu,u),Du.remove(p)},0)}}},[s,l,u,p]);let m=b.useCallback(e=>{if(!n&&!r||p.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=xu(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&Eu(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&Eu(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,p.paused]);return(0,V.jsx)(Cn.div,{tabIndex:-1,...o,ref:f,onKeyDown:m})});yu.displayName=vu;function bu(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(Eu(r,{select:t}),document.activeElement!==n)return}function xu(e){let t=Su(e);return[Cu(t,e),Cu(t.reverse(),e)]}function Su(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Cu(e,t){for(let n of e)if(!wu(n,{upTo:t}))return n}function wu(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function Tu(e){return e instanceof HTMLInputElement&&`select`in e}function Eu(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Tu(e)&&t&&e.select()}}var Du=Ou();function Ou(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=ku(e,t),e.unshift(t)},remove(t){e=ku(e,t),e[0]?.resume()}}}function ku(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Au(e){return e.filter(e=>e.tagName!==`A`)}var ju=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Mu=new WeakMap,Nu=new WeakMap,Pu={},Fu=0,Iu=function(e){return e&&(e.host||Iu(e.parentNode))},Lu=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Iu(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},Ru=function(e,t,n,r){var i=Lu(t,Array.isArray(e)?e:[e]);Pu[n]||(Pu[n]=new WeakMap);var a=Pu[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Mu.get(e)||0)+1,l=(a.get(e)||0)+1;Mu.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Nu.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Fu++,function(){o.forEach(function(e){var t=Mu.get(e)-1,i=a.get(e)-1;Mu.set(e,t),a.set(e,i),t||(Nu.has(e)||e.removeAttribute(r),Nu.delete(e)),i||e.removeAttribute(n)}),Fu--,Fu||(Mu=new WeakMap,Mu=new WeakMap,Nu=new WeakMap,Pu={})}},zu=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||ju(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),Ru(r,i,n,`aria-hidden`)):function(){return null}},Bu=function(){return Bu=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Bu.apply(this,arguments)};function Vu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Hu(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var Uu=`right-scroll-bar-position`,Wu=`width-before-scroll-bar`,Gu=`with-scroll-bars-hidden`,Ku=`--removed-body-scroll-bar-size`;function qu(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Ju(e,t){var n=(0,b.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var Yu=typeof window<`u`?b.useLayoutEffect:b.useEffect,Xu=new WeakMap;function Zu(e,t){var n=Ju(t||null,function(t){return e.forEach(function(e){return qu(e,t)})});return Yu(function(){var t=Xu.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||qu(e,null)}),i.forEach(function(e){r.has(e)||qu(e,a)})}Xu.set(n,e)},[e]),n}function Qu(e){return e}function $u(e,t){t===void 0&&(t=Qu);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function ed(e){e===void 0&&(e={});var t=$u(null);return t.options=Bu({async:!0,ssr:!1},e),t}var td=function(e){var t=e.sideCar,n=Vu(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return b.createElement(r,Bu({},n))};td.isSideCarExport=!0;function nd(e,t){return e.useMedium(t),td}var rd=ed(),id=function(){},ad=b.forwardRef(function(e,t){var n=b.useRef(null),r=b.useState({onScrollCapture:id,onWheelCapture:id,onTouchMoveCapture:id}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noRelative,m=e.noIsolation,h=e.inert,g=e.allowPinchZoom,_=e.as,v=_===void 0?`div`:_,y=e.gapMode,x=Vu(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=f,C=Zu([n,t]),w=Bu(Bu({},x),i);return b.createElement(b.Fragment,null,u&&b.createElement(S,{sideCar:rd,removeScrollBar:l,shards:d,noRelative:p,noIsolation:m,inert:h,setCallbacks:a,allowPinchZoom:!!g,lockRef:n,gapMode:y}),o?b.cloneElement(b.Children.only(s),Bu(Bu({},w),{ref:C})):b.createElement(v,Bu({},w,{className:c,ref:C}),s))});ad.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ad.classNames={fullWidth:Wu,zeroRight:Uu};var od=function(){if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function sd(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=od();return t&&e.setAttribute(`nonce`,t),e}function cd(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function ld(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var ud=function(){var e=0,t=null;return{add:function(n){e==0&&(t=sd())&&(cd(t,n),ld(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},dd=function(){var e=ud();return function(t,n){b.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},fd=function(){var e=dd();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},pd={left:0,top:0,right:0,gap:0},md=function(e){return parseInt(e||``,10)||0},hd=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[md(n),md(r),md(i)]},gd=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return pd;var t=hd(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},_d=fd(),vd=`data-scroll-locked`,yd=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
|
|
30
|
+
`,style:{borderColor:f,boxShadow:`0 0 20px ${f}20`},children:[(0,V.jsx)(Il,{warnings:l}),t&&(0,V.jsx)(Vl,{}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:f},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:f},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200 z-10`,children:(0,V.jsx)(G,{size:`sm`,variant:`destructive`,className:`h-5 w-5 p-0 bg-red-500/80 hover:bg-red-500 border-red-400`,onClick:t=>{t.stopPropagation(),window.confirm(`Delete playbook "${e.title}"?`)&&h.mutate()},title:`Delete ${e.title}`,children:(0,V.jsx)(Hi,{className:`w-3 h-3`})})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:f},children:(0,V.jsx)(fi,{className:`h-7 w-7`,strokeWidth:2.25})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:f},children:e.title}),(0,V.jsxs)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:f,borderColor:f},children:[`Playbook`,p>0?` · ${p} deps`:``]})]}),(0,V.jsx)(`div`,{className:`absolute bottom-6 inset-x-1`,children:(0,V.jsx)(G,{size:`sm`,className:`w-full text-[8px] px-1 py-1 h-5 bg-black/20 hover:bg-black/40 border`,style:{color:f,borderColor:f},onClick:e=>{e.stopPropagation(),m.mutate()},disabled:t||m.isPending||!n,children:t?`IN DECK`:`ADD`})}),(0,V.jsx)(`div`,{className:`absolute inset-0 rounded-lg bg-gradient-to-br from-transparent via-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-500 pointer-events-none`})]})})}var Yl=(0,b.memo)(Jl),Xl=64,Zl=4,Ql=12,$l=1.08;function eu(e=Ql,t=$l){let n=e*Math.PI/180,r=128*Math.sin(n)+192*Math.cos(n);return Math.ceil(r*t)+8}var tu=eu();function nu(e,t=48){return e===0?0:128+Math.max(0,e-1)*(128-t)}function ru(e=10,t=48,n=12){return nu(e,t)+2*n}function iu(e,t=48){return nu(e,t)+24}var au=ru();function ou(e,t,n,r=Ql){let i=t+n/2,a=n/2;if(a<=0)return 0;let o=(e-i)/a;return Math.max(-r,Math.min(r,o*r))}function su(e){return{flexShrink:0,marginLeft:e===0?0:`-48px`}}function cu(e,t,n){return n===e?999999:t-e}function lu({cardCount:e,children:t}){let n=(0,b.useRef)(null),r=(0,b.useRef)([]),i=(0,b.useRef)(0),a=(0,b.useRef)(void 0),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(!1),g=(0,b.useRef)(!1),_=(0,b.useRef)(!1),[v,y]=(0,b.useState)(null),x=(0,b.useRef)(null);x.current=v;let S=(0,b.useCallback)(()=>{let t=n.current;if(!t)return;let i=t.getBoundingClientRect(),a=x.current;r.current.forEach((t,n)=>{if(!t)return;let r=t.getBoundingClientRect(),o=r.left+r.width/2,s=a===n?0:ou(o,i.left,i.width),c=a===n?$l:1;t.style.transform=`rotate(${s}deg) scale(${c})`,t.style.transformOrigin=`center center`,t.style.zIndex=String(cu(n,e,a))})},[e]),C=(0,b.useCallback)(e=>{let t=n.current;t&&t.scrollBy({left:e===`left`?-80:80,behavior:`smooth`})},[]),w=(0,b.useCallback)(()=>{let t=n.current;if(!t)return;let r=iu(e,48)>t.clientWidth+2;s(r),l(r&&t.scrollLeft>4),d(r&&t.scrollLeft+t.clientWidth<t.scrollWidth-4),S()},[e,S]);(0,b.useLayoutEffect)(()=>{let e=n.current;if(!e)return;w();let t=new ResizeObserver(w);return t.observe(e),e.addEventListener(`scroll`,w,{passive:!0}),()=>{t.disconnect(),e.removeEventListener(`scroll`,w)}},[e,w]),(0,b.useEffect)(()=>{let e=()=>{let t=n.current,r=i.current;if(t&&r!==0){t.scrollLeft+=r,S();let e=t.scrollLeft>4,n=t.scrollLeft+t.clientWidth<t.scrollWidth-4;l(e),d(n)}let o=r<0,s=r>0;o!==g.current&&(g.current=o,p(o)),s!==_.current&&(_.current=s,h(s)),a.current=requestAnimationFrame(e)};return a.current=requestAnimationFrame(e),()=>{a.current!==void 0&&cancelAnimationFrame(a.current)}},[S]);let T=e=>{let t=n.current;if(!t||!o){i.current=0;return}let r=t.getBoundingClientRect(),a=e.clientX-r.left;if(a<Xl&&c){let e=1-a/Xl;i.current=-(Zl+e*10)}else if(a>r.width-Xl&&u){let e=1-(r.width-a)/Xl;i.current=Zl+e*10}else i.current=0;S()},E=()=>{i.current=0,g.current=!1,_.current=!1,p(!1),h(!1)};if((0,b.useLayoutEffect)(()=>{r.current.length=e,S()},[e,v,S]),e===0)return(0,V.jsx)(V.Fragment,{children:t});let D=(e,t)=>`absolute ${e===`left`?`left-2`:`right-2`} top-1/2 z-30 -translate-y-1/2 rounded-full bg-gray-950/90 p-1.5 text-yellow-300 shadow-lg ring-1 ring-black/50 transition-all duration-150 hover:bg-gray-950 hover:ring-yellow-300/40 ${t?`scale-110`:`scale-100`}`;return(0,V.jsxs)(`div`,{className:`relative flex h-full w-full min-w-0 max-w-full items-center justify-center overflow-hidden`,"data-testid":`deck-fan`,onMouseMove:T,onMouseLeave:E,children:[o&&c&&(0,V.jsx)(`button`,{type:`button`,className:D(`left`,f),"aria-label":`Scroll deck left`,"data-testid":`deck-scroll-left`,onClick:()=>C(`left`),children:(0,V.jsx)(_i,{className:`h-6 w-6`,strokeWidth:2.5})}),o&&u&&(0,V.jsx)(`button`,{type:`button`,className:D(`right`,m),"aria-label":`Scroll deck right`,"data-testid":`deck-scroll-right`,onClick:()=>C(`right`),children:(0,V.jsx)(vi,{className:`h-6 w-6`,strokeWidth:2.5})}),(0,V.jsx)(`div`,{ref:n,className:`max-w-full overflow-x-auto overflow-y-visible [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,style:{width:au,maxWidth:`100%`},children:(0,V.jsx)(`div`,{className:`flex items-center justify-start isolate group/fan`,style:{minHeight:tu,paddingLeft:12,paddingRight:12},children:b.Children.map(t,(e,t)=>(0,V.jsx)(`div`,{ref:e=>{r.current[t]=e},className:`relative flex items-center justify-center transition-[transform,box-shadow] duration-500 will-change-transform`,style:{...su(t),minHeight:tu},onMouseEnter:()=>y(t),onMouseLeave:()=>y(null),children:e},e&&typeof e==`object`&&`key`in e?e.key:t))})})]})}var uu=b.forwardRef(({className:e,type:t,...n},r)=>(0,V.jsx)(`input`,{type:t,className:W(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,e),ref:r,...n}));uu.displayName=`Input`;function du({deck:e,services:t,credentials:n=[],playbooks:r=[],collectionWarnings:i,onDrop:a,onDragStart:o,onCredentialDragStart:s,onPlaybookDragStart:c,onDragEnd:l,onCardClick:u,onPlaybookClick:d,onCredentialClick:f}){let[p,m]=(0,b.useState)(!1),[h,g]=(0,b.useState)(e.name),_=(0,b.useRef)(null),v=Et(),{toast:y}=on();(0,b.useEffect)(()=>{g(e.name),m(!1)},[e.id,e.name]),(0,b.useEffect)(()=>{p&&(_.current?.focus(),_.current?.select())},[p]);let x=Ht({mutationFn:async t=>(await H(`PUT`,`/api/decks/${e.id}`,{name:t})).json(),onSuccess:e=>{if(!e.success)throw Error(e.error||`Rename failed`);v.invalidateQueries({queryKey:[`/api/decks`]}),m(!1)},onError:t=>{g(e.name),m(!1),y({title:`Could not rename deck`,description:t.message,variant:`destructive`})}}),S=()=>{let t=h.trim();if(!t||t===e.name){g(e.name),m(!1);return}x.mutate(t)},C=e=>{e.preventDefault(),a(e)},w=e=>{e.preventDefault()},T=t.length+n.length+r.length;return(0,V.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col overflow-hidden`,children:[(0,V.jsxs)(`h3`,{className:`mb-4 flex min-w-0 shrink-0 items-center text-lg font-bold`,children:[(0,V.jsx)(`i`,{className:`fas fa-layer-group mr-2 text-blue-400`}),(0,V.jsx)(`span`,{className:`font-ui-display`,children:`Deck`}),p?(0,V.jsx)(uu,{ref:_,value:h,disabled:x.isPending,onChange:e=>g(e.target.value),onBlur:S,onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),S()):t.key===`Escape`&&(t.preventDefault(),g(e.name),m(!1))},className:`ml-2 h-7 max-w-[12rem] border-white/20 bg-white/10 px-2 text-sm font-normal text-white sm:max-w-[16rem]`,"data-testid":`input-deck-name`,"aria-label":`Deck name`}):(0,V.jsx)(`button`,{type:`button`,className:`ml-2 min-w-0 truncate text-left text-sm font-normal text-gray-400 hover:text-white hover:underline`,title:`Click to rename`,onClick:()=>m(!0),"data-testid":`button-rename-deck`,children:e.name}),(0,V.jsxs)(`span`,{className:`ml-2 shrink-0 text-sm font-normal text-gray-400`,children:[`(`,T,` cards)`]})]}),(0,V.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden rounded-xl border-2 border-dashed px-4 py-2 min-w-0`,onDrop:C,onDragOver:w,style:{background:`linear-gradient(135deg, rgba(196, 182, 67, 0.1), rgba(212, 199, 96, 0.1))`,borderColor:`rgba(196, 182, 67, 0.3)`},"data-testid":`deck-drop-zone`,children:(0,V.jsx)(`div`,{className:`relative flex min-h-0 flex-1 items-center justify-center overflow-hidden min-w-0`,children:T===0?(0,V.jsx)(`div`,{className:`flex items-center justify-center`,style:{minHeight:tu},children:(0,V.jsx)(`div`,{className:`flex items-center justify-center rounded-lg border-2 border-dashed border-gray-500 opacity-50 transition-opacity hover:opacity-75`,style:{width:128,height:192},"data-testid":`deck-empty-placeholder`,children:(0,V.jsx)(Ii,{className:`h-8 w-8 text-gray-500`})})}):(0,V.jsxs)(lu,{cardCount:T,children:[n.map((e,t)=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:Al,boxShadow:`0 0 20px ${Al}20`},draggable:!0,onDragStart:t=>s(t,e,!0),onDragEnd:l,onClick:()=>f?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.credentialWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Al},children:`AK`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Al},children:`AK`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:Al},children:(0,V.jsx)(Gl,{credential:e,color:Al})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:Al},children:e.label}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:Al,borderColor:Al},children:e.hasSecret?`API Key`:`Missing key`})]})]},e.id)),r.map((e,t)=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:jl,boxShadow:`0 0 20px ${jl}20`},draggable:!0,onDragStart:t=>c(t,e,!0),onDragEnd:l,onClick:()=>d?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.playbookWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:jl},children:`PB`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:jl},children:`PB`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:jl},children:(0,V.jsx)(fi,{className:`h-7 w-7`,strokeWidth:2.25})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:jl},children:e.title}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:jl,borderColor:jl},children:`Playbook`})]})]},e.id)),t.map(e=>(0,V.jsxs)(`div`,{className:`w-32 h-48 aspect-[2/3] rounded-lg border-2 p-3 transition-shadow duration-500 shadow-lg hover:shadow-2xl bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900 relative overflow-hidden cursor-pointer`,style:{borderColor:Nl(e),boxShadow:`0 0 20px ${Nl(e)}20`},draggable:!0,onDragStart:t=>o(t,e,!0),onDragEnd:l,onClick:()=>u?.(e),"data-testid":`deck-card-${e.id}`,children:[(0,V.jsx)(Il,{warnings:i?.serviceWarnings.get(e.id)}),(0,V.jsx)(`div`,{className:`absolute top-1 left-1 text-xs font-bold`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Nl(e)},children:e.type===`mcp`?`RM`:e.type===`local-mcp`?`LM`:`A`})}),(0,V.jsx)(`div`,{className:`absolute bottom-1 right-1 text-xs font-bold rotate-180`,children:(0,V.jsx)(`div`,{className:`leading-none`,style:{color:Nl(e)},children:e.type===`mcp`?`RM`:e.type===`local-mcp`?`LM`:`A`})}),(0,V.jsxs)(`div`,{className:`absolute inset-x-2 top-6 bottom-8 flex flex-col items-center justify-center text-center`,children:[(0,V.jsx)(`div`,{className:`mb-2`,style:{color:Nl(e)},children:(0,V.jsx)(zl,{service:e})}),(0,V.jsx)(`h3`,{className:`font-bold text-xs mb-1 line-clamp-2`,style:{color:Nl(e)},children:e.name}),(0,V.jsx)(`div`,{className:`text-[8px] px-1 py-0.5 rounded border opacity-70`,style:{color:Nl(e),borderColor:Nl(e)},children:e.type===`mcp`?`Remote MCP`:e.type===`local-mcp`?`Local MCP`:`A2A`})]})]},e.id))]})})})]})}var fu=0;function pu(){b.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??mu()),document.body.insertAdjacentElement(`beforeend`,e[1]??mu()),fu++,()=>{fu===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),fu--}},[])}function mu(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var hu=`focusScope.autoFocusOnMount`,gu=`focusScope.autoFocusOnUnmount`,_u={bubbles:!1,cancelable:!0},vu=`FocusScope`,yu=b.forwardRef((e,t)=>{let{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...o}=e,[s,c]=b.useState(null),l=Tn(i),u=Tn(a),d=b.useRef(null),f=un(t,e=>c(e)),p=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(r){let e=function(e){if(p.paused||!s)return;let t=e.target;s.contains(t)?d.current=t:Eu(d.current,{select:!0})},t=function(e){if(p.paused||!s)return;let t=e.relatedTarget;t!==null&&(s.contains(t)||Eu(d.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&Eu(s)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return s&&r.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,s,p.paused]),b.useEffect(()=>{if(s){Du.add(p);let e=document.activeElement;if(!s.contains(e)){let t=new CustomEvent(hu,_u);s.addEventListener(hu,l),s.dispatchEvent(t),t.defaultPrevented||(bu(Au(Su(s)),{select:!0}),document.activeElement===e&&Eu(s))}return()=>{s.removeEventListener(hu,l),setTimeout(()=>{let t=new CustomEvent(gu,_u);s.addEventListener(gu,u),s.dispatchEvent(t),t.defaultPrevented||Eu(e??document.body,{select:!0}),s.removeEventListener(gu,u),Du.remove(p)},0)}}},[s,l,u,p]);let m=b.useCallback(e=>{if(!n&&!r||p.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=xu(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&Eu(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&Eu(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,p.paused]);return(0,V.jsx)(Cn.div,{tabIndex:-1,...o,ref:f,onKeyDown:m})});yu.displayName=vu;function bu(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(Eu(r,{select:t}),document.activeElement!==n)return}function xu(e){let t=Su(e);return[Cu(t,e),Cu(t.reverse(),e)]}function Su(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Cu(e,t){for(let n of e)if(!wu(n,{upTo:t}))return n}function wu(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function Tu(e){return e instanceof HTMLInputElement&&`select`in e}function Eu(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Tu(e)&&t&&e.select()}}var Du=Ou();function Ou(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=ku(e,t),e.unshift(t)},remove(t){e=ku(e,t),e[0]?.resume()}}}function ku(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Au(e){return e.filter(e=>e.tagName!==`A`)}var ju=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Mu=new WeakMap,Nu=new WeakMap,Pu={},Fu=0,Iu=function(e){return e&&(e.host||Iu(e.parentNode))},Lu=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=Iu(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},Ru=function(e,t,n,r){var i=Lu(t,Array.isArray(e)?e:[e]);Pu[n]||(Pu[n]=new WeakMap);var a=Pu[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Mu.get(e)||0)+1,l=(a.get(e)||0)+1;Mu.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Nu.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Fu++,function(){o.forEach(function(e){var t=Mu.get(e)-1,i=a.get(e)-1;Mu.set(e,t),a.set(e,i),t||(Nu.has(e)||e.removeAttribute(r),Nu.delete(e)),i||e.removeAttribute(n)}),Fu--,Fu||(Mu=new WeakMap,Mu=new WeakMap,Nu=new WeakMap,Pu={})}},zu=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||ju(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),Ru(r,i,n,`aria-hidden`)):function(){return null}},Bu=function(){return Bu=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Bu.apply(this,arguments)};function Vu(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Hu(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var Uu=`right-scroll-bar-position`,Wu=`width-before-scroll-bar`,Gu=`with-scroll-bars-hidden`,Ku=`--removed-body-scroll-bar-size`;function qu(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Ju(e,t){var n=(0,b.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var Yu=typeof window<`u`?b.useLayoutEffect:b.useEffect,Xu=new WeakMap;function Zu(e,t){var n=Ju(t||null,function(t){return e.forEach(function(e){return qu(e,t)})});return Yu(function(){var t=Xu.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||qu(e,null)}),i.forEach(function(e){r.has(e)||qu(e,a)})}Xu.set(n,e)},[e]),n}function Qu(e){return e}function $u(e,t){t===void 0&&(t=Qu);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function ed(e){e===void 0&&(e={});var t=$u(null);return t.options=Bu({async:!0,ssr:!1},e),t}var td=function(e){var t=e.sideCar,n=Vu(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return b.createElement(r,Bu({},n))};td.isSideCarExport=!0;function nd(e,t){return e.useMedium(t),td}var rd=ed(),id=function(){},ad=b.forwardRef(function(e,t){var n=b.useRef(null),r=b.useState({onScrollCapture:id,onWheelCapture:id,onTouchMoveCapture:id}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noRelative,m=e.noIsolation,h=e.inert,g=e.allowPinchZoom,_=e.as,v=_===void 0?`div`:_,y=e.gapMode,x=Vu(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=f,C=Zu([n,t]),w=Bu(Bu({},x),i);return b.createElement(b.Fragment,null,u&&b.createElement(S,{sideCar:rd,removeScrollBar:l,shards:d,noRelative:p,noIsolation:m,inert:h,setCallbacks:a,allowPinchZoom:!!g,lockRef:n,gapMode:y}),o?b.cloneElement(b.Children.only(s),Bu(Bu({},w),{ref:C})):b.createElement(v,Bu({},w,{className:c,ref:C}),s))});ad.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ad.classNames={fullWidth:Wu,zeroRight:Uu};var od=function(){if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function sd(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=od();return t&&e.setAttribute(`nonce`,t),e}function cd(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function ld(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var ud=function(){var e=0,t=null;return{add:function(n){e==0&&(t=sd())&&(cd(t,n),ld(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},dd=function(){var e=ud();return function(t,n){b.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},fd=function(){var e=dd();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},pd={left:0,top:0,right:0,gap:0},md=function(e){return parseInt(e||``,10)||0},hd=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[md(n),md(r),md(i)]},gd=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return pd;var t=hd(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},_d=fd(),vd=`data-scroll-locked`,yd=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
|
|
31
31
|
.${Gu} {
|
|
32
32
|
overflow: hidden ${r};
|
|
33
33
|
padding-right: ${s}px ${r};
|
|
@@ -127,7 +127,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
127
127
|
}`})]})]}),(0,V.jsxs)(G,{type:`button`,className:`flex-1 border`,style:{background:`linear-gradient(135deg, #C4B643, #D4C760)`,borderColor:`#C4B643`,color:`#0A0A07`},onClick:O,disabled:!s.trim()||s.trim().length<10,"data-testid":`button-parse-json`,children:[(0,V.jsx)(xi,{className:`w-4 h-4 mr-2`,style:{color:`#0A0A07`}}),`Parse Configuration`]})]}),a===`review`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`local-name`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Server Name`}),(0,V.jsx)(uu,{id:`local-name`,placeholder:`e.g., Memory Server`,value:S.name,onChange:e=>{L(`name`,e.target.value),e.target.value.trim()?A(e.target.value):m(null)},className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,required:!0,"data-testid":`input-local-service-name`}),p&&(0,V.jsxs)(`div`,{className:`mt-2 text-xs text-red-400 flex items-center`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4 mr-1`}),`A service with the name "`,p,`" already exists.`]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`command`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Command`}),(0,V.jsx)(uu,{id:`command`,placeholder:`e.g., npx, python, node`,value:S.command,onChange:e=>L(`command`,e.target.value),className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,required:!0,"data-testid":`input-command`}),(0,V.jsx)(`div`,{className:`mt-1 text-xs text-gray-400`,children:`The command to execute (e.g., npx, python, node)`})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Arguments`}),S.args.map((e,t)=>(0,V.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,V.jsx)(uu,{placeholder:`Argument ${t+1}`,value:e,onChange:e=>{let n=[...S.args];n[t]=e.target.value,L(`args`,n)},className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,"data-testid":`input-arg-${t}`}),t===S.args.length-1&&(0,V.jsx)(G,{type:`button`,size:`sm`,onClick:()=>L(`args`,[...S.args,``]),className:`bg-white/20 hover:bg-white/30 text-white`,children:(0,V.jsx)(Ii,{className:`w-4 h-4`})}),S.args.length>1&&(0,V.jsx)(G,{type:`button`,size:`sm`,variant:`destructive`,onClick:()=>{let e=S.args.filter((e,n)=>n!==t);L(`args`,e)},className:`bg-red-500/80 hover:bg-red-500 text-white`,children:(0,V.jsx)(qi,{className:`w-4 h-4`})})]},t)),(0,V.jsx)(`div`,{className:`mt-1 text-xs text-gray-400`,children:`Command arguments (e.g., -y, @modelcontextprotocol/server-memory)`})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Environment Variables`}),Object.entries(S.env).length===0?(0,V.jsx)(`div`,{className:`text-gray-400 text-sm italic`,children:`No environment variables configured`}):(0,V.jsx)(`div`,{className:`space-y-2`,children:Object.entries(S.env).map(([e,t],n)=>(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(uu,{placeholder:`Variable name`,value:e,onChange:n=>{let r={...S.env};delete r[e],r[n.target.value]=t,L(`env`,r)},className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,"data-testid":`input-env-key-${n}`}),(0,V.jsx)(uu,{placeholder:`Value`,value:t,onChange:t=>{let n={...S.env};n[e]=t.target.value,L(`env`,n)},className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,"data-testid":`input-env-value-${n}`}),(0,V.jsx)(G,{type:`button`,size:`sm`,variant:`destructive`,onClick:()=>{let t={...S.env};delete t[e],L(`env`,t)},className:`bg-red-500/80 hover:bg-red-500 text-white`,children:(0,V.jsx)(qi,{className:`w-4 h-4`})})]},n))}),(0,V.jsxs)(G,{type:`button`,size:`sm`,onClick:()=>{let e={...S.env};e[``]=``,L(`env`,e)},className:`mt-2 bg-white/20 hover:bg-white/30 text-white`,children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),`Add Environment Variable`]}),(0,V.jsx)(`div`,{className:`mt-1 text-xs text-gray-400`,children:`Environment variables for the MCP server process`})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`local-description`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Description`}),(0,V.jsx)(Pp,{id:`local-description`,placeholder:`Brief description of capabilities...`,value:S.description,onChange:e=>L(`description`,e.target.value),rows:3,className:`bg-white/10 border-white/20 text-white placeholder-gray-400 resize-none`,"data-testid":`textarea-local-description`})]}),(0,V.jsxs)(`div`,{className:`flex gap-3`,children:[(0,V.jsx)(G,{type:`button`,variant:`outline`,className:`flex-1 border-white/20 text-white hover:bg-white/10`,onClick:()=>o(`json`),"data-testid":`button-back-to-json`,children:`← Back to JSON`}),(0,V.jsxs)(G,{type:`button`,variant:`ghost`,className:`flex-1 border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#92E4DD`),onClick:M,disabled:ne(),"data-testid":`button-register`,children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),j.isPending?`Registering...`:te()]})]})]}),a===`complete`&&(0,V.jsxs)(`div`,{className:`text-center py-8`,children:[(0,V.jsx)(xi,{className:`w-16 h-16 text-green-500 mx-auto mb-4`}),(0,V.jsx)(`h3`,{className:`text-xl font-bold mb-2`,style:{color:`#92E4DD`},children:`Local MCP Registered!`}),(0,V.jsx)(`p`,{className:`text-gray-400 mb-4`,children:`Your local MCP server has been successfully registered.`}),(0,V.jsx)(G,{type:`button`,className:`flex-1 border`,style:{background:`linear-gradient(135deg, #C4B643, #D4C760)`,borderColor:`#C4B643`,color:`#0A0A07`},onClick:N,"data-testid":`button-close`,children:`Close`})]})]})]}):(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`name`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Agent Name`}),(0,V.jsx)(uu,{id:`name`,placeholder:`e.g., Code Assistant`,value:w.name,onChange:e=>{ee(`name`,e.target.value),e.target.value.trim()?A(e.target.value):m(null)},className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,required:!0,"data-testid":`input-service-name`}),p&&(0,V.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-red-400 text-sm`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4`}),(0,V.jsx)(`span`,{children:`A service with this name already exists`})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`manifest_url`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Manifest URL`}),(0,V.jsx)(uu,{id:`manifest_url`,type:`url`,placeholder:`http://localhost:8001/.well-known/a2a/manifest.json`,value:w.manifest_url,onChange:e=>ee(`manifest_url`,e.target.value),className:`bg-white/10 border-white/20 text-white placeholder-gray-400`,required:!0,"data-testid":`input-manifest-url`})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`description`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`Description`}),(0,V.jsx)(Pp,{id:`description`,placeholder:`Brief description of capabilities...`,value:w.description,onChange:e=>ee(`description`,e.target.value),rows:3,className:`bg-white/10 border-white/20 text-white placeholder-gray-400 resize-none`,"data-testid":`textarea-description`})]})]}),e===`mcp`&&r===`remote`&&(0,V.jsxs)(`div`,{className:`space-y-4 border border-white/10 rounded-lg p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`headers_enabled`,checked:h.headers_enabled,onChange:e=>F(e.target.checked),className:`rounded border-white/20 bg-white/10`}),(0,V.jsx)(zp,{htmlFor:`headers_enabled`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`🔐 Authentication Required`})]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-400`,children:(0,V.jsx)(`p`,{children:`Enable this if your MCP server requires authentication (API keys, tokens, etc.).`})}),h.headers_enabled&&(0,V.jsxs)(`div`,{className:`space-y-3 pl-6`,children:[(0,V.jsxs)(`div`,{className:`text-xs text-gray-400 mb-2`,children:[(0,V.jsx)(`p`,{children:`Configure HTTP headers for authentication. Common examples:`}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside ml-2 mt-1 space-y-1`,children:[(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`code`,{children:`Authorization: Bearer YOUR_TOKEN`}),` - For API tokens`]}),(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`code`,{children:`X-API-Key: YOUR_API_KEY`}),` - For API keys`]}),(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`code`,{children:`X-Custom-Header: value`}),` - For custom headers`]})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(zp,{htmlFor:`headers`,className:`text-sm font-semibold`,style:{color:`#92E4DD`},children:`HTTP Headers (JSON)`}),(0,V.jsx)(Pp,{id:`headers`,placeholder:`{
|
|
128
128
|
"Authorization": "Bearer YOUR_TOKEN_HERE",
|
|
129
129
|
"X-API-Key": "YOUR_API_KEY_HERE"
|
|
130
|
-
}`,value:_,onChange:e=>{v(e.target.value),y&&x(null)},onBlur:()=>{_.trim()&&I()},rows:6,className:`bg-white/10 border-white/20 text-white placeholder-gray-400 resize-none font-mono text-xs`,"data-testid":`textarea-headers`}),y&&(0,V.jsxs)(`p`,{className:`text-red-400 text-xs mt-1 flex items-center gap-1`,children:[(0,V.jsx)(Ui,{className:`w-3 h-3 shrink-0`}),y]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-400 mt-1`,children:(0,V.jsx)(`p`,{children:`Enter headers as JSON. Keys are header names, values are header values.`})})]})]})]}),d&&(0,V.jsxs)(`div`,{className:`text-red-400 text-sm mt-2`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4 mr-1`}),d]}),p&&(0,V.jsxs)(`div`,{className:`text-red-400 text-sm mt-2`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4 mr-1`}),`A service with the name "`,p,`" already exists. You can register it anyway, but it might overwrite the existing one.`]}),(0,V.jsxs)(`div`,{className:`flex space-x-3 pt-4`,children:[(0,V.jsx)(G,{type:`button`,variant:`secondary`,className:`flex-1 border text-white`,style:{background:`#ad095e`,borderColor:`#ad095e`},onClick:N,"data-testid":`button-cancel`,children:`Cancel`}),(e!==`mcp`||r!==`local`)&&(0,V.jsxs)(G,{type:`button`,variant:`ghost`,className:`flex-1 border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#92E4DD`),disabled:j.isPending||ne(),"data-testid":`button-register`,onClick:M,children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),j.isPending?`Registering...`:`Register Service`]})]})]})})}function zm(e){let t=e.message||`Unknown error`;if(/already exists/i.test(t))return{title:`Deck name already exists`,description:`Choose a different name — a deck with that name already exists.`};if(e instanceof Ut){if(e.errorCode===`GRANT_REQUIRED`||e.errorCode===`DASHBOARD_REQUIRED`)return{title:`Dashboard session required`,description:`Your dashboard session is missing or expired. Run agent-deck open and try again.`};if(e.errorCode===`ADMIN_REQUIRED`)return{title:`Admin elevation required`,description:`Deck-admin elevation is required for this agent session.`}}return/file store/i.test(t)?{title:`Could not save deck`,description:t}:{title:`Failed to create deck`,description:t}}async function Bm(e){return(await(await H(`POST`,`/api/export`,{scope:e.scope??`collection`,...e.deckId?{deckId:e.deckId}:{}})).json()).data}async function Vm(e){return(await(await H(`POST`,`/api/import`,e)).json()).data}function Hm(e,t){let n=new Blob([`${JSON.stringify(e,null,2)}\n`],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}function Um(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)||`deck`}function Wm(e){let{services:t,playbooks:n,decks:r}=e.counts;return`Decks +${r.created} / skipped ${r.reused}. Services +${t.created} / skipped ${t.reused}. Playbooks +${n.created} / skipped ${n.reused}.`}function Gm({decks:e,editingDeckId:t,onSelectDeck:n,isLoading:r}){let[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(``),c=Et(),{toast:l}=on(),{data:u}=Vt({queryKey:[`/api/scope/bindings`],refetchInterval:3e3}),d=(0,b.useMemo)(()=>jf(u?.data??[]),[u]),f=Ht({mutationFn:async e=>H(`POST`,`/api/decks`,{name:e,isActive:!1}),onSuccess:async(e,t)=>{let r=await e.json();await c.invalidateQueries({queryKey:[`/api/decks`]}),r.data?.id&&n(r.data.id),l({title:`Deck created`,description:`${t} has been created successfully.`}),a(!1),s(``)},onError:e=>{let{title:t,description:n}=zm(e);l({title:t,description:n,variant:`destructive`})}}),p=Ht({mutationFn:async e=>{let t=await Bm({scope:`deck`,deckId:e.id});return Hm(t,`${Um(e.name)}.agent-deck.json`),t},onSuccess:(e,t)=>{l({title:`Deck exported`,description:`${t.name}: ${e.services.length} services, ${e.playbooks.length} playbooks`})},onError:e=>{l({title:`Export failed`,description:e.message,variant:`destructive`})}}),m=(e,t)=>{e.stopPropagation(),p.mutate(t)},h=Ht({mutationFn:async e=>H(`DELETE`,`/api/decks/${e}`,{}),onSuccess:()=>{c.invalidateQueries({queryKey:[`/api/decks`]}),l({title:`Deck deleted`,description:`Your deck has been deleted successfully.`})},onError:e=>{e.message.includes(`Cannot delete the last deck`)?l({title:`Cannot delete deck`,description:`You cannot delete the last deck. Please create another deck first.`,variant:`destructive`}):l({title:`Failed to delete deck`,description:e.message,variant:`destructive`})}}),g=async(e,t)=>{e.stopPropagation();try{await navigator.clipboard.writeText(t.id),l({title:`Copied deck id`,description:`Use with bind_workspace({ workspaceRoot, deckId }) in your agent.`})}catch(e){l({title:`Failed to copy deck id`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}},_=(e,t)=>{e.stopPropagation(),window.confirm(`Are you sure you want to delete this deck? This action cannot be undone.`)&&h.mutate(t)},v=e=>{e.preventDefault();let t=o.trim();t&&f.mutate(t)},y=e=>(e.services?.length??0)+(e.credentials?.length??0)+(e.playbooks?.length??0);return r?(0,V.jsx)(`div`,{className:`bg-black/40 backdrop-blur-md rounded-2xl border border-white/10 p-6 shadow-2xl`,children:(0,V.jsxs)(`div`,{className:`animate-pulse space-y-4`,children:[(0,V.jsx)(`div`,{className:`h-6 bg-white/10 rounded`}),(0,V.jsx)(`div`,{className:`space-y-3`,children:Array.from({length:3}).map((e,t)=>(0,V.jsx)(`div`,{className:`h-16 bg-white/5 rounded-lg`},t))})]})}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`deck-management-panel`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold mb-3 flex items-center`,children:[(0,V.jsx)(Mi,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{style:{color:`#92E4DD`},children:`My Decks`})]}),(0,V.jsx)(`div`,{className:`mb-3`,children:(0,V.jsxs)(G,{onClick:()=>a(!0),className:`w-full border text-sm py-2`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},"data-testid":`create-deck-button`,children:[(0,V.jsx)(Ii,{className:`w-3 h-3 mr-2`}),`Add Deck`]})}),(0,V.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,V.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>{let r=e.id===t,i=Mf(y(e),d.get(e.id)??0);return(0,V.jsxs)(`div`,{className:`p-2 rounded-lg border cursor-pointer transition-all relative group ${r?`bg-gradient-to-r from-yellow-500/20 to-yellow-600/20 border-2 border-yellow-500/40 hover:border-yellow-400/60`:`bg-white/5 border border-white/10 hover:border-white/20`}`,onClick:()=>n(e.id),"data-testid":`deck-item-${e.id}`,children:[(0,V.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200`,children:[(0,V.jsx)(G,{size:`sm`,variant:`secondary`,className:`h-5 w-5 p-0`,onClick:t=>m(t,e),title:`Export this deck`,"data-testid":`export-deck-${e.id}`,children:(0,V.jsx)(Ei,{className:`w-2 h-2`})}),(0,V.jsx)(G,{size:`sm`,variant:`secondary`,className:`h-5 w-5 p-0`,onClick:t=>g(t,e),title:`Copy deck id for bind_workspace`,children:(0,V.jsx)(wi,{className:`w-2 h-2`})}),(0,V.jsx)(G,{size:`sm`,variant:`destructive`,className:`h-5 w-5 p-0 bg-red-500/80 hover:bg-red-500 border-red-400`,onClick:t=>_(t,e.id),title:`Delete deck`,children:(0,V.jsx)(Hi,{className:`w-2 h-2`})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`font-semibold text-sm pr-16 ${r?`text-yellow-300`:`text-white`}`,children:e.name}),(0,V.jsx)(`p`,{className:`text-xs text-gray-400 select-none pointer-events-none`,children:i})]})]},e.id)})})})]}),(0,V.jsx)(Dp,{open:i,onOpenChange:a,children:(0,V.jsxs)(Ap,{className:`sm:max-w-md border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsx)(jp,{children:(0,V.jsxs)(Mp,{className:`flex items-center text-xl font-bold`,children:[(0,V.jsx)(Mi,{className:`mr-2 h-5 w-5`,style:{color:`#92E4DD`}}),`Create New Deck`]})}),(0,V.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,"data-testid":`form-create-deck`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`deckName`,children:`Deck Name`}),(0,V.jsx)(uu,{id:`deckName`,placeholder:`e.g., Hiring stack`,value:o,onChange:e=>s(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#A8C4C0]/60`,required:!0,"data-testid":`input-deck-name`})]}),(0,V.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,V.jsx)(G,{type:`button`,variant:`outline`,className:`flex-1 rounded-full border-white/20 text-[#E8F6F4] hover:bg-white/10`,onClick:()=>a(!1),"data-testid":`button-cancel-create`,children:`Cancel`}),(0,V.jsx)(G,{type:`submit`,className:`flex-1 rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},disabled:f.isPending,"data-testid":`button-submit-create`,children:f.isPending?`Creating…`:`Create Deck`})]})]})]})})]})}function Km({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(``),o=Et(),{toast:s}=on(),c=Ht({mutationFn:async()=>H(`POST`,`/api/credentials`,{label:n.trim(),value:i}),onSuccess:()=>{o.invalidateQueries({queryKey:[`/api/credentials/vault`]}),o.invalidateQueries({queryKey:[`/api/decks`]}),s({title:`API key saved`,description:`${n.trim()} is stored securely. Your agent can use it from the active deck.`}),t(!1),r(``),a(``)},onError:e=>{s({title:`Could not save API key`,description:e.message,variant:`destructive`})}}),l=n.trim().length>0&&i.trim().length>0;return(0,V.jsx)(Dp,{open:e,onOpenChange:t,children:(0,V.jsxs)(Ap,{className:`sm:max-w-md border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{className:`text-[#E8F6F4]`,children:`Register API key`}),(0,V.jsx)(Np,{className:`text-[#A8C4C0]`,children:`Name the service and paste the key. Agent Deck handles the rest — stored in your vault, never shown again.`})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`credential-name`,className:`text-[#CFEAE6]`,children:`Service name`}),(0,V.jsx)(uu,{id:`credential-name`,placeholder:`OpenAI, Linear, Slack…`,value:n,onChange:e=>r(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#6B8581]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`credential-value`,className:`text-[#CFEAE6]`,children:`API key`}),(0,V.jsx)(uu,{id:`credential-value`,type:`password`,placeholder:`Paste key from the service dashboard`,value:i,onChange:e=>a(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#6B8581]`})]}),(0,V.jsx)(G,{variant:`ghost`,className:`w-full border-2 hover:opacity-90 ${Ml}`,style:Pl(Al),onClick:()=>c.mutate(),disabled:!l||c.isPending,children:`Save to vault`})]})]})})}function qm({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(``),[c,l]=(0,b.useState)(``),[u,d]=(0,b.useState)(``),[f,p]=(0,b.useState)([]),[m,h]=(0,b.useState)([]),g=Et(),{toast:_}=on(),{data:v}=Vt({queryKey:[`/api/credentials/vault`],enabled:e}),{data:y}=Vt({queryKey:[`/api/services`],enabled:e}),x=v?.data??[],S=y?.data??[],C=Ht({mutationFn:async()=>H(`POST`,`/api/playbooks`,{title:n.trim(),body:i,triggers:o.split(`,`).map(e=>e.trim()).filter(Boolean),dependsOnCredentialIds:f,dependsOnServiceIds:m,exec:c.trim()||void 0,skill:u.trim()||void 0,autoDetectDependencies:!0}),onSuccess:()=>{g.invalidateQueries({queryKey:[`/api/playbooks/vault`]}),_({title:`Playbook saved`,description:`${n.trim()} is in your collection.`}),t(!1),r(``),a(``),s(``),l(``),d(``),p([]),h([])},onError:e=>{_({title:`Could not save playbook`,description:e.message,variant:`destructive`})}}),w=(e,t,n)=>{n(e.includes(t)?e.filter(e=>e!==t):[...e,t])},T=n.trim().length>0&&i.trim().length>0;return(0,V.jsx)(Dp,{open:e,onOpenChange:t,children:(0,V.jsxs)(Ap,{className:`sm:max-w-2xl max-h-[90vh] overflow-y-auto border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{children:`Register Playbook`}),(0,V.jsxs)(Np,{className:`text-[#A8C4C0]`,children:[`Prefer`,` `,(0,V.jsx)(`span`,{className:`font-mono text-xs`,children:`register_playbook`}),` /`,` `,(0,V.jsx)(`span`,{className:`font-mono text-xs`,children:`update_playbook`}),` from your AI agent. This form also auto-detects API key and MCP dependencies from the content on save.`]})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-title`,children:`Title`}),(0,V.jsx)(uu,{id:`playbook-title`,placeholder:`Hiring inbox, Ashby API guide…`,value:n,onChange:e=>r(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-triggers`,children:`Triggers (comma-separated, max 16)`}),(0,V.jsx)(uu,{id:`playbook-triggers`,placeholder:`check inbox, review applicants`,value:o,onChange:e=>s(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-body`,children:`Instructions (markdown)`}),(0,V.jsx)(Pp,{id:`playbook-body`,rows:8,placeholder:`# Steps
|
|
130
|
+
}`,value:_,onChange:e=>{v(e.target.value),y&&x(null)},onBlur:()=>{_.trim()&&I()},rows:6,className:`bg-white/10 border-white/20 text-white placeholder-gray-400 resize-none font-mono text-xs`,"data-testid":`textarea-headers`}),y&&(0,V.jsxs)(`p`,{className:`text-red-400 text-xs mt-1 flex items-center gap-1`,children:[(0,V.jsx)(Ui,{className:`w-3 h-3 shrink-0`}),y]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-400 mt-1`,children:(0,V.jsx)(`p`,{children:`Enter headers as JSON. Keys are header names, values are header values.`})})]})]})]}),d&&(0,V.jsxs)(`div`,{className:`text-red-400 text-sm mt-2`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4 mr-1`}),d]}),p&&(0,V.jsxs)(`div`,{className:`text-red-400 text-sm mt-2`,children:[(0,V.jsx)(Ui,{className:`w-4 h-4 mr-1`}),`A service with the name "`,p,`" already exists. You can register it anyway, but it might overwrite the existing one.`]}),(0,V.jsxs)(`div`,{className:`flex space-x-3 pt-4`,children:[(0,V.jsx)(G,{type:`button`,variant:`secondary`,className:`flex-1 border text-white`,style:{background:`#ad095e`,borderColor:`#ad095e`},onClick:N,"data-testid":`button-cancel`,children:`Cancel`}),(e!==`mcp`||r!==`local`)&&(0,V.jsxs)(G,{type:`button`,variant:`ghost`,className:`flex-1 border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#92E4DD`),disabled:j.isPending||ne(),"data-testid":`button-register`,onClick:M,children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),j.isPending?`Registering...`:`Register Service`]})]})]})})}function zm(e){let t=e.message||`Unknown error`;if(/already exists/i.test(t))return{title:`Deck name already exists`,description:`Choose a different name — a deck with that name already exists.`};if(e instanceof Ut){if(e.errorCode===`GRANT_REQUIRED`||e.errorCode===`DASHBOARD_REQUIRED`)return{title:`Dashboard session required`,description:`Your dashboard session is missing or expired. Run agent-deck open and try again.`};if(e.errorCode===`ADMIN_REQUIRED`)return{title:`Admin elevation required`,description:`Deck-admin elevation is required for this agent session.`}}return/file store/i.test(t)?{title:`Could not save deck`,description:t}:{title:`Failed to create deck`,description:t}}async function Bm(e){return(await(await H(`POST`,`/api/export`,{scope:e.scope??`collection`,...e.deckId?{deckId:e.deckId}:{}})).json()).data}async function Vm(e){return(await(await H(`POST`,`/api/import`,e)).json()).data}function Hm(e,t){let n=new Blob([`${JSON.stringify(e,null,2)}\n`],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}function Um(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)||`deck`}function Wm(e){let{services:t,playbooks:n,decks:r}=e.counts;return`Decks +${r.created} / skipped ${r.reused}. Services +${t.created} / skipped ${t.reused}. Playbooks +${n.created} / skipped ${n.reused}.`}function Gm({decks:e,editingDeckId:t,onSelectDeck:n,isLoading:r}){let[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(``),c=Et(),{toast:l}=on(),{data:u}=Vt({queryKey:[`/api/scope/bindings`],refetchInterval:3e3}),d=(0,b.useMemo)(()=>jf(u?.data??[]),[u]),f=Ht({mutationFn:async e=>H(`POST`,`/api/decks`,{name:e,isActive:!1}),onSuccess:async(e,t)=>{let r=await e.json();await c.invalidateQueries({queryKey:[`/api/decks`]}),r.data?.id&&n(r.data.id),l({title:`Deck created`,description:`${t} has been created successfully.`}),a(!1),s(``)},onError:e=>{let{title:t,description:n}=zm(e);l({title:t,description:n,variant:`destructive`})}}),p=Ht({mutationFn:async e=>{let t=await Bm({scope:`deck`,deckId:e.id});return Hm(t,`${Um(e.name)}.agent-deck.json`),t},onSuccess:(e,t)=>{l({title:`Deck exported`,description:`${t.name}: ${e.services.length} services, ${e.playbooks.length} playbooks`})},onError:e=>{l({title:`Export failed`,description:e.message,variant:`destructive`})}}),m=(e,t)=>{e.stopPropagation(),p.mutate(t)},h=Ht({mutationFn:async e=>H(`DELETE`,`/api/decks/${e}`,{}),onSuccess:()=>{c.invalidateQueries({queryKey:[`/api/decks`]}),l({title:`Deck deleted`,description:`Your deck has been deleted successfully.`})},onError:e=>{e.message.includes(`Cannot delete the last deck`)?l({title:`Cannot delete deck`,description:`You cannot delete the last deck. Please create another deck first.`,variant:`destructive`}):l({title:`Failed to delete deck`,description:e.message,variant:`destructive`})}}),g=async(e,t)=>{e.stopPropagation();try{await navigator.clipboard.writeText(t.id),l({title:`Copied deck id`,description:`Use with bind_workspace({ workspaceRoot, deckId }) in your agent.`})}catch(e){l({title:`Failed to copy deck id`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}},_=(e,t)=>{e.stopPropagation(),window.confirm(`Are you sure you want to delete this deck? This action cannot be undone.`)&&h.mutate(t)},v=e=>{e.preventDefault();let t=o.trim();t&&f.mutate(t)},y=e=>(e.services?.length??0)+(e.credentials?.length??0)+(e.playbooks?.length??0);return r?(0,V.jsx)(`div`,{className:`bg-black/40 backdrop-blur-md rounded-2xl border border-white/10 p-6 shadow-2xl`,children:(0,V.jsxs)(`div`,{className:`animate-pulse space-y-4`,children:[(0,V.jsx)(`div`,{className:`h-6 bg-white/10 rounded`}),(0,V.jsx)(`div`,{className:`space-y-3`,children:Array.from({length:3}).map((e,t)=>(0,V.jsx)(`div`,{className:`h-16 bg-white/5 rounded-lg`},t))})]})}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`deck-management-panel`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold mb-3 flex items-center`,children:[(0,V.jsx)(Mi,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{className:`font-ui-display`,style:{color:`#92E4DD`},children:`My Decks`})]}),(0,V.jsx)(`div`,{className:`mb-3`,children:(0,V.jsxs)(G,{onClick:()=>a(!0),className:`w-full border text-sm py-2`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},"data-testid":`create-deck-button`,children:[(0,V.jsx)(Ii,{className:`w-3 h-3 mr-2`}),`Add Deck`]})}),(0,V.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,V.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>{let r=e.id===t,i=Mf(y(e),d.get(e.id)??0);return(0,V.jsxs)(`div`,{className:`p-2 rounded-lg border cursor-pointer transition-all relative group ${r?`bg-gradient-to-r from-yellow-500/20 to-yellow-600/20 border-2 border-yellow-500/40 hover:border-yellow-400/60`:`bg-white/5 border border-white/10 hover:border-white/20`}`,onClick:()=>n(e.id),"data-testid":`deck-item-${e.id}`,children:[(0,V.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200`,children:[(0,V.jsx)(G,{size:`sm`,variant:`secondary`,className:`h-5 w-5 p-0`,onClick:t=>m(t,e),title:`Export this deck`,"data-testid":`export-deck-${e.id}`,children:(0,V.jsx)(Ei,{className:`w-2 h-2`})}),(0,V.jsx)(G,{size:`sm`,variant:`secondary`,className:`h-5 w-5 p-0`,onClick:t=>g(t,e),title:`Copy deck id for bind_workspace`,children:(0,V.jsx)(wi,{className:`w-2 h-2`})}),(0,V.jsx)(G,{size:`sm`,variant:`destructive`,className:`h-5 w-5 p-0 bg-red-500/80 hover:bg-red-500 border-red-400`,onClick:t=>_(t,e.id),title:`Delete deck`,children:(0,V.jsx)(Hi,{className:`w-2 h-2`})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`font-semibold text-sm pr-16 ${r?`text-yellow-300`:`text-white`}`,children:e.name}),(0,V.jsx)(`p`,{className:`text-xs text-gray-400 select-none pointer-events-none`,children:i})]})]},e.id)})})})]}),(0,V.jsx)(Dp,{open:i,onOpenChange:a,children:(0,V.jsxs)(Ap,{className:`sm:max-w-md border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsx)(jp,{children:(0,V.jsxs)(Mp,{className:`flex items-center text-xl font-bold`,children:[(0,V.jsx)(Mi,{className:`mr-2 h-5 w-5`,style:{color:`#92E4DD`}}),`Create New Deck`]})}),(0,V.jsxs)(`form`,{onSubmit:v,className:`space-y-4`,"data-testid":`form-create-deck`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`deckName`,children:`Deck Name`}),(0,V.jsx)(uu,{id:`deckName`,placeholder:`e.g., Hiring stack`,value:o,onChange:e=>s(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#A8C4C0]/60`,required:!0,"data-testid":`input-deck-name`})]}),(0,V.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,V.jsx)(G,{type:`button`,variant:`outline`,className:`flex-1 rounded-full border-white/20 text-[#E8F6F4] hover:bg-white/10`,onClick:()=>a(!1),"data-testid":`button-cancel-create`,children:`Cancel`}),(0,V.jsx)(G,{type:`submit`,className:`flex-1 rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},disabled:f.isPending,"data-testid":`button-submit-create`,children:f.isPending?`Creating…`:`Create Deck`})]})]})]})})]})}function Km({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(``),o=Et(),{toast:s}=on(),c=Ht({mutationFn:async()=>H(`POST`,`/api/credentials`,{label:n.trim(),value:i}),onSuccess:()=>{o.invalidateQueries({queryKey:[`/api/credentials/vault`]}),o.invalidateQueries({queryKey:[`/api/decks`]}),s({title:`API key saved`,description:`${n.trim()} is stored securely. Your agent can use it from the active deck.`}),t(!1),r(``),a(``)},onError:e=>{s({title:`Could not save API key`,description:e.message,variant:`destructive`})}}),l=n.trim().length>0&&i.trim().length>0;return(0,V.jsx)(Dp,{open:e,onOpenChange:t,children:(0,V.jsxs)(Ap,{className:`sm:max-w-md border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{className:`text-[#E8F6F4]`,children:`Register API key`}),(0,V.jsx)(Np,{className:`text-[#A8C4C0]`,children:`Name the service and paste the key. Agent Deck handles the rest — stored in your vault, never shown again.`})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`credential-name`,className:`text-[#CFEAE6]`,children:`Service name`}),(0,V.jsx)(uu,{id:`credential-name`,placeholder:`OpenAI, Linear, Slack…`,value:n,onChange:e=>r(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#6B8581]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`credential-value`,className:`text-[#CFEAE6]`,children:`API key`}),(0,V.jsx)(uu,{id:`credential-value`,type:`password`,placeholder:`Paste key from the service dashboard`,value:i,onChange:e=>a(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] placeholder:text-[#6B8581]`})]}),(0,V.jsx)(G,{variant:`ghost`,className:`w-full border-2 hover:opacity-90 ${Ml}`,style:Pl(Al),onClick:()=>c.mutate(),disabled:!l||c.isPending,children:`Save to vault`})]})]})})}function qm({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(``),[c,l]=(0,b.useState)(``),[u,d]=(0,b.useState)(``),[f,p]=(0,b.useState)([]),[m,h]=(0,b.useState)([]),g=Et(),{toast:_}=on(),{data:v}=Vt({queryKey:[`/api/credentials/vault`],enabled:e}),{data:y}=Vt({queryKey:[`/api/services`],enabled:e}),x=v?.data??[],S=y?.data??[],C=Ht({mutationFn:async()=>H(`POST`,`/api/playbooks`,{title:n.trim(),body:i,triggers:o.split(`,`).map(e=>e.trim()).filter(Boolean),dependsOnCredentialIds:f,dependsOnServiceIds:m,exec:c.trim()||void 0,skill:u.trim()||void 0,autoDetectDependencies:!0}),onSuccess:()=>{g.invalidateQueries({queryKey:[`/api/playbooks/vault`]}),_({title:`Playbook saved`,description:`${n.trim()} is in your collection.`}),t(!1),r(``),a(``),s(``),l(``),d(``),p([]),h([])},onError:e=>{_({title:`Could not save playbook`,description:e.message,variant:`destructive`})}}),w=(e,t,n)=>{n(e.includes(t)?e.filter(e=>e!==t):[...e,t])},T=n.trim().length>0&&i.trim().length>0;return(0,V.jsx)(Dp,{open:e,onOpenChange:t,children:(0,V.jsxs)(Ap,{className:`sm:max-w-2xl max-h-[90vh] overflow-y-auto border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{children:`Register Playbook`}),(0,V.jsxs)(Np,{className:`text-[#A8C4C0]`,children:[`Prefer`,` `,(0,V.jsx)(`span`,{className:`font-mono text-xs`,children:`register_playbook`}),` /`,` `,(0,V.jsx)(`span`,{className:`font-mono text-xs`,children:`update_playbook`}),` from your AI agent. This form also auto-detects API key and MCP dependencies from the content on save.`]})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-title`,children:`Title`}),(0,V.jsx)(uu,{id:`playbook-title`,placeholder:`Hiring inbox, Ashby API guide…`,value:n,onChange:e=>r(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-triggers`,children:`Triggers (comma-separated, max 16)`}),(0,V.jsx)(uu,{id:`playbook-triggers`,placeholder:`check inbox, review applicants`,value:o,onChange:e=>s(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4]`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-body`,children:`Instructions (markdown)`}),(0,V.jsx)(Pp,{id:`playbook-body`,rows:8,placeholder:`# Steps
|
|
131
131
|
1. …
|
|
132
132
|
2. …`,value:i,onChange:e=>a(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] font-mono text-sm`})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{children:`Extra API key deps (optional)`}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500`,children:`Merged with auto-detected refs from content.`}),(0,V.jsx)(`div`,{className:`max-h-28 overflow-y-auto rounded border border-white/10 p-2 space-y-1`,children:x.length===0?(0,V.jsx)(`p`,{className:`text-xs text-gray-500`,children:`No API keys registered yet.`}):x.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:f.includes(e.id),onChange:()=>w(f,e.id,p)}),e.label]},e.id))})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{children:`Extra MCP deps (optional)`}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500`,children:`Merged with auto-detected refs from content.`}),(0,V.jsx)(`div`,{className:`max-h-28 overflow-y-auto rounded border border-white/10 p-2 space-y-1`,children:S.length===0?(0,V.jsx)(`p`,{className:`text-xs text-gray-500`,children:`No MCP services registered yet.`}):S.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:m.includes(e.id),onChange:()=>w(m,e.id,h)}),e.name]},e.id))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-exec`,children:`Suggested exec (optional)`}),(0,V.jsx)(uu,{id:`playbook-exec`,placeholder:`agent-deck exec --connections … -- uv run …`,value:c,onChange:e=>l(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] font-mono text-xs`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`playbook-skill`,children:`Skill path hint (optional)`}),(0,V.jsx)(uu,{id:`playbook-skill`,placeholder:`.cursor/skills/…/SKILL.md`,value:u,onChange:e=>d(e.target.value),className:`border-white/15 bg-[#0F0F0C] text-[#E8F6F4] font-mono text-xs`})]}),(0,V.jsx)(G,{variant:`ghost`,className:`w-full border-2 hover:opacity-90 ${Ml}`,style:Pl(jl),onClick:()=>C.mutate(),disabled:!T||C.isPending,children:`Save to collection`})]})]})})}async function Jm(e){let t=await e.json();if(!t.success)throw Error(t.error??`Request failed`);return t.data}function Ym(e){return e.length===0?null:e.length<=3?e.join(`, `):`${e.slice(0,3).join(`, `)} and ${e.length-3} more`}async function Xm(e){return Jm(await H(`GET`,`/api/playbook-patches${e?`?status=${encodeURIComponent(e)}`:``}`))}async function Zm(e){return Jm(await H(`GET`,`/api/playbook-patches/${e}/preview`))}async function Qm(e){return Jm(await H(`POST`,`/api/playbook-patches/${e}/accept`))}async function $m(e,t){let n=t?.trim();return Jm(await H(`POST`,`/api/playbook-patches/${e}/reject`,n?{reason:n}:{}))}async function eh(e){return Jm(await H(`GET`,`/api/playbooks/${e}/events/count`))}async function th(e){let t=await e.json();if(!t.success)throw Error(t.error??`Request failed`);return t.data}async function nh(e){let t=new URLSearchParams({available:`1`});return e&&t.set(`playbookId`,e),(await th(await H(`GET`,`/api/feedback-signals/count?${t.toString()}`))).open}async function rh(e){let t=new URLSearchParams;return e?.status&&t.set(`status`,e.status),e?.playbookId&&t.set(`playbookId`,e.playbookId),e?.deckId&&t.set(`deckId`,e.deckId),e?.excludeInProposal!==void 0&&t.set(`excludeInProposal`,e.excludeInProposal?`true`:`false`),th(await H(`GET`,`/api/feedback-signals${t.toString()?`?${t.toString()}`:``}`))}async function ih(e){return th(await H(`POST`,`/api/feedback-signals/discard`,{signalIds:e}))}function ah(e){return!!e.linkedPatchId&&e.status===`open`}function oh(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`)}"`}function sh(e){return e==null||e===``?`null`:oh(e)}function ch(e){return`Propose playbook updates from these Agent Deck feedback signals (copied from the Feedback table).
|
|
133
133
|
|
|
@@ -186,7 +186,7 @@ npx @piotr-agier/google-drive-mcp auth`})]}),(0,V.jsxs)(`li`,{children:[`Set `,(
|
|
|
186
186
|
|
|
187
187
|
${F.data.oauth.authorizationUrl?`Authorization URL: ${F.data.oauth.authorizationUrl}`:``}
|
|
188
188
|
${F.data.oauth.tokenUrl?`Token URL: ${F.data.oauth.tokenUrl}`:``}
|
|
189
|
-
${F.data.oauth.issuer?`Issuer: ${F.data.oauth.issuer}`:``}`;A({title:`OAuth Setup Instructions`,description:e,duration:1e4})},children:`📋 Setup Instructions`})]})]}),(0,V.jsxs)(`div`,{className:`mt-2 text-xs`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`💡 Next Steps:`})}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside ml-2 space-y-1`,children:[(0,V.jsx)(`li`,{children:`For OAuth servers: Provide OAuth credentials in service settings`}),(0,V.jsx)(`li`,{children:`For SSE servers: We'll automatically use the correct protocol`}),(0,V.jsx)(`li`,{children:`For connection issues: Verify the server URL and status`})]})]})]}),L&&(0,V.jsxs)(`div`,{className:`mt-3 p-3 bg-red-500/20 rounded`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`❌ Discovery Failed`})}),(0,V.jsx)(`p`,{children:`Could not analyze MCP server configuration`}),(0,V.jsx)(`pre`,{className:`text-xs overflow-x-auto`,children:L instanceof Error?L.message:String(L)})]})]})]}),!de&&!ie&&!ce&&e.type===`a2a`&&!ue&&(0,V.jsxs)(`div`,{className:`bg-yellow-500/20 border border-yellow-500/30 rounded-lg p-4`,children:[(0,V.jsx)(`h3`,{className:`text-yellow-300 font-semibold mb-2`,children:`Agent Details Not Available`}),(0,V.jsxs)(`p`,{className:`text-yellow-200 text-sm`,children:[`Successfully connected to A2A agent at `,M?.url,`, but no manifest was found.`]}),(0,V.jsxs)(`div`,{className:`text-yellow-200 text-xs mt-2`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`This could mean:`})}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside ml-2 space-y-1`,children:[(0,V.jsx)(`li`,{children:`The agent doesn't provide a manifest`}),(0,V.jsx)(`li`,{children:`Manifest endpoint is not implemented`}),(0,V.jsx)(`li`,{children:`Agent requires specific authentication`})]})]})]})]})]})})}function TE({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[o,s]=(0,b.useState)(null),[c,l]=(0,b.useState)(!1),u=Et(),{toast:d}=on(),f=()=>{r(null),a(null),s(null),l(!1)},p=Ht({mutationFn:async()=>{if(!n)throw Error(`Choose a bundle file first`);let e=await n.text(),t;try{t=JSON.parse(e)}catch{throw Error(`File is not valid JSON`)}return Vm(t)},onSuccess:e=>{s(e),u.invalidateQueries({queryKey:[`/api/decks`]}),u.invalidateQueries({queryKey:[`/api/services`]}),u.invalidateQueries({queryKey:[`/api/playbooks`]}),u.invalidateQueries({queryKey:[`/api/playbooks/collection`]}),u.invalidateQueries({queryKey:[`/api/credentials/collection`]}),u.invalidateQueries({queryKey:[`/api/collection/warnings`]}),d({title:`Import complete`,description:Wm(e)})},onError:e=>{d({title:`Import failed`,description:e.message,variant:`destructive`})}}),m=async e=>{if(r(e),s(null),!e){a(null);return}try{let t=await e.text(),n=JSON.parse(t);a(`${n.services?.length??0} services · ${n.playbooks?.length??0} playbooks · ${n.decks?.length??0} decks`)}catch{a(`Invalid JSON`)}};return(0,V.jsx)(Dp,{open:e,onOpenChange:e=>{e||f(),t(e)},children:(0,V.jsxs)(Ap,{className:`sm:max-w-lg border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{children:`Import bundle`}),(0,V.jsx)(Np,{asChild:!0,children:(0,V.jsxs)(`div`,{className:`space-y-2 text-left text-sm text-[#A8C4C0]`,children:[(0,V.jsx)(`p`,{children:`Adds MCP, playbooks, and decks from a JSON file.`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`font-medium text-amber-200/90`,children:`Notes`}),(0,V.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4`,children:[(0,V.jsx)(`li`,{children:`Same name as an existing card or deck is skipped (linked only).`}),(0,V.jsx)(`li`,{children:`No credentials or secrets — re-enter keys and reconnect OAuth.`})]})]})]})})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`bundle-file`,children:`Bundle file`}),(0,V.jsx)(uu,{id:`bundle-file`,type:`file`,accept:`.json,.agent-deck.json,application/json`,className:`cursor-pointer bg-white/5 border-white/20`,onChange:e=>m(e.target.files?.[0]??null),"data-testid":`input-import-bundle`}),i&&(0,V.jsx)(`p`,{className:`text-xs text-[#A8C4C0]`,"data-testid":`import-preview`,children:i})]}),!o&&(0,V.jsx)(G,{onClick:()=>p.mutate(),disabled:!n||p.isPending||i===`Invalid JSON`,className:`rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},"data-testid":`button-import-apply`,children:p.isPending?`Importing…`:`Import`}),o&&(0,V.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-white/10 bg-white/5 p-3 text-sm`,"data-testid":`import-report`,children:[(0,V.jsx)(`p`,{className:`font-medium`,children:Wm(o)}),o.servicesNeedingOauth.length>0&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-amber-200`,children:`Needs OAuth reconnect:`}),(0,V.jsx)(`ul`,{className:`list-disc pl-5 text-[#A8C4C0]`,children:o.servicesNeedingOauth.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}),o.warnings.length>0&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-amber-200`,children:`Warnings:`}),(0,V.jsx)(`ul`,{className:`list-disc pl-5 text-[#A8C4C0]`,children:o.warnings.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}),(0,V.jsx)(G,{variant:`outline`,size:`sm`,className:`rounded-full border border-white/20 text-white hover:bg-white/10`,onClick:()=>l(e=>!e),children:c?`Hide id map`:`Show id map`}),c&&(0,V.jsx)(`pre`,{className:`max-h-40 overflow-auto rounded bg-black/40 p-2 text-xs`,children:JSON.stringify(o.idMap,null,2)}),(0,V.jsx)(G,{className:`rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},onClick:()=>{f(),t(!1)},children:`Done`})]})]})]})})}function EE(){let[e,t]=(0,b.useState)(`connecting`),[n,r]=(0,b.useState)(null),i=(0,b.useRef)(null),a=(0,b.useRef)(null),o=Et();return(0,b.useEffect)(()=>{let e=`${window.location.protocol===`https:`?`wss:`:`ws:`}//${window.location.host}/api/ws/events`,n=()=>{try{let s=new WebSocket(e);i.current=s,s.onopen=()=>{console.log(`WebSocket connected`),t(`connected`)},s.onmessage=e=>{try{let n=JSON.parse(e.data);r(n),n.type===`deck_update`?(console.log(`Received deck update:`,n),o.invalidateQueries({queryKey:[`/api/decks`]})):n.type===`service_update`?(console.log(`Received service update:`,n),pE(o,typeof n.data?.serviceId==`string`?n.data.serviceId:void 0)):n.type===`connection_status`&&t(n.status===`connected`?`connected`:`disconnected`)}catch(e){console.error(`Failed to parse WebSocket message:`,e)}},s.onclose=()=>{console.log(`WebSocket disconnected`),t(`disconnected`),a.current=setTimeout(()=>{console.log(`Attempting to reconnect WebSocket...`),t(`connecting`),n()},3e3)},s.onerror=e=>{console.error(`WebSocket error:`,e),t(`disconnected`)}}catch(e){console.error(`Failed to connect WebSocket:`,e),t(`disconnected`)}};n();let s=e=>{e.origin===window.location.origin&&hE(e.data)&&pE(o,e.data.serviceId)};return window.addEventListener(`message`,s),()=>{window.removeEventListener(`message`,s),a.current&&clearTimeout(a.current),i.current&&i.current.readyState===WebSocket.OPEN&&i.current.close()}},[o]),{connectionStatus:e,lastMessage:n}}async function DE(e,t){return(await(await H(`GET`,`/api/playbooks/dependents/check?${e===`credential`?`credentialId=${encodeURIComponent(t)}`:`serviceId=${encodeURIComponent(t)}`}`)).json()).data??[]}function OE(e){let[t,n]=(0,b.useState)(null),[r,i]=(0,b.useState)(null),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(!1),l=Et(),{toast:u}=on(),d=()=>{if(!e)throw Error(`Select a deck to edit first`);return e},f=Ht({mutationFn:async e=>{let t=d(),n=(await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t);if(!n)throw Error(`Selected deck not found`);if(n.services?.some(t=>t.id===e))throw Error(`Service is already in the deck`);let r=n.services?.length??0;return H(`POST`,`/api/decks/${t}/services`,{serviceId:e,position:r})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Service added to deck`,description:`${t?.name||`Service`} has been added to the deck.`})},onError:e=>{u({title:`Failed to add service`,description:e.message,variant:`destructive`})}}),p=Ht({mutationFn:async e=>{let t=d();if(((await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t))?.credentials?.some(t=>t.id===e))throw Error(`API key is already in the deck`);return H(`POST`,`/api/decks/${t}/credentials`,{credentialId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`API key added to deck`,description:`${r?.label||`API key`} is scoped to this deck.`})},onError:e=>{u({title:`Failed to add API key`,description:e.message,variant:`destructive`})}}),m=Ht({mutationFn:async e=>{let t=d();if(((await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t))?.playbooks?.some(t=>t.id===e))throw Error(`Playbook is already in the deck`);return H(`POST`,`/api/decks/${t}/playbooks`,{playbookId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Playbook added to deck`,description:`${a?.title||`Playbook`} is on this deck.`})},onError:e=>{u({title:`Failed to add playbook`,description:e.message,variant:`destructive`})}}),h=Ht({mutationFn:async e=>{let t=await DE(`service`,e);if(t.length>0){let e=t.map(e=>e.title).join(`, `);if(!window.confirm(`Warning: ${t.length} playbook(s) depend on this MCP (${e}). Remove from deck anyway?`))throw Error(`Cancelled`)}return H(`DELETE`,`/api/decks/${d()}/services`,{serviceId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Service removed from deck`,description:`${t?.name||`Service`} has been removed from the deck.`})},onError:e=>{e.message!==`Cancelled`&&u({title:`Failed to remove service`,description:e.message,variant:`destructive`})}}),g=Ht({mutationFn:async e=>{let t=await DE(`credential`,e);if(t.length>0){let e=t.map(e=>e.title).join(`, `);if(!window.confirm(`Warning: ${t.length} playbook(s) depend on this API key (${e}). Remove from deck anyway?`))throw Error(`Cancelled`)}return H(`DELETE`,`/api/decks/${d()}/credentials`,{credentialId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`API key removed from deck`,description:`${r?.label||`API key`} is no longer on this deck.`})},onError:e=>{e.message!==`Cancelled`&&u({title:`Failed to remove API key`,description:e.message,variant:`destructive`})}}),_=Ht({mutationFn:async e=>H(`DELETE`,`/api/decks/${d()}/playbooks`,{playbookId:e}),onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Playbook removed from deck`,description:`${a?.title||`Playbook`} is no longer on this deck.`})},onError:e=>{u({title:`Failed to remove playbook`,description:e.message,variant:`destructive`})}}),v=(e,t)=>{e.currentTarget instanceof HTMLElement&&(e.currentTarget.style.opacity=t)},y=(e,t)=>{e.dataTransfer.setData(`text/plain`,t.id),e.dataTransfer.setData(`application/json`,JSON.stringify(t)),e.dataTransfer.effectAllowed=t.fromDeck?`move`:`copy`},x=(e,t,r=!1)=>{n(t),i(null),o(null),c(r),y(e,{kind:`service`,id:t.id,fromDeck:r}),v(e,`0.5`)},S=(e,t,r=!1)=>{i(t),n(null),o(null),c(r),y(e,{kind:`credential`,id:t.id,fromDeck:r}),v(e,`0.5`)},C=(e,t,r=!1)=>{o(t),n(null),i(null),c(r),y(e,{kind:`playbook`,id:t.id,fromDeck:r}),v(e,`0.5`)},w=e=>{n(null),i(null),o(null),v(e,`1`)},T=e=>{if(e.kind===`service`){e.fromDeck?h.mutate(e.id):f.mutate(e.id);return}if(e.kind===`credential`){e.fromDeck?g.mutate(e.id):p.mutate(e.id);return}e.fromDeck?_.mutate(e.id):m.mutate(e.id)};return{draggedService:t,draggedCredential:r,draggedPlaybook:a,isDraggingFromDeck:s,handleDragStart:x,handleCredentialDragStart:S,handlePlaybookDragStart:C,handleDragEnd:w,handleDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData(`application/json`);if(r){try{T(JSON.parse(r))}catch{let n=e.dataTransfer.getData(`text/plain`);n&&t&&f.mutate(n)}n(null),i(null),o(null),c(!1)}},handleGlobalDrop:e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/json`);if(t){try{let e=JSON.parse(t);e.fromDeck&&T(e)}catch{}n(null),i(null),o(null),c(!1)}},isDropping:f.isPending||p.isPending||m.isPending||h.isPending||g.isPending||_.isPending}}var kE=`agent-deck-editing-deck-id`;function AE(e){let[t,n]=(0,b.useState)(()=>typeof window>`u`?null:localStorage.getItem(kE));return(0,b.useEffect)(()=>{if(e.length!==0&&!(t&&e.some(e=>e.id===t))){let t=e[0].id;n(t),localStorage.setItem(kE,t)}},[e,t]),{editingDeck:e.find(e=>e.id===t)??null,editingDeckId:t,setEditingDeckId:e=>{n(e),localStorage.setItem(kE,e)}}}function jE(e,[t,n]){return Math.min(n,Math.max(t,e))}function ME(e){let t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var NE=[` `,`Enter`,`ArrowUp`,`ArrowDown`],PE=[` `,`Enter`],FE=`Select`,[IE,LE,RE]=Sn(FE),[zE,BE]=fn(FE,[RE,Ec]),VE=Ec(),[HE,UE]=zE(FE),[WE,GE]=zE(FE),KE=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=VE(t),[g,_]=b.useState(null),[v,y]=b.useState(null),[x,S]=b.useState(!1),C=Vp(l),[w,T]=Zn({prop:r,defaultProp:i??!1,onChange:a,caller:FE}),[E,D]=Zn({prop:o,defaultProp:s,onChange:c,caller:FE}),O=b.useRef(null),k=!g||m||!!g.closest(`form`),[A,j]=b.useState(new Set),M=Array.from(A).map(e=>e.props.value).join(`;`);return(0,V.jsx)(Hc,{...h,children:(0,V.jsxs)(HE,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:to(),value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,children:[(0,V.jsx)(IE.Provider,{scope:t,children:(0,V.jsx)(WE,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(e=>{j(t=>new Set(t).add(e))},[]),onNativeOptionRemove:b.useCallback(e=>{j(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),k?(0,V.jsxs)(VD,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:E,onChange:e=>D(e.target.value),disabled:f,form:m,children:[E===void 0?(0,V.jsx)(`option`,{value:``}):null,Array.from(A)]},M):null]})})};KE.displayName=FE;var qE=`SelectTrigger`,JE=b.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=VE(n),o=UE(qE,n),s=o.disabled||r,c=un(t,o.onTriggerChange),l=LE(n),u=b.useRef(`touch`),[d,f,p]=UD(e=>{let t=l().filter(e=>!e.disabled),n=WD(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,V.jsx)(Uc,{asChild:!0,...a,children:(0,V.jsx)(Cn.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":HD(o.value)?``:void 0,...i,ref:c,onClick:U(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:U(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:U(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&NE.includes(e.key)&&(m(),e.preventDefault())})})})});JE.displayName=qE;var YE=`SelectValue`,XE=b.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=UE(YE,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=un(t,c.onValueNodeChange);return Hn(()=>{l(u)},[l,u]),(0,V.jsx)(Cn.span,{...s,ref:d,style:{pointerEvents:`none`},children:HD(c.value)?(0,V.jsx)(V.Fragment,{children:o}):a})});XE.displayName=YE;var ZE=`SelectIcon`,QE=b.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,V.jsx)(Cn.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});QE.displayName=ZE;var $E=`SelectPortal`,eD=e=>(0,V.jsx)(Wn,{asChild:!0,...e});eD.displayName=$E;var tD=`SelectContent`,nD=b.forwardRef((e,t)=>{let n=UE(tD,e.__scopeSelect),[r,i]=b.useState();if(Hn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?sn.createPortal((0,V.jsx)(iD,{scope:e.__scopeSelect,children:(0,V.jsx)(IE.Slot,{scope:e.__scopeSelect,children:(0,V.jsx)(`div`,{children:e.children})})}),t):null}return(0,V.jsx)(cD,{...e,ref:t})});nD.displayName=tD;var rD=10,[iD,aD]=zE(tD),oD=`SelectContentImpl`,sD=mn(`SelectContent.RemoveScroll`),cD=b.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=UE(tD,n),[y,x]=b.useState(null),[S,C]=b.useState(null),w=un(t,e=>x(e)),[T,E]=b.useState(null),[D,O]=b.useState(null),k=LE(n),[A,j]=b.useState(!1),M=b.useRef(!1);b.useEffect(()=>{if(y)return zu(y)},[y]),pu();let N=b.useCallback(e=>{let[t,...n]=k().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&S&&(S.scrollTop=0),n===r&&S&&(S.scrollTop=S.scrollHeight),n?.focus(),document.activeElement!==i))return},[k,S]),P=b.useCallback(()=>N([T,y]),[N,T,y]);b.useEffect(()=>{A&&P()},[A,P]);let{onOpenChange:F,triggerPointerDownPosRef:I}=v;b.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(I.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(I.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||F(!1),document.removeEventListener(`pointermove`,t),I.current=null};return I.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,F,I]),b.useEffect(()=>{let e=()=>F(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[F]);let[L,ee]=UD(e=>{let t=k().filter(e=>!e.disabled),n=WD(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),te=b.useCallback((e,t,n)=>{let r=!M.current&&!n;(v.value!==void 0&&v.value===t||r)&&(E(e),r&&(M.current=!0))},[v.value]),ne=b.useCallback(()=>y?.focus(),[y]),R=b.useCallback((e,t,n)=>{let r=!M.current&&!n;(v.value!==void 0&&v.value===t||r)&&O(e)},[v.value]),z=r===`popper`?fD:uD,B=z===fD?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,V.jsx)(iD,{scope:n,content:y,viewport:S,onViewportChange:C,itemRefCallback:te,selectedItem:T,onItemLeave:ne,itemTextRefCallback:R,focusSelectedItem:P,selectedItemText:D,position:r,isPositioned:A,searchRef:L,children:(0,V.jsx)(qd,{as:sD,allowPinchZoom:!0,children:(0,V.jsx)(yu,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:U(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,V.jsx)(Nn,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,V.jsx)(z,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...B,onPlaced:()=>j(!0),ref:w,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:U(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&ee(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=k().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>N(t)),e.preventDefault()}})})})})})})});cD.displayName=oD;var lD=`SelectItemAlignedPosition`,uD=b.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=UE(tD,n),o=aD(tD,n),[s,c]=b.useState(null),[l,u]=b.useState(null),d=un(t,e=>u(e)),f=LE(n),p=b.useRef(!1),m=b.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=b.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-rD,d=jE(a,[rD,Math.max(rD,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-rD,d=jE(a,[rD,Math.max(rD,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-rD*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-rD,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${rD}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Hn(()=>y(),[y]);let[x,S]=b.useState();Hn(()=>{l&&S(window.getComputedStyle(l).zIndex)},[l]);let C=b.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]);return(0,V.jsx)(pD,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:(0,V.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:x},children:(0,V.jsx)(Cn.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});uD.displayName=lD;var dD=`SelectPopperPosition`,fD=b.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=rD,...a}=e,o=VE(n);return(0,V.jsx)(Wc,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});fD.displayName=dD;var[pD,mD]=zE(tD,{}),hD=`SelectViewport`,gD=b.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=aD(hD,n),o=mD(hD,n),s=un(t,a.onViewportChange),c=b.useRef(0);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,V.jsx)(IE.Slot,{scope:n,children:(0,V.jsx)(Cn.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:U(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-rD*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});gD.displayName=hD;var _D=`SelectGroup`,[vD,yD]=zE(_D),bD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=to();return(0,V.jsx)(vD,{scope:n,id:i,children:(0,V.jsx)(Cn.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});bD.displayName=_D;var xD=`SelectLabel`,SD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=yD(xD,n);return(0,V.jsx)(Cn.div,{id:i.id,...r,ref:t})});SD.displayName=xD;var CD=`SelectItem`,[wD,TD]=zE(CD),ED=b.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=UE(CD,n),c=aD(CD,n),l=s.value===r,[u,d]=b.useState(a??``),[f,p]=b.useState(!1),m=un(t,e=>c.itemRefCallback?.(e,r,i)),h=to(),g=b.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,V.jsx)(wD,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:b.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,V.jsx)(IE.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,V.jsx)(Cn.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:U(o.onFocus,()=>p(!0)),onBlur:U(o.onBlur,()=>p(!1)),onClick:U(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:U(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:U(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:U(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:U(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:U(o.onKeyDown,e=>{(c.searchRef?.current===``||e.key!==` `)&&(PE.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});ED.displayName=CD;var DD=`SelectItemText`,OD=b.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=UE(DD,n),s=aD(DD,n),c=TD(DD,n),l=GE(DD,n),[u,d]=b.useState(null),f=un(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=b.useMemo(()=>(0,V.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return Hn(()=>(h(m),()=>g(m)),[h,g,m]),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Cn.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?sn.createPortal(a.children,o.valueNode):null]})});OD.displayName=DD;var kD=`SelectItemIndicator`,AD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return TD(kD,n).isSelected?(0,V.jsx)(Cn.span,{"aria-hidden":!0,...r,ref:t}):null});AD.displayName=kD;var jD=`SelectScrollUpButton`,MD=b.forwardRef((e,t)=>{let n=aD(jD,e.__scopeSelect),r=mD(jD,e.__scopeSelect),[i,a]=b.useState(!1),o=un(t,r.onScrollButtonChange);return Hn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,V.jsx)(FD,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});MD.displayName=jD;var ND=`SelectScrollDownButton`,PD=b.forwardRef((e,t)=>{let n=aD(ND,e.__scopeSelect),r=mD(ND,e.__scopeSelect),[i,a]=b.useState(!1),o=un(t,r.onScrollButtonChange);return Hn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,V.jsx)(FD,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});PD.displayName=ND;var FD=b.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=aD(`SelectScrollButton`,n),o=b.useRef(null),s=LE(n),c=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>c(),[c]),Hn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,V.jsx)(Cn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:U(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:U(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:U(i.onPointerLeave,()=>{c()})})}),ID=`SelectSeparator`,LD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,V.jsx)(Cn.div,{"aria-hidden":!0,...r,ref:t})});LD.displayName=ID;var RD=`SelectArrow`,zD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=VE(n),a=UE(RD,n),o=aD(RD,n);return a.open&&o.position===`popper`?(0,V.jsx)(Gc,{...i,...r,ref:t}):null});zD.displayName=RD;var BD=`SelectBubbleInput`,VD=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=b.useRef(null),a=un(r,i),o=ME(t);return b.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,V.jsx)(Cn.select,{...n,style:{...er,...n.style},ref:a,defaultValue:t})});VD.displayName=BD;function HD(e){return e===``||e===void 0}function UD(e){let t=Tn(e),n=b.useRef(``),r=b.useRef(0),i=b.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=b.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function WD(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=GD(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function GD(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var KD=KE,qD=JE,JD=XE,YD=QE,XD=eD,ZD=nD,QD=gD,$D=SD,eO=ED,tO=OD,nO=AD,rO=MD,iO=PD,aO=LD,oO=KD,sO=JD,cO=b.forwardRef(({className:e,children:t,...n},r)=>(0,V.jsxs)(qD,{ref:r,className:W(`flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,V.jsx)(YD,{asChild:!0,children:(0,V.jsx)(gi,{className:`h-4 w-4 opacity-50`})})]}));cO.displayName=qD.displayName;var lO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(rO,{ref:n,className:W(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,V.jsx)(yi,{className:`h-4 w-4`})}));lO.displayName=rO.displayName;var uO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(iO,{ref:n,className:W(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,V.jsx)(gi,{className:`h-4 w-4`})}));uO.displayName=iO.displayName;var dO=b.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,V.jsx)(XD,{children:(0,V.jsxs)(ZD,{ref:i,className:W(`relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,V.jsx)(lO,{}),(0,V.jsx)(QD,{className:W(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,V.jsx)(uO,{})]})}));dO.displayName=ZD.displayName;var fO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)($D,{ref:n,className:W(`py-1.5 pl-8 pr-2 text-sm font-semibold`,e),...t}));fO.displayName=$D.displayName;var pO=b.forwardRef(({className:e,children:t,...n},r)=>(0,V.jsxs)(eO,{ref:r,className:W(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,V.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,V.jsx)(nO,{children:(0,V.jsx)(hi,{className:`h-4 w-4`})})}),(0,V.jsx)(tO,{children:t})]}));pO.displayName=eO.displayName;var mO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(aO,{ref:n,className:W(`-mx-1 my-1 h-px bg-muted`,e),...t}));mO.displayName=aO.displayName;var hO=`/assets/AgentDeckLogo3-X5qCXS2A.png`;function gO(){let[e,t]=(0,b.useState)(``),[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(null),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(null),[g,_]=(0,b.useState)(!1),[v,y]=(0,b.useState)(!1),[x,S]=(0,b.useState)(null),[C,w]=(0,b.useState)(!1),[T,E]=(0,b.useState)(!1),[D,O]=(0,b.useState)(!1),[k,A]=(0,b.useState)(null),{toast:j}=on(),{data:M=[]}=Vt({queryKey:[`/api/playbook-patches`,`proposed`],queryFn:()=>Xm(`proposed`)}),{data:N=0}=Vt({queryKey:[`/api/feedback-signals/count`,`available`],queryFn:()=>nh()}),P=async()=>{O(!0);try{let e=await Bm({scope:`collection`});Hm(e,`backup.agent-deck.json`),j({title:`Exported collection`,description:`${e.services.length} services, ${e.playbooks.length} playbooks, ${e.decks.length} decks`})}catch(e){j({title:`Export failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{O(!1)}},{connectionStatus:F}=EE(),{data:I,isLoading:L,error:ee}=Vt({queryKey:[`/api/decks`]}),te=I?.data||[],{editingDeck:ne,editingDeckId:R,setEditingDeckId:z}=AE(te),{handleDragStart:B,handleCredentialDragStart:re,handlePlaybookDragStart:ie,handleDragEnd:ae,handleDrop:oe,handleGlobalDrop:se,isDraggingFromDeck:ce}=OE(R),{data:le,isLoading:ue,error:de}=Vt({queryKey:[`/api/services`]}),{data:fe,isLoading:pe}=Vt({queryKey:[`/api/credentials/vault`]}),{data:me,isLoading:he}=Vt({queryKey:[`/api/playbooks/vault`]}),{data:ge}=Vt({queryKey:[`/api/collection/warnings`],staleTime:6e4}),_e=le?.data||[],ve=fe?.data||[],be=me?.data||[],xe=(0,b.useMemo)(()=>Ol(ge?.data),[ge?.data]),Se=(e,t)=>i?e===`service`?xe.serviceWarnings.has(t):e===`credential`?xe.credentialWarnings.has(t):xe.playbookWarnings.has(t):!0,Ce=_e.filter(t=>{if(!Se(`service`,t.id)||n===`api-key`||n===`playbook`)return!1;let r=t.name.toLowerCase().includes(e.toLowerCase())||t.description?.toLowerCase().includes(e.toLowerCase()),i=!n||n===`all`||t.type===n;return r&&i}),we=ve.filter(t=>!Se(`credential`,t.id)||n&&n!==`all`&&n!==`api-key`?!1:t.label.toLowerCase().includes(e.toLowerCase())),Te=be.filter(t=>!Se(`playbook`,t.id)||n&&n!==`all`&&n!==`playbook`?!1:t.title.toLowerCase().includes(e.toLowerCase())||t.body.toLowerCase().includes(e.toLowerCase())),Ee=Ce.length+we.length+Te.length;de&&console.error(`Services error:`,de),ee&&console.error(`Decks error:`,ee);let De=()=>{t(``),r(``),a(!1)},Oe=!!(e||n||i),ke=new Set((ne?.credentials??[]).map(e=>e.id)),Ae=new Set((ne?.playbooks??[]).map(e=>e.id)),je=ne?.services||[],Me=ne?.playbooks||[],Ne=e=>{l(e),d(!0)},Pe=e=>{S(e.id),w(!0)},Fe=e=>{h(e.id),_(!0)},Ie=e=>{A(e)};if(de||ee){let e=Wt(ee)||Wt(de),t=(ee instanceof Error?ee.message:null)??(de instanceof Error?de.message:null)??`There was an error loading the application data.`;return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center max-w-lg px-4`,children:[(0,V.jsx)(`h2`,{className:`text-2xl font-bold text-red-400 mb-4`,children:e?`Dashboard Access Expired`:`Error Loading Data`}),e?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-gray-300 mb-2`,children:`Dashboard access has expired.`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:`Reopen it securely from your terminal or the Agent Deck menubar.`}),(0,V.jsx)(`code`,{className:`mb-6 block rounded bg-black/30 px-3 py-2 text-gray-200`,children:`agent-deck open`}),(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(`agent-deck open`).then(()=>{j({title:`Command copied`,description:`Run it in your terminal.`})})},className:`px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700`,children:`Copy Command`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-gray-300 mb-2`,children:`There was an error loading the application data.`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:t}),(0,V.jsxs)(`p`,{className:`text-gray-500 text-xs mb-6`,children:[`Is the API running? Try `,(0,V.jsx)(`code`,{className:`text-gray-300`,children:`agent-deck stop && agent-deck start`})]}),(0,V.jsx)(`button`,{onClick:()=>window.location.reload(),className:`px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700`,children:`Reload Page`})]})]})})}return ue||L||pe||he?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-12 w-12 border-b-2 border-yellow-400 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-300`,children:`Loading AgentDeck...`})]})}):(0,V.jsxs)(`div`,{className:`flex min-h-dvh flex-col overflow-x-hidden`,onDrop:se,onDragOver:e=>e.preventDefault(),style:{position:`relative`,...ce&&{background:`linear-gradient(to bottom right, #1a1a2e, #16213e, #0f3460)`}},children:[(0,V.jsx)(`header`,{className:`relative z-20 shrink-0 bg-black/30 backdrop-blur-md border-b border-white/10`,children:(0,V.jsx)(`div`,{className:`container mx-auto px-4 py-3 sm:py-4`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 sm:gap-4`,children:[(0,V.jsx)(`img`,{src:hO,alt:`Agent Deck Logo`,className:`h-12 w-12 shrink-0 object-contain sm:h-16 sm:w-16`}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`h1`,{className:`text-xl font-bold bg-gradient-to-r from-yellow-400 to-yellow-600 bg-clip-text text-transparent sm:text-2xl`,style:{background:`linear-gradient(to right, #C4B643, #D4C760)`,WebkitBackgroundClip:`text`,WebkitTextFillColor:`transparent`,backgroundClip:`text`},children:`AgentDeck`}),(0,V.jsx)(`p`,{className:`text-xs sm:text-sm`,style:{color:`#92E4DD`},children:`Build tool deck for your agent`})]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-2 px-3 py-1 rounded-full border ${F===`connected`?`bg-emerald-500/20 border-emerald-500/30`:`bg-red-500/20 border-red-500/30`}`,children:[(0,V.jsx)(`div`,{className:`w-2 h-2 rounded-full animate-pulse ${F===`connected`?`bg-emerald-400`:`bg-red-400`}`}),(0,V.jsx)(`button`,{className:`text-sm hover:underline cursor-pointer ${F===`connected`?`text-emerald-300`:`text-red-300`}`,"data-testid":`button-copy-mcp-url`,onClick:()=>{navigator.clipboard.writeText(`http://localhost:3001/mcp`).then(()=>{j({title:`MCP URL copied!`,description:`The MCP server URL has been copied to your clipboard.`})})},title:`Click to copy MCP URL`,children:`Get MCP URL`})]}),(0,V.jsx)(zf,{highlightDeckId:R??void 0}),(0,V.jsx)(ye,{href:`/feedback-signals`,children:(0,V.jsxs)(G,{variant:`outline`,size:`sm`,className:`relative border-white/20 bg-white/5 text-[#E8F6F4]`,children:[`Feedback`,N>0&&(0,V.jsx)(`span`,{className:`ml-2 rounded-full px-2 py-0.5 text-xs font-semibold`,style:{background:`#C4B643`,color:`#0A0A07`},title:`Open feedback available for curation`,children:N})]})}),(0,V.jsx)(ye,{href:`/playbook-patches`,children:(0,V.jsxs)(G,{variant:`outline`,size:`sm`,className:`relative border-white/20 bg-white/5 text-[#E8F6F4]`,children:[(0,V.jsx)(ki,{className:`mr-2 h-4 w-4`}),`Review`,M.length>0&&(0,V.jsx)(`span`,{className:`ml-2 rounded-full px-2 py-0.5 text-xs font-semibold`,style:{background:`#C4B643`,color:`#0A0A07`},title:`Proposed playbook patches`,children:M.length})]})})]})]})})}),ce&&(0,V.jsx)(`div`,{className:`fixed inset-0 pointer-events-none z-50 flex items-center justify-center`,children:(0,V.jsxs)(`div`,{className:`bg-red-500/20 border-2 border-dashed border-red-500/50 rounded-lg p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`text-red-400 text-lg font-bold mb-2`,children:`Drop to Remove`}),(0,V.jsx)(`div`,{className:`text-red-300 text-sm`,children:`Release to remove card from deck`})]})}),(0,V.jsx)(`main`,{className:`container mx-auto flex min-h-0 flex-1 flex-col px-4 py-4 sm:py-6`,children:(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 sm:gap-6 xl:min-h-0 xl:flex-1 xl:grid-cols-4 xl:overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4 sm:space-y-6 xl:col-span-1 xl:min-h-0 xl:overflow-y-auto`,children:[(0,V.jsx)(`div`,{className:`panel-surface h-64 overflow-hidden p-4 min-w-0 sm:h-72 xl:h-80`,children:(0,V.jsx)(Gm,{decks:te,editingDeckId:R,onSelectDeck:z,isLoading:L})}),(0,V.jsxs)(`div`,{className:`panel-surface p-4`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold mb-3 flex items-center`,children:[(0,V.jsx)(di,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{style:{color:`#92E4DD`},children:`Add Cards`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(kl),onClick:()=>s(!0),"data-testid":`button-register-mcp`,children:[(0,V.jsx)(zi,{className:`w-3 h-3 mr-2`}),`Register MCP`]}),(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(Al),onClick:()=>p(!0),"data-testid":`button-register-api-key`,children:[(0,V.jsx)(Ai,{className:`w-3 h-3 mr-2`}),`Register API key`]}),(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(jl),onClick:()=>y(!0),"data-testid":`button-register-playbook`,children:[(0,V.jsx)(fi,{className:`w-3 h-3 mr-2`}),`Register Playbook`]})]})]})]}),(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 sm:gap-6 xl:col-span-3 xl:h-full xl:min-h-0`,children:[(0,V.jsx)(`div`,{className:`panel-surface h-64 shrink-0 overflow-hidden p-4 min-w-0 sm:h-72 xl:h-80`,children:ne?(0,V.jsx)(`div`,{className:`h-full`,children:(0,V.jsx)(du,{deck:ne,services:je,credentials:ne.credentials??[],playbooks:Me,allServices:_e,collectionWarnings:xe,onDrop:oe,onDragStart:B,onCredentialDragStart:re,onPlaybookDragStart:ie,onDragEnd:ae,onCardClick:Ne,onPlaybookClick:Pe,onCredentialClick:Fe})}):(0,V.jsxs)(`div`,{className:`text-center h-full flex flex-col justify-center`,children:[(0,V.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-yellow-500/20 border border-yellow-500/30 flex items-center justify-center mx-auto mb-3`,children:(0,V.jsx)(Mi,{className:`w-6 h-6 text-yellow-400`})}),(0,V.jsx)(`h3`,{className:`text-lg font-bold mb-2`,style:{color:`#92E4DD`},children:`No deck selected`}),(0,V.jsx)(`p`,{className:`text-gray-300 mb-4 text-sm`,children:`Create a deck or select one from the sidebar to edit its cards.`}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsxs)(G,{onClick:()=>{let e=document.querySelector(`[data-testid="create-deck-button"]`);e&&e.click()},className:`border text-sm py-2`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),`Create New Deck`]}),(0,V.jsxs)(G,{variant:`outline`,className:`border-white/20 text-white hover:bg-white/10 text-sm py-2`,onClick:()=>{let e=document.querySelector(`[data-testid="deck-management-panel"]`);e&&e.scrollIntoView({behavior:`smooth`})},children:[(0,V.jsx)(Mi,{className:`w-4 h-4 mr-2`}),`Manage Decks`]})]})]})}),(0,V.jsxs)(`div`,{className:`panel-surface flex min-h-[20rem] flex-col overflow-hidden p-4 min-w-0 sm:min-h-[24rem] xl:min-h-0 xl:flex-1`,"data-testid":`collection-panel`,children:[(0,V.jsxs)(`div`,{className:`mb-3 flex shrink-0 flex-wrap items-center justify-between gap-2`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold flex items-center`,children:[(0,V.jsx)(Ni,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{style:{color:`#92E4DD`},children:`My Collection`}),(0,V.jsxs)(`span`,{className:`ml-3 text-sm font-normal text-gray-400`,children:[`(`,Ee,` cards)`]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:P,disabled:D,title:`Export all MCP, playbooks, and decks`,"data-testid":`button-export-all`,children:[(0,V.jsx)(Ei,{className:`w-3 h-3 mr-1`}),D?`Exporting…`:`Export all`]}),(0,V.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:()=>E(!0),title:`Import a bundle file`,"data-testid":`button-import-bundle`,children:[(0,V.jsx)(Wi,{className:`w-3 h-3 mr-1`}),`Import`]}),(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(Ri,{className:`absolute left-2 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4`}),(0,V.jsx)(uu,{placeholder:`Search...`,value:e,onChange:e=>t(e.target.value),className:`h-8 w-36 pl-8 text-sm bg-white/10 border-white/20 text-white placeholder-gray-400 sm:w-48`,"data-testid":`input-search`})]}),(0,V.jsxs)(oO,{value:n||`all`,onValueChange:e=>r(e===`all`?``:e),children:[(0,V.jsxs)(cO,{className:`w-[7.5rem] h-8 bg-white/10 border-white/20 text-white text-xs shrink-0`,"data-testid":`select-type`,children:[(0,V.jsx)(Oi,{className:`w-3 h-3 mr-1 shrink-0`}),(0,V.jsx)(sO,{placeholder:`Type`})]}),(0,V.jsxs)(dO,{children:[(0,V.jsx)(pO,{value:`all`,children:`All`}),(0,V.jsx)(pO,{value:`mcp`,children:`MCP`}),(0,V.jsx)(pO,{value:`local-mcp`,children:`Local MCP`}),(0,V.jsx)(pO,{value:`api-key`,children:`API Key`}),(0,V.jsx)(pO,{value:`playbook`,children:`Playbook`})]})]}),(e||n||i)&&(0,V.jsx)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:De,title:`Clear all filters`,children:`Clear`})]})]}),xe.total>0&&(0,V.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`mb-3 w-full shrink-0 rounded-lg border px-3 py-2 text-left text-sm transition-colors ${i?`border-amber-300/60 bg-amber-500/15 text-amber-100`:`border-amber-400/30 bg-amber-500/10 text-amber-100 hover:bg-amber-500/15`}`,"data-testid":`button-collection-warnings`,children:(0,V.jsxs)(`span`,{className:`flex items-start gap-2`,children:[(0,V.jsx)(Ui,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-300`}),(0,V.jsx)(`span`,{children:i?(0,V.jsxs)(V.Fragment,{children:[`Showing `,(0,V.jsx)(`strong`,{children:Ee}),` card`,Ee===1?``:`s`,` needing attention.`,(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:` Click to show all cards.`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`strong`,{children:xe.total}),` card`,xe.total===1?``:`s`,` need attention`,xe.byKind.oauth_expired+xe.byKind.oauth_required>0&&(0,V.jsxs)(V.Fragment,{children:[` `,`(`,xe.byKind.oauth_expired+xe.byKind.oauth_required,` `,`OAuth)`]}),`. `,(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Click to filter.`})]})})]})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-1 py-2`,children:ue||pe||he?(0,V.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,5rem)] gap-y-2 pr-12`,children:Array.from({length:10}).map((e,t)=>(0,V.jsx)(`div`,{className:`animate-pulse`,children:(0,V.jsx)(`div`,{className:`bg-white/10 rounded-lg w-32 h-48 aspect-[2/3]`})},t))}):Ee===0?(0,V.jsxs)(`div`,{className:`text-center py-12`,children:[(0,V.jsx)(`div`,{className:`text-gray-400 mb-4`,children:(0,V.jsx)(`i`,{className:`fas fa-layer-group text-4xl`})}),(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-300 mb-2`,children:`No cards yet`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:Oe?i?`No cards with warnings match your current filters`:`Try adjusting your search or filters`:`Register an MCP server, API key, or playbook to get started`}),!Oe&&(0,V.jsxs)(`div`,{className:`flex gap-3 justify-center`,children:[(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#92E4DD`),onClick:()=>s(!0),"data-testid":`button-register-mcp-empty`,children:[(0,V.jsx)(zi,{className:`w-3 h-3 mr-1`}),`Register MCP`]}),(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#F9386D`),onClick:()=>p(!0),"data-testid":`button-register-api-key-empty`,children:[(0,V.jsx)(Ai,{className:`w-3 h-3 mr-1`}),`Register API key`]})]})]}):(0,V.jsxs)(`div`,{className:`relative isolate grid grid-cols-[repeat(auto-fill,5rem)] gap-y-2 pr-12`,style:{isolation:`isolate`},"data-testid":`collection-card-grid`,children:[Te.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-t},children:(0,V.jsx)(Yl,{playbook:e,isInActiveDeck:Ae.has(e.id),activeDeck:ne??void 0,isInCollection:!0,onDragStart:ie,onDragEnd:ae,onCardClick:Pe,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),warnings:xe.playbookWarnings.get(e.id)})},e.id)),we.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-Te.length-t},children:(0,V.jsx)(ql,{credential:e,isInActiveDeck:ke.has(e.id),activeDeck:ne??void 0,isInCollection:!0,onDragStart:re,onDragEnd:ae,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),onCardClick:Fe,warnings:xe.credentialWarnings.get(e.id)})},e.id)),Ce.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-Te.length-we.length-t},children:(0,V.jsx)(Ul,{service:e,onDragStart:B,onDragEnd:ae,isInActiveDeck:ne?.services?.some(t=>t.id===e.id)||!1,onCardClick:Ne,isInCollection:!0,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),activeDeck:ne??void 0,warnings:xe.serviceWarnings.get(e.id)})},e.id))]})})]})]})]})}),(0,V.jsxs)(`div`,{className:`fixed inset-0 pointer-events-none z-0 overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`absolute top-20 left-20`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-cyan-500/10 blur-3xl animate-orb-drift-1`})}),(0,V.jsx)(`div`,{className:`absolute bottom-20 right-20`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-pink-500/10 blur-3xl animate-orb-drift-2`})}),(0,V.jsx)(`div`,{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-purple-500/5 blur-3xl animate-orb-drift-3`})})]}),(0,V.jsx)(Rm,{type:`mcp`,open:o,onOpenChange:s}),(0,V.jsx)(wE,{service:c,isOpen:u,onClose:()=>d(!1)}),(0,V.jsx)(Km,{open:f,onOpenChange:p}),(0,V.jsx)(uh,{credentialId:m,open:g,onOpenChange:_}),(0,V.jsx)(qm,{open:v,onOpenChange:y}),(0,V.jsx)(lh,{playbookId:x,open:C,onOpenChange:w}),(0,V.jsx)(TE,{open:T,onOpenChange:E})]})}var _O=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`rounded-lg border bg-card text-card-foreground shadow-sm`,e),...t}));_O.displayName=`Card`;var vO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`flex flex-col space-y-1.5 p-6`,e),...t}));vO.displayName=`CardHeader`;var yO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`text-2xl font-semibold leading-none tracking-tight`,e),...t}));yO.displayName=`CardTitle`;var bO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`text-sm text-muted-foreground`,e),...t}));bO.displayName=`CardDescription`;var xO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`p-6 pt-0`,e),...t}));xO.displayName=`CardContent`;var SO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`flex items-center p-6 pt-0`,e),...t}));SO.displayName=`CardFooter`;function CO(){return(0,V.jsx)(`div`,{className:`min-h-screen w-full flex items-center justify-center bg-gray-50`,children:(0,V.jsx)(_O,{className:`w-full max-w-md mx-4`,children:(0,V.jsxs)(xO,{className:`pt-6`,children:[(0,V.jsxs)(`div`,{className:`flex mb-4 gap-2`,children:[(0,V.jsx)(bi,{className:`h-8 w-8 text-red-500`}),(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900`,children:`404 Page Not Found`})]}),(0,V.jsx)(`p`,{className:`mt-4 text-sm text-gray-600`,children:`Did you forget to add the page to the router?`})]})})})}function wO(){let[e]=pe(),[t,n]=(0,b.useState)(`loading`),[r,i]=(0,b.useState)(`Authenticating...`);return(0,b.useEffect)(()=>{(async()=>{try{let e=new URL(window.location.href),t=e.searchParams.get(`success`),r=e.searchParams.get(`error`),a=e.searchParams.get(`serviceId`);t===`true`?(n(`success`),i(`Authentication successful! This window will close automatically.`),window.opener&&!window.opener.closed&&window.opener.postMessage({type:mE,serviceId:a??void 0},window.location.origin),setTimeout(()=>{window.close()},2e3)):t===`false`?(n(`error`),i(`OAuth Error: ${r||`Authentication failed`}`)):(n(`error`),i(`Invalid OAuth callback - please try again`))}catch(e){n(`error`),i(e instanceof Error?e.message:`Authentication failed`)}})()},[e]),(0,V.jsx)(`div`,{className:`flex items-center justify-center min-h-screen bg-background`,children:(0,V.jsxs)(`div`,{className:`text-center space-y-4`,children:[t===`loading`&&(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),t===`success`&&(0,V.jsx)(`div`,{className:`text-green-500 text-4xl`,children:`✓`}),t===`error`&&(0,V.jsx)(`div`,{className:`text-red-500 text-4xl`,children:`✗`}),(0,V.jsx)(`h1`,{className:`text-xl font-semibold`,children:r}),t===`error`&&(0,V.jsx)(`button`,{onClick:()=>window.close(),className:`px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90`,children:`Close Window`})]})})}function TO(e){let t=()=>{throw Error(`Invalid url to pass to open(): ${e}`)},n;try{n=new URL(e)}catch{t()}return n.protocol!==`https:`&&n.protocol!==`http:`&&t(),n.hostname!==encodeURIComponent(n.hostname)&&t(),n.username&&(n.username=encodeURIComponent(n.username)),n.password&&(n.password=encodeURIComponent(n.password)),n.pathname=n.pathname.slice(0,1)+encodeURIComponent(n.pathname.slice(1)).replace(/%2f/gi,`/`),n.search=n.search.slice(0,1)+Array.from(n.searchParams.entries()).map(EO).join(`&`),n.hash=n.hash.slice(0,1)+encodeURIComponent(n.hash.slice(1)),n.href}function EO([e,t]){return`${encodeURIComponent(e)}${t.length>0?`=${encodeURIComponent(t)}`:``}`}var DO=class{serverUrl;storageKeyPrefix;serverUrlHash;clientName;clientUri;callbackUrl;preventAutoAuth;onPopupWindow;constructor(e,t={}){this.serverUrl=e,this.storageKeyPrefix=t.storageKeyPrefix||`mcp:auth`,this.serverUrlHash=this.hashString(e),this.clientName=t.clientName||`MCP Browser Client`,this.clientUri=t.clientUri||(typeof window<`u`?window.location.origin:``),this.callbackUrl=TO(t.callbackUrl||(typeof window<`u`?new URL(`/oauth/callback`,window.location.origin).toString():`/oauth/callback`)),this.preventAutoAuth=t.preventAutoAuth,this.onPopupWindow=t.onPopupWindow}get redirectUrl(){return TO(this.callbackUrl)}get clientMetadata(){return{redirect_uris:[this.redirectUrl],token_endpoint_auth_method:`none`,grant_types:[`authorization_code`,`refresh_token`],response_types:[`code`],client_name:this.clientName,client_uri:this.clientUri}}async clientInformation(){let e=this.getKey(`client_info`),t=localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.warn(`[${this.storageKeyPrefix}] Failed to parse client information:`,t),localStorage.removeItem(e);return}}async saveClientInformation(e){let t=this.getKey(`client_info`);localStorage.setItem(t,JSON.stringify(e))}async tokens(){let e=this.getKey(`tokens`),t=localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.warn(`[${this.storageKeyPrefix}] Failed to parse tokens:`,t),localStorage.removeItem(e);return}}async saveTokens(e){let t=this.getKey(`tokens`);localStorage.setItem(t,JSON.stringify(e)),localStorage.removeItem(this.getKey(`code_verifier`)),localStorage.removeItem(this.getKey(`last_auth_url`))}async saveCodeVerifier(e){let t=this.getKey(`code_verifier`);localStorage.setItem(t,e)}async codeVerifier(){let e=this.getKey(`code_verifier`),t=localStorage.getItem(e);if(!t)throw Error(`[${this.storageKeyPrefix}] Code verifier not found in storage for key ${e}. Auth flow likely corrupted or timed out.`);return t}async prepareAuthorizationUrl(e){let t=crypto.randomUUID(),n=`${this.storageKeyPrefix}:state_${t}`,r={serverUrlHash:this.serverUrlHash,expiry:Date.now()+6e5,providerOptions:{serverUrl:this.serverUrl,storageKeyPrefix:this.storageKeyPrefix,clientName:this.clientName,clientUri:this.clientUri,callbackUrl:this.callbackUrl}};localStorage.setItem(n,JSON.stringify(r)),e.searchParams.set(`state`,t);let i=TO(e.toString());return localStorage.setItem(this.getKey(`last_auth_url`),i),i}async redirectToAuthorization(e){if(this.preventAutoAuth)return;let t=await this.prepareAuthorizationUrl(e),n=`width=600,height=700,resizable=yes,scrollbars=yes,status=yes`;try{let e=window.open(t,`mcp_auth_${this.serverUrlHash}`,n);this.onPopupWindow&&this.onPopupWindow(t,n,e),!e||e.closed||e.closed===void 0?console.warn(`[${this.storageKeyPrefix}] Popup likely blocked by browser. Manual navigation might be required using the stored URL.`):(e.focus(),console.info(`[${this.storageKeyPrefix}] Redirecting to authorization URL in popup.`))}catch(e){console.error(`[${this.storageKeyPrefix}] Error opening popup window:`,e)}}getLastAttemptedAuthUrl(){let e=localStorage.getItem(this.getKey(`last_auth_url`));return e?TO(e):null}clearStorage(){let e=`${this.storageKeyPrefix}_${this.serverUrlHash}_`,t=`${this.storageKeyPrefix}:state_`,n=[],r=0;for(let r=0;r<localStorage.length;r++){let i=localStorage.key(r);if(i){if(i.startsWith(e))n.push(i);else if(i.startsWith(t))try{let e=localStorage.getItem(i);e&&JSON.parse(e).serverUrlHash===this.serverUrlHash&&n.push(i)}catch(e){console.warn(`[${this.storageKeyPrefix}] Error parsing state key ${i} during clearStorage:`,e)}}}return[...new Set(n)].forEach(e=>{localStorage.removeItem(e),r++}),r}hashString(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(16)}getKey(e){return`${this.storageKeyPrefix}_${this.serverUrlHash}_${e}`}},OO=Object.freeze({status:`aborted`});function J(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(let e in o.prototype)e in n||Object.defineProperty(n,e,{value:o.prototype[e].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var kO=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},AO={};function jO(e){return e&&Object.assign(AO,e),AO}function MO(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function NO(e,t){return typeof t==`bigint`?t.toString():t}function PO(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function FO(e){return e==null}function IO(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function LO(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r;return Number.parseInt(e.toFixed(i).replace(`.`,``))%Number.parseInt(t.toFixed(i).replace(`.`,``))/10**i}function RO(e,t,n){Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function zO(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function BO(e){return JSON.stringify(e)}var VO=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function HO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var UO=PO(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function WO(e){if(HO(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return HO(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}var GO=new Set([`string`,`number`,`symbol`]);function KO(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function qO(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function Y(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function JO(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var YO={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function XO(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&(n[e]=r.shape[e])}return qO(e,{...e._zod.def,shape:n,checks:[]})}function ZO(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete n[e]}return qO(e,{...e._zod.def,shape:n,checks:[]})}function QO(e,t){if(!WO(t))throw Error(`Invalid input to extend: expected a plain object`);return qO(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return zO(this,`shape`,n),n},checks:[]})}function $O(e,t){return qO(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return zO(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function ek(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return qO(t,{...t._zod.def,shape:i,checks:[]})}function tk(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return qO(t,{...t._zod.def,shape:i,checks:[]})}function nk(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function rk(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function ik(e){return typeof e==`string`?e:e?.message}function ak(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=ik(e.inst?._zod.def?.error?.(e))??ik(t?.error?.(e))??ik(n.customError?.(e))??ik(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function ok(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function sk(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ck=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get(){return JSON.stringify(t,NO,2)},enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},lk=J(`$ZodError`,ck),uk=J(`$ZodError`,ck,{Parent:Error});function dk(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function fk(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}var pk=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new kO;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>ak(e,a,jO())));throw VO(t,i?.callee),t}return o.value},mk=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>ak(e,a,jO())));throw VO(t,i?.callee),t}return o.value},hk=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new kO;return a.issues.length?{success:!1,error:new(e??lk)(a.issues.map(e=>ak(e,i,jO())))}:{success:!0,data:a.value}},gk=hk(uk),_k=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>ak(e,i,jO())))}:{success:!0,data:a.value}},vk=_k(uk),yk=/^[cC][^\s-]{8,}$/,bk=/^[0-9a-z]+$/,xk=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sk=/^[0-9a-vA-V]{20}$/,Ck=/^[A-Za-z0-9]{27}$/,wk=/^[a-zA-Z0-9_-]{21}$/,Tk=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ek=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Dk=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,Ok=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,kk=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Ak(){return new RegExp(kk,`u`)}var jk=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Mk=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,Nk=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Pk=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Fk=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Ik=/^[A-Za-z0-9_-]*$/,Lk=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,Rk=/^\+(?:[0-9]){6,14}[0-9]$/,zk=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Bk=RegExp(`^${zk}$`);function Vk(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Hk(e){return RegExp(`^${Vk(e)}$`)}function Uk(e){let t=Vk({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${zk}T(?:${r})$`)}var Wk=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Gk=/^\d+$/,Kk=/^-?\d+(?:\.\d+)?/i,qk=/true|false/i,Jk=/null/i,Yk=/^[^A-Z]*$/,Xk=/^[^a-z]*$/,Zk=J(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qk={number:`number`,bigint:`bigint`,object:`date`},$k=J(`$ZodCheckLessThan`,(e,t)=>{Zk.init(e,t);let n=Qk[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),eA=J(`$ZodCheckGreaterThan`,(e,t)=>{Zk.init(e,t);let n=Qk[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tA=J(`$ZodCheckMultipleOf`,(e,t)=>{Zk.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):LO(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nA=J(`$ZodCheckNumberFormat`,(e,t)=>{Zk.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=YO[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Gk)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),rA=J(`$ZodCheckMaxLength`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=ok(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),iA=J(`$ZodCheckMinLength`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=ok(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),aA=J(`$ZodCheckLengthEquals`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=ok(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),oA=J(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Zk.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),sA=J(`$ZodCheckRegex`,(e,t)=>{oA.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),cA=J(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Yk,oA.init(e,t)}),lA=J(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Xk,oA.init(e,t)}),uA=J(`$ZodCheckIncludes`,(e,t)=>{Zk.init(e,t);let n=KO(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),dA=J(`$ZodCheckStartsWith`,(e,t)=>{Zk.init(e,t);let n=RegExp(`^${KO(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),fA=J(`$ZodCheckEndsWith`,(e,t)=>{Zk.init(e,t);let n=RegExp(`.*${KO(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),pA=J(`$ZodCheckOverwrite`,(e,t)=>{Zk.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),mA=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
189
|
+
${F.data.oauth.issuer?`Issuer: ${F.data.oauth.issuer}`:``}`;A({title:`OAuth Setup Instructions`,description:e,duration:1e4})},children:`📋 Setup Instructions`})]})]}),(0,V.jsxs)(`div`,{className:`mt-2 text-xs`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`💡 Next Steps:`})}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside ml-2 space-y-1`,children:[(0,V.jsx)(`li`,{children:`For OAuth servers: Provide OAuth credentials in service settings`}),(0,V.jsx)(`li`,{children:`For SSE servers: We'll automatically use the correct protocol`}),(0,V.jsx)(`li`,{children:`For connection issues: Verify the server URL and status`})]})]})]}),L&&(0,V.jsxs)(`div`,{className:`mt-3 p-3 bg-red-500/20 rounded`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`❌ Discovery Failed`})}),(0,V.jsx)(`p`,{children:`Could not analyze MCP server configuration`}),(0,V.jsx)(`pre`,{className:`text-xs overflow-x-auto`,children:L instanceof Error?L.message:String(L)})]})]})]}),!de&&!ie&&!ce&&e.type===`a2a`&&!ue&&(0,V.jsxs)(`div`,{className:`bg-yellow-500/20 border border-yellow-500/30 rounded-lg p-4`,children:[(0,V.jsx)(`h3`,{className:`text-yellow-300 font-semibold mb-2`,children:`Agent Details Not Available`}),(0,V.jsxs)(`p`,{className:`text-yellow-200 text-sm`,children:[`Successfully connected to A2A agent at `,M?.url,`, but no manifest was found.`]}),(0,V.jsxs)(`div`,{className:`text-yellow-200 text-xs mt-2`,children:[(0,V.jsx)(`p`,{children:(0,V.jsx)(`strong`,{children:`This could mean:`})}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside ml-2 space-y-1`,children:[(0,V.jsx)(`li`,{children:`The agent doesn't provide a manifest`}),(0,V.jsx)(`li`,{children:`Manifest endpoint is not implemented`}),(0,V.jsx)(`li`,{children:`Agent requires specific authentication`})]})]})]})]})]})})}function TE({open:e,onOpenChange:t}){let[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),[o,s]=(0,b.useState)(null),[c,l]=(0,b.useState)(!1),u=Et(),{toast:d}=on(),f=()=>{r(null),a(null),s(null),l(!1)},p=Ht({mutationFn:async()=>{if(!n)throw Error(`Choose a bundle file first`);let e=await n.text(),t;try{t=JSON.parse(e)}catch{throw Error(`File is not valid JSON`)}return Vm(t)},onSuccess:e=>{s(e),u.invalidateQueries({queryKey:[`/api/decks`]}),u.invalidateQueries({queryKey:[`/api/services`]}),u.invalidateQueries({queryKey:[`/api/playbooks`]}),u.invalidateQueries({queryKey:[`/api/playbooks/collection`]}),u.invalidateQueries({queryKey:[`/api/credentials/collection`]}),u.invalidateQueries({queryKey:[`/api/collection/warnings`]}),d({title:`Import complete`,description:Wm(e)})},onError:e=>{d({title:`Import failed`,description:e.message,variant:`destructive`})}}),m=async e=>{if(r(e),s(null),!e){a(null);return}try{let t=await e.text(),n=JSON.parse(t);a(`${n.services?.length??0} services · ${n.playbooks?.length??0} playbooks · ${n.decks?.length??0} decks`)}catch{a(`Invalid JSON`)}};return(0,V.jsx)(Dp,{open:e,onOpenChange:e=>{e||f(),t(e)},children:(0,V.jsxs)(Ap,{className:`sm:max-w-lg border-border bg-[#161612] text-[#E8F6F4]`,children:[(0,V.jsxs)(jp,{children:[(0,V.jsx)(Mp,{children:`Import bundle`}),(0,V.jsx)(Np,{asChild:!0,children:(0,V.jsxs)(`div`,{className:`space-y-2 text-left text-sm text-[#A8C4C0]`,children:[(0,V.jsx)(`p`,{children:`Adds MCP, playbooks, and decks from a JSON file.`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`font-medium text-amber-200/90`,children:`Notes`}),(0,V.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4`,children:[(0,V.jsx)(`li`,{children:`Same name as an existing card or deck is skipped (linked only).`}),(0,V.jsx)(`li`,{children:`No credentials or secrets — re-enter keys and reconnect OAuth.`})]})]})]})})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(zp,{htmlFor:`bundle-file`,children:`Bundle file`}),(0,V.jsx)(uu,{id:`bundle-file`,type:`file`,accept:`.json,.agent-deck.json,application/json`,className:`cursor-pointer bg-white/5 border-white/20`,onChange:e=>m(e.target.files?.[0]??null),"data-testid":`input-import-bundle`}),i&&(0,V.jsx)(`p`,{className:`text-xs text-[#A8C4C0]`,"data-testid":`import-preview`,children:i})]}),!o&&(0,V.jsx)(G,{onClick:()=>p.mutate(),disabled:!n||p.isPending||i===`Invalid JSON`,className:`rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},"data-testid":`button-import-apply`,children:p.isPending?`Importing…`:`Import`}),o&&(0,V.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-white/10 bg-white/5 p-3 text-sm`,"data-testid":`import-report`,children:[(0,V.jsx)(`p`,{className:`font-medium`,children:Wm(o)}),o.servicesNeedingOauth.length>0&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-amber-200`,children:`Needs OAuth reconnect:`}),(0,V.jsx)(`ul`,{className:`list-disc pl-5 text-[#A8C4C0]`,children:o.servicesNeedingOauth.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}),o.warnings.length>0&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-amber-200`,children:`Warnings:`}),(0,V.jsx)(`ul`,{className:`list-disc pl-5 text-[#A8C4C0]`,children:o.warnings.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}),(0,V.jsx)(G,{variant:`outline`,size:`sm`,className:`rounded-full border border-white/20 text-white hover:bg-white/10`,onClick:()=>l(e=>!e),children:c?`Hide id map`:`Show id map`}),c&&(0,V.jsx)(`pre`,{className:`max-h-40 overflow-auto rounded bg-black/40 p-2 text-xs`,children:JSON.stringify(o.idMap,null,2)}),(0,V.jsx)(G,{className:`rounded-full border px-6 text-sm font-semibold hover:opacity-90`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},onClick:()=>{f(),t(!1)},children:`Done`})]})]})]})})}function EE(){let[e,t]=(0,b.useState)(`connecting`),[n,r]=(0,b.useState)(null),i=(0,b.useRef)(null),a=(0,b.useRef)(null),o=Et();return(0,b.useEffect)(()=>{let e=`${window.location.protocol===`https:`?`wss:`:`ws:`}//${window.location.host}/api/ws/events`,n=()=>{try{let s=new WebSocket(e);i.current=s,s.onopen=()=>{console.log(`WebSocket connected`),t(`connected`)},s.onmessage=e=>{try{let n=JSON.parse(e.data);r(n),n.type===`deck_update`?(console.log(`Received deck update:`,n),o.invalidateQueries({queryKey:[`/api/decks`]})):n.type===`service_update`?(console.log(`Received service update:`,n),pE(o,typeof n.data?.serviceId==`string`?n.data.serviceId:void 0)):n.type===`connection_status`&&t(n.status===`connected`?`connected`:`disconnected`)}catch(e){console.error(`Failed to parse WebSocket message:`,e)}},s.onclose=()=>{console.log(`WebSocket disconnected`),t(`disconnected`),a.current=setTimeout(()=>{console.log(`Attempting to reconnect WebSocket...`),t(`connecting`),n()},3e3)},s.onerror=e=>{console.error(`WebSocket error:`,e),t(`disconnected`)}}catch(e){console.error(`Failed to connect WebSocket:`,e),t(`disconnected`)}};n();let s=e=>{e.origin===window.location.origin&&hE(e.data)&&pE(o,e.data.serviceId)};return window.addEventListener(`message`,s),()=>{window.removeEventListener(`message`,s),a.current&&clearTimeout(a.current),i.current&&i.current.readyState===WebSocket.OPEN&&i.current.close()}},[o]),{connectionStatus:e,lastMessage:n}}async function DE(e,t){return(await(await H(`GET`,`/api/playbooks/dependents/check?${e===`credential`?`credentialId=${encodeURIComponent(t)}`:`serviceId=${encodeURIComponent(t)}`}`)).json()).data??[]}function OE(e){let[t,n]=(0,b.useState)(null),[r,i]=(0,b.useState)(null),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(!1),l=Et(),{toast:u}=on(),d=()=>{if(!e)throw Error(`Select a deck to edit first`);return e},f=Ht({mutationFn:async e=>{let t=d(),n=(await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t);if(!n)throw Error(`Selected deck not found`);if(n.services?.some(t=>t.id===e))throw Error(`Service is already in the deck`);let r=n.services?.length??0;return H(`POST`,`/api/decks/${t}/services`,{serviceId:e,position:r})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Service added to deck`,description:`${t?.name||`Service`} has been added to the deck.`})},onError:e=>{u({title:`Failed to add service`,description:e.message,variant:`destructive`})}}),p=Ht({mutationFn:async e=>{let t=d();if(((await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t))?.credentials?.some(t=>t.id===e))throw Error(`API key is already in the deck`);return H(`POST`,`/api/decks/${t}/credentials`,{credentialId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`API key added to deck`,description:`${r?.label||`API key`} is scoped to this deck.`})},onError:e=>{u({title:`Failed to add API key`,description:e.message,variant:`destructive`})}}),m=Ht({mutationFn:async e=>{let t=d();if(((await(await H(`GET`,`/api/decks`)).json()).data?.find(e=>e.id===t))?.playbooks?.some(t=>t.id===e))throw Error(`Playbook is already in the deck`);return H(`POST`,`/api/decks/${t}/playbooks`,{playbookId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Playbook added to deck`,description:`${a?.title||`Playbook`} is on this deck.`})},onError:e=>{u({title:`Failed to add playbook`,description:e.message,variant:`destructive`})}}),h=Ht({mutationFn:async e=>{let t=await DE(`service`,e);if(t.length>0){let e=t.map(e=>e.title).join(`, `);if(!window.confirm(`Warning: ${t.length} playbook(s) depend on this MCP (${e}). Remove from deck anyway?`))throw Error(`Cancelled`)}return H(`DELETE`,`/api/decks/${d()}/services`,{serviceId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Service removed from deck`,description:`${t?.name||`Service`} has been removed from the deck.`})},onError:e=>{e.message!==`Cancelled`&&u({title:`Failed to remove service`,description:e.message,variant:`destructive`})}}),g=Ht({mutationFn:async e=>{let t=await DE(`credential`,e);if(t.length>0){let e=t.map(e=>e.title).join(`, `);if(!window.confirm(`Warning: ${t.length} playbook(s) depend on this API key (${e}). Remove from deck anyway?`))throw Error(`Cancelled`)}return H(`DELETE`,`/api/decks/${d()}/credentials`,{credentialId:e})},onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`API key removed from deck`,description:`${r?.label||`API key`} is no longer on this deck.`})},onError:e=>{e.message!==`Cancelled`&&u({title:`Failed to remove API key`,description:e.message,variant:`destructive`})}}),_=Ht({mutationFn:async e=>H(`DELETE`,`/api/decks/${d()}/playbooks`,{playbookId:e}),onSuccess:()=>{l.invalidateQueries({queryKey:[`/api/decks`]}),u({title:`Playbook removed from deck`,description:`${a?.title||`Playbook`} is no longer on this deck.`})},onError:e=>{u({title:`Failed to remove playbook`,description:e.message,variant:`destructive`})}}),v=(e,t)=>{e.currentTarget instanceof HTMLElement&&(e.currentTarget.style.opacity=t)},y=(e,t)=>{e.dataTransfer.setData(`text/plain`,t.id),e.dataTransfer.setData(`application/json`,JSON.stringify(t)),e.dataTransfer.effectAllowed=t.fromDeck?`move`:`copy`},x=(e,t,r=!1)=>{n(t),i(null),o(null),c(r),y(e,{kind:`service`,id:t.id,fromDeck:r}),v(e,`0.5`)},S=(e,t,r=!1)=>{i(t),n(null),o(null),c(r),y(e,{kind:`credential`,id:t.id,fromDeck:r}),v(e,`0.5`)},C=(e,t,r=!1)=>{o(t),n(null),i(null),c(r),y(e,{kind:`playbook`,id:t.id,fromDeck:r}),v(e,`0.5`)},w=e=>{n(null),i(null),o(null),v(e,`1`)},T=e=>{if(e.kind===`service`){e.fromDeck?h.mutate(e.id):f.mutate(e.id);return}if(e.kind===`credential`){e.fromDeck?g.mutate(e.id):p.mutate(e.id);return}e.fromDeck?_.mutate(e.id):m.mutate(e.id)};return{draggedService:t,draggedCredential:r,draggedPlaybook:a,isDraggingFromDeck:s,handleDragStart:x,handleCredentialDragStart:S,handlePlaybookDragStart:C,handleDragEnd:w,handleDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData(`application/json`);if(r){try{T(JSON.parse(r))}catch{let n=e.dataTransfer.getData(`text/plain`);n&&t&&f.mutate(n)}n(null),i(null),o(null),c(!1)}},handleGlobalDrop:e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/json`);if(t){try{let e=JSON.parse(t);e.fromDeck&&T(e)}catch{}n(null),i(null),o(null),c(!1)}},isDropping:f.isPending||p.isPending||m.isPending||h.isPending||g.isPending||_.isPending}}var kE=`agent-deck-editing-deck-id`;function AE(e){let[t,n]=(0,b.useState)(()=>typeof window>`u`?null:localStorage.getItem(kE));return(0,b.useEffect)(()=>{if(e.length!==0&&!(t&&e.some(e=>e.id===t))){let t=e[0].id;n(t),localStorage.setItem(kE,t)}},[e,t]),{editingDeck:e.find(e=>e.id===t)??null,editingDeckId:t,setEditingDeckId:e=>{n(e),localStorage.setItem(kE,e)}}}function jE(e,[t,n]){return Math.min(n,Math.max(t,e))}function ME(e){let t=b.useRef({value:e,previous:e});return b.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var NE=[` `,`Enter`,`ArrowUp`,`ArrowDown`],PE=[` `,`Enter`],FE=`Select`,[IE,LE,RE]=Sn(FE),[zE,BE]=fn(FE,[RE,Ec]),VE=Ec(),[HE,UE]=zE(FE),[WE,GE]=zE(FE),KE=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=VE(t),[g,_]=b.useState(null),[v,y]=b.useState(null),[x,S]=b.useState(!1),C=Vp(l),[w,T]=Zn({prop:r,defaultProp:i??!1,onChange:a,caller:FE}),[E,D]=Zn({prop:o,defaultProp:s,onChange:c,caller:FE}),O=b.useRef(null),k=!g||m||!!g.closest(`form`),[A,j]=b.useState(new Set),M=Array.from(A).map(e=>e.props.value).join(`;`);return(0,V.jsx)(Hc,{...h,children:(0,V.jsxs)(HE,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:x,onValueNodeHasChildrenChange:S,contentId:to(),value:E,onValueChange:D,open:w,onOpenChange:T,dir:C,triggerPointerDownPosRef:O,disabled:f,children:[(0,V.jsx)(IE.Provider,{scope:t,children:(0,V.jsx)(WE,{scope:e.__scopeSelect,onNativeOptionAdd:b.useCallback(e=>{j(t=>new Set(t).add(e))},[]),onNativeOptionRemove:b.useCallback(e=>{j(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),k?(0,V.jsxs)(VD,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:E,onChange:e=>D(e.target.value),disabled:f,form:m,children:[E===void 0?(0,V.jsx)(`option`,{value:``}):null,Array.from(A)]},M):null]})})};KE.displayName=FE;var qE=`SelectTrigger`,JE=b.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=VE(n),o=UE(qE,n),s=o.disabled||r,c=un(t,o.onTriggerChange),l=LE(n),u=b.useRef(`touch`),[d,f,p]=UD(e=>{let t=l().filter(e=>!e.disabled),n=WD(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,V.jsx)(Uc,{asChild:!0,...a,children:(0,V.jsx)(Cn.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":HD(o.value)?``:void 0,...i,ref:c,onClick:U(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:U(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:U(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&NE.includes(e.key)&&(m(),e.preventDefault())})})})});JE.displayName=qE;var YE=`SelectValue`,XE=b.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=UE(YE,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=un(t,c.onValueNodeChange);return Hn(()=>{l(u)},[l,u]),(0,V.jsx)(Cn.span,{...s,ref:d,style:{pointerEvents:`none`},children:HD(c.value)?(0,V.jsx)(V.Fragment,{children:o}):a})});XE.displayName=YE;var ZE=`SelectIcon`,QE=b.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,V.jsx)(Cn.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});QE.displayName=ZE;var $E=`SelectPortal`,eD=e=>(0,V.jsx)(Wn,{asChild:!0,...e});eD.displayName=$E;var tD=`SelectContent`,nD=b.forwardRef((e,t)=>{let n=UE(tD,e.__scopeSelect),[r,i]=b.useState();if(Hn(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?sn.createPortal((0,V.jsx)(iD,{scope:e.__scopeSelect,children:(0,V.jsx)(IE.Slot,{scope:e.__scopeSelect,children:(0,V.jsx)(`div`,{children:e.children})})}),t):null}return(0,V.jsx)(cD,{...e,ref:t})});nD.displayName=tD;var rD=10,[iD,aD]=zE(tD),oD=`SelectContentImpl`,sD=mn(`SelectContent.RemoveScroll`),cD=b.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=UE(tD,n),[y,x]=b.useState(null),[S,C]=b.useState(null),w=un(t,e=>x(e)),[T,E]=b.useState(null),[D,O]=b.useState(null),k=LE(n),[A,j]=b.useState(!1),M=b.useRef(!1);b.useEffect(()=>{if(y)return zu(y)},[y]),pu();let N=b.useCallback(e=>{let[t,...n]=k().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&S&&(S.scrollTop=0),n===r&&S&&(S.scrollTop=S.scrollHeight),n?.focus(),document.activeElement!==i))return},[k,S]),P=b.useCallback(()=>N([T,y]),[N,T,y]);b.useEffect(()=>{A&&P()},[A,P]);let{onOpenChange:F,triggerPointerDownPosRef:I}=v;b.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(I.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(I.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||F(!1),document.removeEventListener(`pointermove`,t),I.current=null};return I.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,F,I]),b.useEffect(()=>{let e=()=>F(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[F]);let[L,ee]=UD(e=>{let t=k().filter(e=>!e.disabled),n=WD(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),te=b.useCallback((e,t,n)=>{let r=!M.current&&!n;(v.value!==void 0&&v.value===t||r)&&(E(e),r&&(M.current=!0))},[v.value]),ne=b.useCallback(()=>y?.focus(),[y]),R=b.useCallback((e,t,n)=>{let r=!M.current&&!n;(v.value!==void 0&&v.value===t||r)&&O(e)},[v.value]),z=r===`popper`?fD:uD,B=z===fD?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,V.jsx)(iD,{scope:n,content:y,viewport:S,onViewportChange:C,itemRefCallback:te,selectedItem:T,onItemLeave:ne,itemTextRefCallback:R,focusSelectedItem:P,selectedItemText:D,position:r,isPositioned:A,searchRef:L,children:(0,V.jsx)(qd,{as:sD,allowPinchZoom:!0,children:(0,V.jsx)(yu,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:U(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,V.jsx)(Nn,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,V.jsx)(z,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...B,onPlaced:()=>j(!0),ref:w,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:U(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&ee(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=k().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>N(t)),e.preventDefault()}})})})})})})});cD.displayName=oD;var lD=`SelectItemAlignedPosition`,uD=b.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=UE(tD,n),o=aD(tD,n),[s,c]=b.useState(null),[l,u]=b.useState(null),d=un(t,e=>u(e)),f=LE(n),p=b.useRef(!1),m=b.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=b.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-rD,d=jE(a,[rD,Math.max(rD,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-rD,d=jE(a,[rD,Math.max(rD,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-rD*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-rD,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,j=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+j;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${rD}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);Hn(()=>y(),[y]);let[x,S]=b.useState();Hn(()=>{l&&S(window.getComputedStyle(l).zIndex)},[l]);let C=b.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]);return(0,V.jsx)(pD,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:(0,V.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:x},children:(0,V.jsx)(Cn.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});uD.displayName=lD;var dD=`SelectPopperPosition`,fD=b.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=rD,...a}=e,o=VE(n);return(0,V.jsx)(Wc,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});fD.displayName=dD;var[pD,mD]=zE(tD,{}),hD=`SelectViewport`,gD=b.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=aD(hD,n),o=mD(hD,n),s=un(t,a.onViewportChange),c=b.useRef(0);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,V.jsx)(IE.Slot,{scope:n,children:(0,V.jsx)(Cn.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:U(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-rD*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});gD.displayName=hD;var _D=`SelectGroup`,[vD,yD]=zE(_D),bD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=to();return(0,V.jsx)(vD,{scope:n,id:i,children:(0,V.jsx)(Cn.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});bD.displayName=_D;var xD=`SelectLabel`,SD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=yD(xD,n);return(0,V.jsx)(Cn.div,{id:i.id,...r,ref:t})});SD.displayName=xD;var CD=`SelectItem`,[wD,TD]=zE(CD),ED=b.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=UE(CD,n),c=aD(CD,n),l=s.value===r,[u,d]=b.useState(a??``),[f,p]=b.useState(!1),m=un(t,e=>c.itemRefCallback?.(e,r,i)),h=to(),g=b.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,V.jsx)(wD,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:b.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,V.jsx)(IE.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,V.jsx)(Cn.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:U(o.onFocus,()=>p(!0)),onBlur:U(o.onBlur,()=>p(!1)),onClick:U(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:U(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:U(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:U(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:U(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:U(o.onKeyDown,e=>{(c.searchRef?.current===``||e.key!==` `)&&(PE.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});ED.displayName=CD;var DD=`SelectItemText`,OD=b.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=UE(DD,n),s=aD(DD,n),c=TD(DD,n),l=GE(DD,n),[u,d]=b.useState(null),f=un(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=b.useMemo(()=>(0,V.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return Hn(()=>(h(m),()=>g(m)),[h,g,m]),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Cn.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?sn.createPortal(a.children,o.valueNode):null]})});OD.displayName=DD;var kD=`SelectItemIndicator`,AD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return TD(kD,n).isSelected?(0,V.jsx)(Cn.span,{"aria-hidden":!0,...r,ref:t}):null});AD.displayName=kD;var jD=`SelectScrollUpButton`,MD=b.forwardRef((e,t)=>{let n=aD(jD,e.__scopeSelect),r=mD(jD,e.__scopeSelect),[i,a]=b.useState(!1),o=un(t,r.onScrollButtonChange);return Hn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollTop>0;a(e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,V.jsx)(FD,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});MD.displayName=jD;var ND=`SelectScrollDownButton`,PD=b.forwardRef((e,t)=>{let n=aD(ND,e.__scopeSelect),r=mD(ND,e.__scopeSelect),[i,a]=b.useState(!1),o=un(t,r.onScrollButtonChange);return Hn(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight,n=Math.ceil(t.scrollTop)<e;a(n)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,V.jsx)(FD,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});PD.displayName=ND;var FD=b.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=aD(`SelectScrollButton`,n),o=b.useRef(null),s=LE(n),c=b.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return b.useEffect(()=>()=>c(),[c]),Hn(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,V.jsx)(Cn.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:U(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:U(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:U(i.onPointerLeave,()=>{c()})})}),ID=`SelectSeparator`,LD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,V.jsx)(Cn.div,{"aria-hidden":!0,...r,ref:t})});LD.displayName=ID;var RD=`SelectArrow`,zD=b.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=VE(n),a=UE(RD,n),o=aD(RD,n);return a.open&&o.position===`popper`?(0,V.jsx)(Gc,{...i,...r,ref:t}):null});zD.displayName=RD;var BD=`SelectBubbleInput`,VD=b.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=b.useRef(null),a=un(r,i),o=ME(t);return b.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,V.jsx)(Cn.select,{...n,style:{...er,...n.style},ref:a,defaultValue:t})});VD.displayName=BD;function HD(e){return e===``||e===void 0}function UD(e){let t=Tn(e),n=b.useRef(``),r=b.useRef(0),i=b.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=b.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function WD(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=GD(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function GD(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var KD=KE,qD=JE,JD=XE,YD=QE,XD=eD,ZD=nD,QD=gD,$D=SD,eO=ED,tO=OD,nO=AD,rO=MD,iO=PD,aO=LD,oO=KD,sO=JD,cO=b.forwardRef(({className:e,children:t,...n},r)=>(0,V.jsxs)(qD,{ref:r,className:W(`flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,V.jsx)(YD,{asChild:!0,children:(0,V.jsx)(gi,{className:`h-4 w-4 opacity-50`})})]}));cO.displayName=qD.displayName;var lO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(rO,{ref:n,className:W(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,V.jsx)(yi,{className:`h-4 w-4`})}));lO.displayName=rO.displayName;var uO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(iO,{ref:n,className:W(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,V.jsx)(gi,{className:`h-4 w-4`})}));uO.displayName=iO.displayName;var dO=b.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,V.jsx)(XD,{children:(0,V.jsxs)(ZD,{ref:i,className:W(`relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,V.jsx)(lO,{}),(0,V.jsx)(QD,{className:W(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,V.jsx)(uO,{})]})}));dO.displayName=ZD.displayName;var fO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)($D,{ref:n,className:W(`py-1.5 pl-8 pr-2 text-sm font-semibold`,e),...t}));fO.displayName=$D.displayName;var pO=b.forwardRef(({className:e,children:t,...n},r)=>(0,V.jsxs)(eO,{ref:r,className:W(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,V.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,V.jsx)(nO,{children:(0,V.jsx)(hi,{className:`h-4 w-4`})})}),(0,V.jsx)(tO,{children:t})]}));pO.displayName=eO.displayName;var mO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(aO,{ref:n,className:W(`-mx-1 my-1 h-px bg-muted`,e),...t}));mO.displayName=aO.displayName;var hO=`/assets/AgentDeckLogo3-X5qCXS2A.png`;function gO(){let[e,t]=(0,b.useState)(``),[n,r]=(0,b.useState)(``),[i,a]=(0,b.useState)(!1),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(null),[u,d]=(0,b.useState)(!1),[f,p]=(0,b.useState)(!1),[m,h]=(0,b.useState)(null),[g,_]=(0,b.useState)(!1),[v,y]=(0,b.useState)(!1),[x,S]=(0,b.useState)(null),[C,w]=(0,b.useState)(!1),[T,E]=(0,b.useState)(!1),[D,O]=(0,b.useState)(!1),[k,A]=(0,b.useState)(null),{toast:j}=on(),{data:M=[]}=Vt({queryKey:[`/api/playbook-patches`,`proposed`],queryFn:()=>Xm(`proposed`)}),{data:N=0}=Vt({queryKey:[`/api/feedback-signals/count`,`available`],queryFn:()=>nh()}),P=async()=>{O(!0);try{let e=await Bm({scope:`collection`});Hm(e,`backup.agent-deck.json`),j({title:`Exported collection`,description:`${e.services.length} services, ${e.playbooks.length} playbooks, ${e.decks.length} decks`})}catch(e){j({title:`Export failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{O(!1)}},{connectionStatus:F}=EE(),{data:I,isLoading:L,error:ee}=Vt({queryKey:[`/api/decks`]}),te=I?.data||[],{editingDeck:ne,editingDeckId:R,setEditingDeckId:z}=AE(te),{handleDragStart:B,handleCredentialDragStart:re,handlePlaybookDragStart:ie,handleDragEnd:ae,handleDrop:oe,handleGlobalDrop:se,isDraggingFromDeck:ce}=OE(R),{data:le,isLoading:ue,error:de}=Vt({queryKey:[`/api/services`]}),{data:fe,isLoading:pe}=Vt({queryKey:[`/api/credentials/vault`]}),{data:me,isLoading:he}=Vt({queryKey:[`/api/playbooks/vault`]}),{data:ge}=Vt({queryKey:[`/api/collection/warnings`],staleTime:6e4}),_e=le?.data||[],ve=fe?.data||[],be=me?.data||[],xe=(0,b.useMemo)(()=>Ol(ge?.data),[ge?.data]),Se=(e,t)=>i?e===`service`?xe.serviceWarnings.has(t):e===`credential`?xe.credentialWarnings.has(t):xe.playbookWarnings.has(t):!0,Ce=_e.filter(t=>{if(!Se(`service`,t.id)||n===`api-key`||n===`playbook`)return!1;let r=t.name.toLowerCase().includes(e.toLowerCase())||t.description?.toLowerCase().includes(e.toLowerCase()),i=!n||n===`all`||t.type===n;return r&&i}),we=ve.filter(t=>!Se(`credential`,t.id)||n&&n!==`all`&&n!==`api-key`?!1:t.label.toLowerCase().includes(e.toLowerCase())),Te=be.filter(t=>!Se(`playbook`,t.id)||n&&n!==`all`&&n!==`playbook`?!1:t.title.toLowerCase().includes(e.toLowerCase())||t.body.toLowerCase().includes(e.toLowerCase())),Ee=Ce.length+we.length+Te.length;de&&console.error(`Services error:`,de),ee&&console.error(`Decks error:`,ee);let De=()=>{t(``),r(``),a(!1)},Oe=!!(e||n||i),ke=new Set((ne?.credentials??[]).map(e=>e.id)),Ae=new Set((ne?.playbooks??[]).map(e=>e.id)),je=ne?.services||[],Me=ne?.playbooks||[],Ne=e=>{l(e),d(!0)},Pe=e=>{S(e.id),w(!0)},Fe=e=>{h(e.id),_(!0)},Ie=e=>{A(e)};if(de||ee){let e=Wt(ee)||Wt(de),t=(ee instanceof Error?ee.message:null)??(de instanceof Error?de.message:null)??`There was an error loading the application data.`;return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center max-w-lg px-4`,children:[(0,V.jsx)(`h2`,{className:`text-2xl font-bold text-red-400 mb-4`,children:e?`Dashboard Access Expired`:`Error Loading Data`}),e?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-gray-300 mb-2`,children:`Dashboard access has expired.`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:`Reopen it securely from your terminal or the Agent Deck menubar.`}),(0,V.jsx)(`code`,{className:`mb-6 block rounded bg-black/30 px-3 py-2 text-gray-200`,children:`agent-deck open`}),(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(`agent-deck open`).then(()=>{j({title:`Command copied`,description:`Run it in your terminal.`})})},className:`px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700`,children:`Copy Command`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-gray-300 mb-2`,children:`There was an error loading the application data.`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:t}),(0,V.jsxs)(`p`,{className:`text-gray-500 text-xs mb-6`,children:[`Is the API running? Try `,(0,V.jsx)(`code`,{className:`text-gray-300`,children:`agent-deck stop && agent-deck start`})]}),(0,V.jsx)(`button`,{onClick:()=>window.location.reload(),className:`px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700`,children:`Reload Page`})]})]})})}return ue||L||pe||he?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-12 w-12 border-b-2 border-yellow-400 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-300`,children:`Loading AgentDeck...`})]})}):(0,V.jsxs)(`div`,{className:`flex min-h-dvh flex-col overflow-x-hidden`,onDrop:se,onDragOver:e=>e.preventDefault(),style:{position:`relative`,...ce&&{background:`linear-gradient(to bottom right, #1a1a2e, #16213e, #0f3460)`}},children:[(0,V.jsx)(`header`,{className:`relative z-20 shrink-0 bg-black/30 backdrop-blur-md border-b border-white/10`,children:(0,V.jsx)(`div`,{className:`container mx-auto px-4 py-3 sm:py-4`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 sm:gap-4`,children:[(0,V.jsx)(`img`,{src:hO,alt:`Agent Deck Logo`,className:`h-12 w-12 shrink-0 object-contain sm:h-16 sm:w-16`}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`h1`,{className:`text-xl font-bold bg-gradient-to-r from-yellow-400 to-yellow-600 bg-clip-text text-transparent sm:text-2xl`,style:{background:`linear-gradient(to right, #C4B643, #D4C760)`,WebkitBackgroundClip:`text`,WebkitTextFillColor:`transparent`,backgroundClip:`text`},children:`AgentDeck`}),(0,V.jsx)(`p`,{className:`text-xs sm:text-sm`,style:{color:`#92E4DD`},children:`Build tool deck for your agent`})]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-2 px-3 py-1 rounded-full border ${F===`connected`?`bg-emerald-500/20 border-emerald-500/30`:`bg-red-500/20 border-red-500/30`}`,children:[(0,V.jsx)(`div`,{className:`w-2 h-2 rounded-full animate-pulse ${F===`connected`?`bg-emerald-400`:`bg-red-400`}`}),(0,V.jsx)(`button`,{className:`font-ui-display text-sm hover:underline cursor-pointer ${F===`connected`?`text-emerald-300`:`text-red-300`}`,"data-testid":`button-copy-mcp-url`,onClick:()=>{navigator.clipboard.writeText(`http://localhost:3001/mcp`).then(()=>{j({title:`MCP URL copied!`,description:`The MCP server URL has been copied to your clipboard.`})})},title:`Click to copy MCP URL`,children:`Get MCP URL`})]}),(0,V.jsx)(zf,{highlightDeckId:R??void 0}),(0,V.jsx)(ye,{href:`/feedback-signals`,children:(0,V.jsxs)(G,{variant:`outline`,size:`sm`,className:`relative border-white/20 bg-white/5 text-[#E8F6F4]`,children:[(0,V.jsx)(`span`,{className:`font-ui-display`,children:`Feedback`}),N>0&&(0,V.jsx)(`span`,{className:`ml-2 rounded-full px-2 py-0.5 text-xs font-semibold`,style:{background:`#C4B643`,color:`#0A0A07`},title:`Open feedback available for curation`,children:N})]})}),(0,V.jsx)(ye,{href:`/playbook-patches`,children:(0,V.jsxs)(G,{variant:`outline`,size:`sm`,className:`relative border-white/20 bg-white/5 text-[#E8F6F4]`,children:[(0,V.jsx)(ki,{className:`mr-2 h-4 w-4`}),(0,V.jsx)(`span`,{className:`font-ui-display`,children:`Review`}),M.length>0&&(0,V.jsx)(`span`,{className:`ml-2 rounded-full px-2 py-0.5 text-xs font-semibold`,style:{background:`#C4B643`,color:`#0A0A07`},title:`Proposed playbook patches`,children:M.length})]})})]})]})})}),ce&&(0,V.jsx)(`div`,{className:`fixed inset-0 pointer-events-none z-50 flex items-center justify-center`,children:(0,V.jsxs)(`div`,{className:`bg-red-500/20 border-2 border-dashed border-red-500/50 rounded-lg p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`text-red-400 text-lg font-bold mb-2`,children:`Drop to Remove`}),(0,V.jsx)(`div`,{className:`text-red-300 text-sm`,children:`Release to remove card from deck`})]})}),(0,V.jsx)(`main`,{className:`container mx-auto flex min-h-0 flex-1 flex-col px-4 py-4 sm:py-6`,children:(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 sm:gap-6 xl:min-h-0 xl:flex-1 xl:grid-cols-4 xl:overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4 sm:space-y-6 xl:col-span-1 xl:min-h-0 xl:overflow-y-auto`,children:[(0,V.jsx)(`div`,{className:`panel-surface h-64 overflow-hidden p-4 min-w-0 sm:h-72 xl:h-80`,children:(0,V.jsx)(Gm,{decks:te,editingDeckId:R,onSelectDeck:z,isLoading:L})}),(0,V.jsxs)(`div`,{className:`panel-surface p-4`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold mb-3 flex items-center`,children:[(0,V.jsx)(di,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{className:`font-ui-display`,style:{color:`#92E4DD`},children:`Add Cards`})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(kl),onClick:()=>s(!0),"data-testid":`button-register-mcp`,children:[(0,V.jsx)(zi,{className:`w-3 h-3 mr-2`}),`Register MCP`]}),(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(Al),onClick:()=>p(!0),"data-testid":`button-register-api-key`,children:[(0,V.jsx)(Ai,{className:`w-3 h-3 mr-2`}),`Register API key`]}),(0,V.jsxs)(G,{variant:`ghost`,className:`w-full border-2 text-sm py-2 hover:opacity-90 ${Ml}`,style:Pl(jl),onClick:()=>y(!0),"data-testid":`button-register-playbook`,children:[(0,V.jsx)(fi,{className:`w-3 h-3 mr-2`}),`Register Playbook`]})]})]})]}),(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 sm:gap-6 xl:col-span-3 xl:h-full xl:min-h-0`,children:[(0,V.jsx)(`div`,{className:`panel-surface h-64 shrink-0 overflow-hidden p-4 min-w-0 sm:h-72 xl:h-80`,children:ne?(0,V.jsx)(`div`,{className:`h-full`,children:(0,V.jsx)(du,{deck:ne,services:je,credentials:ne.credentials??[],playbooks:Me,allServices:_e,collectionWarnings:xe,onDrop:oe,onDragStart:B,onCredentialDragStart:re,onPlaybookDragStart:ie,onDragEnd:ae,onCardClick:Ne,onPlaybookClick:Pe,onCredentialClick:Fe})}):(0,V.jsxs)(`div`,{className:`text-center h-full flex flex-col justify-center`,children:[(0,V.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-yellow-500/20 border border-yellow-500/30 flex items-center justify-center mx-auto mb-3`,children:(0,V.jsx)(Mi,{className:`w-6 h-6 text-yellow-400`})}),(0,V.jsx)(`h3`,{className:`text-lg font-bold mb-2`,style:{color:`#92E4DD`},children:`No deck selected`}),(0,V.jsx)(`p`,{className:`text-gray-300 mb-4 text-sm`,children:`Create a deck or select one from the sidebar to edit its cards.`}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsxs)(G,{onClick:()=>{let e=document.querySelector(`[data-testid="create-deck-button"]`);e&&e.click()},className:`border text-sm py-2`,style:{background:`#C4B643`,borderColor:`#C4B643`,color:`black`},children:[(0,V.jsx)(Ii,{className:`w-4 h-4 mr-2`}),`Create New Deck`]}),(0,V.jsxs)(G,{variant:`outline`,className:`border-white/20 text-white hover:bg-white/10 text-sm py-2`,onClick:()=>{let e=document.querySelector(`[data-testid="deck-management-panel"]`);e&&e.scrollIntoView({behavior:`smooth`})},children:[(0,V.jsx)(Mi,{className:`w-4 h-4 mr-2`}),`Manage Decks`]})]})]})}),(0,V.jsxs)(`div`,{className:`panel-surface flex min-h-[20rem] flex-col overflow-hidden p-4 min-w-0 sm:min-h-[24rem] xl:min-h-0 xl:flex-1`,"data-testid":`collection-panel`,children:[(0,V.jsxs)(`div`,{className:`mb-3 flex shrink-0 flex-wrap items-center justify-between gap-2`,children:[(0,V.jsxs)(`h2`,{className:`text-lg font-bold flex items-center`,children:[(0,V.jsx)(Ni,{className:`w-4 h-4 mr-2`,style:{color:`#92E4DD`}}),(0,V.jsx)(`span`,{className:`font-ui-display`,style:{color:`#92E4DD`},children:`My Collection`}),(0,V.jsxs)(`span`,{className:`ml-3 text-sm font-normal text-gray-400`,children:[`(`,Ee,` cards)`]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:P,disabled:D,title:`Export all MCP, playbooks, and decks`,"data-testid":`button-export-all`,children:[(0,V.jsx)(Ei,{className:`w-3 h-3 mr-1`}),D?`Exporting…`:`Export all`]}),(0,V.jsxs)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:()=>E(!0),title:`Import a bundle file`,"data-testid":`button-import-bundle`,children:[(0,V.jsx)(Wi,{className:`w-3 h-3 mr-1`}),`Import`]}),(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(Ri,{className:`absolute left-2 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4`}),(0,V.jsx)(uu,{placeholder:`Search...`,value:e,onChange:e=>t(e.target.value),className:`h-8 w-36 pl-8 text-sm bg-white/10 border-white/20 text-white placeholder-gray-400 sm:w-48`,"data-testid":`input-search`})]}),(0,V.jsxs)(oO,{value:n||`all`,onValueChange:e=>r(e===`all`?``:e),children:[(0,V.jsxs)(cO,{className:`w-[7.5rem] h-8 bg-white/10 border-white/20 text-white text-xs shrink-0`,"data-testid":`select-type`,children:[(0,V.jsx)(Oi,{className:`w-3 h-3 mr-1 shrink-0`}),(0,V.jsx)(sO,{placeholder:`Type`})]}),(0,V.jsxs)(dO,{children:[(0,V.jsx)(pO,{value:`all`,children:`All`}),(0,V.jsx)(pO,{value:`mcp`,children:`MCP`}),(0,V.jsx)(pO,{value:`local-mcp`,children:`Local MCP`}),(0,V.jsx)(pO,{value:`api-key`,children:`API Key`}),(0,V.jsx)(pO,{value:`playbook`,children:`Playbook`})]})]}),(e||n||i)&&(0,V.jsx)(G,{size:`sm`,variant:`outline`,className:`h-8 px-2 text-xs border-white/20 text-white hover:bg-white/10`,onClick:De,title:`Clear all filters`,children:`Clear`})]})]}),xe.total>0&&(0,V.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`mb-3 w-full shrink-0 rounded-lg border px-3 py-2 text-left text-sm transition-colors ${i?`border-amber-300/60 bg-amber-500/15 text-amber-100`:`border-amber-400/30 bg-amber-500/10 text-amber-100 hover:bg-amber-500/15`}`,"data-testid":`button-collection-warnings`,children:(0,V.jsxs)(`span`,{className:`flex items-start gap-2`,children:[(0,V.jsx)(Ui,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-300`}),(0,V.jsx)(`span`,{children:i?(0,V.jsxs)(V.Fragment,{children:[`Showing `,(0,V.jsx)(`strong`,{children:Ee}),` card`,Ee===1?``:`s`,` needing attention.`,(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:` Click to show all cards.`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`strong`,{children:xe.total}),` card`,xe.total===1?``:`s`,` need attention`,xe.byKind.oauth_expired+xe.byKind.oauth_required>0&&(0,V.jsxs)(V.Fragment,{children:[` `,`(`,xe.byKind.oauth_expired+xe.byKind.oauth_required,` `,`OAuth)`]}),`. `,(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Click to filter.`})]})})]})}),(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-1 py-2`,children:ue||pe||he?(0,V.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,5rem)] gap-y-2 pr-12`,children:Array.from({length:10}).map((e,t)=>(0,V.jsx)(`div`,{className:`animate-pulse`,children:(0,V.jsx)(`div`,{className:`bg-white/10 rounded-lg w-32 h-48 aspect-[2/3]`})},t))}):Ee===0?(0,V.jsxs)(`div`,{className:`text-center py-12`,children:[(0,V.jsx)(`div`,{className:`text-gray-400 mb-4`,children:(0,V.jsx)(`i`,{className:`fas fa-layer-group text-4xl`})}),(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-300 mb-2`,children:`No cards yet`}),(0,V.jsx)(`p`,{className:`text-gray-400 text-sm mb-4`,children:Oe?i?`No cards with warnings match your current filters`:`Try adjusting your search or filters`:`Register an MCP server, API key, or playbook to get started`}),!Oe&&(0,V.jsxs)(`div`,{className:`flex gap-3 justify-center`,children:[(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#92E4DD`),onClick:()=>s(!0),"data-testid":`button-register-mcp-empty`,children:[(0,V.jsx)(zi,{className:`w-3 h-3 mr-1`}),`Register MCP`]}),(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`border-2 hover:opacity-90 bg-gradient-to-b from-gray-900 via-gray-800 to-gray-900`,style:Pl(`#F9386D`),onClick:()=>p(!0),"data-testid":`button-register-api-key-empty`,children:[(0,V.jsx)(Ai,{className:`w-3 h-3 mr-1`}),`Register API key`]})]})]}):(0,V.jsxs)(`div`,{className:`relative isolate grid grid-cols-[repeat(auto-fill,5rem)] gap-y-2 pr-12`,style:{isolation:`isolate`},"data-testid":`collection-card-grid`,children:[Te.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-t},children:(0,V.jsx)(Yl,{playbook:e,isInActiveDeck:Ae.has(e.id),activeDeck:ne??void 0,isInCollection:!0,onDragStart:ie,onDragEnd:ae,onCardClick:Pe,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),warnings:xe.playbookWarnings.get(e.id)})},e.id)),we.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-Te.length-t},children:(0,V.jsx)(ql,{credential:e,isInActiveDeck:ke.has(e.id),activeDeck:ne??void 0,isInCollection:!0,onDragStart:re,onDragEnd:ae,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),onCardClick:Fe,warnings:xe.credentialWarnings.get(e.id)})},e.id)),Ce.map((e,t)=>(0,V.jsx)(`div`,{className:`relative group`,style:{zIndex:k===e.id?999999:Ee-Te.length-we.length-t},children:(0,V.jsx)(Ul,{service:e,onDragStart:B,onDragEnd:ae,isInActiveDeck:ne?.services?.some(t=>t.id===e.id)||!1,onCardClick:Ne,isInCollection:!0,onMouseEnter:()=>Ie(e.id),onMouseLeave:()=>Ie(null),activeDeck:ne??void 0,warnings:xe.serviceWarnings.get(e.id)})},e.id))]})})]})]})]})}),(0,V.jsxs)(`div`,{className:`fixed inset-0 pointer-events-none z-0 overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`absolute top-20 left-20`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-cyan-500/10 blur-3xl animate-orb-drift-1`})}),(0,V.jsx)(`div`,{className:`absolute bottom-20 right-20`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-pink-500/10 blur-3xl animate-orb-drift-2`})}),(0,V.jsx)(`div`,{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2`,children:(0,V.jsx)(`div`,{className:`h-96 w-96 rounded-full bg-purple-500/5 blur-3xl animate-orb-drift-3`})})]}),(0,V.jsx)(Rm,{type:`mcp`,open:o,onOpenChange:s}),(0,V.jsx)(wE,{service:c,isOpen:u,onClose:()=>d(!1)}),(0,V.jsx)(Km,{open:f,onOpenChange:p}),(0,V.jsx)(uh,{credentialId:m,open:g,onOpenChange:_}),(0,V.jsx)(qm,{open:v,onOpenChange:y}),(0,V.jsx)(lh,{playbookId:x,open:C,onOpenChange:w}),(0,V.jsx)(TE,{open:T,onOpenChange:E})]})}var _O=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`rounded-lg border bg-card text-card-foreground shadow-sm`,e),...t}));_O.displayName=`Card`;var vO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`flex flex-col space-y-1.5 p-6`,e),...t}));vO.displayName=`CardHeader`;var yO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`text-2xl font-semibold leading-none tracking-tight`,e),...t}));yO.displayName=`CardTitle`;var bO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`text-sm text-muted-foreground`,e),...t}));bO.displayName=`CardDescription`;var xO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`p-6 pt-0`,e),...t}));xO.displayName=`CardContent`;var SO=b.forwardRef(({className:e,...t},n)=>(0,V.jsx)(`div`,{ref:n,className:W(`flex items-center p-6 pt-0`,e),...t}));SO.displayName=`CardFooter`;function CO(){return(0,V.jsx)(`div`,{className:`min-h-screen w-full flex items-center justify-center bg-gray-50`,children:(0,V.jsx)(_O,{className:`w-full max-w-md mx-4`,children:(0,V.jsxs)(xO,{className:`pt-6`,children:[(0,V.jsxs)(`div`,{className:`flex mb-4 gap-2`,children:[(0,V.jsx)(bi,{className:`h-8 w-8 text-red-500`}),(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900`,children:`404 Page Not Found`})]}),(0,V.jsx)(`p`,{className:`mt-4 text-sm text-gray-600`,children:`Did you forget to add the page to the router?`})]})})})}function wO(){let[e]=pe(),[t,n]=(0,b.useState)(`loading`),[r,i]=(0,b.useState)(`Authenticating...`);return(0,b.useEffect)(()=>{(async()=>{try{let e=new URL(window.location.href),t=e.searchParams.get(`success`),r=e.searchParams.get(`error`),a=e.searchParams.get(`serviceId`);t===`true`?(n(`success`),i(`Authentication successful! This window will close automatically.`),window.opener&&!window.opener.closed&&window.opener.postMessage({type:mE,serviceId:a??void 0},window.location.origin),setTimeout(()=>{window.close()},2e3)):t===`false`?(n(`error`),i(`OAuth Error: ${r||`Authentication failed`}`)):(n(`error`),i(`Invalid OAuth callback - please try again`))}catch(e){n(`error`),i(e instanceof Error?e.message:`Authentication failed`)}})()},[e]),(0,V.jsx)(`div`,{className:`flex items-center justify-center min-h-screen bg-background`,children:(0,V.jsxs)(`div`,{className:`text-center space-y-4`,children:[t===`loading`&&(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto`}),t===`success`&&(0,V.jsx)(`div`,{className:`text-green-500 text-4xl`,children:`✓`}),t===`error`&&(0,V.jsx)(`div`,{className:`text-red-500 text-4xl`,children:`✗`}),(0,V.jsx)(`h1`,{className:`text-xl font-semibold`,children:r}),t===`error`&&(0,V.jsx)(`button`,{onClick:()=>window.close(),className:`px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90`,children:`Close Window`})]})})}function TO(e){let t=()=>{throw Error(`Invalid url to pass to open(): ${e}`)},n;try{n=new URL(e)}catch{t()}return n.protocol!==`https:`&&n.protocol!==`http:`&&t(),n.hostname!==encodeURIComponent(n.hostname)&&t(),n.username&&(n.username=encodeURIComponent(n.username)),n.password&&(n.password=encodeURIComponent(n.password)),n.pathname=n.pathname.slice(0,1)+encodeURIComponent(n.pathname.slice(1)).replace(/%2f/gi,`/`),n.search=n.search.slice(0,1)+Array.from(n.searchParams.entries()).map(EO).join(`&`),n.hash=n.hash.slice(0,1)+encodeURIComponent(n.hash.slice(1)),n.href}function EO([e,t]){return`${encodeURIComponent(e)}${t.length>0?`=${encodeURIComponent(t)}`:``}`}var DO=class{serverUrl;storageKeyPrefix;serverUrlHash;clientName;clientUri;callbackUrl;preventAutoAuth;onPopupWindow;constructor(e,t={}){this.serverUrl=e,this.storageKeyPrefix=t.storageKeyPrefix||`mcp:auth`,this.serverUrlHash=this.hashString(e),this.clientName=t.clientName||`MCP Browser Client`,this.clientUri=t.clientUri||(typeof window<`u`?window.location.origin:``),this.callbackUrl=TO(t.callbackUrl||(typeof window<`u`?new URL(`/oauth/callback`,window.location.origin).toString():`/oauth/callback`)),this.preventAutoAuth=t.preventAutoAuth,this.onPopupWindow=t.onPopupWindow}get redirectUrl(){return TO(this.callbackUrl)}get clientMetadata(){return{redirect_uris:[this.redirectUrl],token_endpoint_auth_method:`none`,grant_types:[`authorization_code`,`refresh_token`],response_types:[`code`],client_name:this.clientName,client_uri:this.clientUri}}async clientInformation(){let e=this.getKey(`client_info`),t=localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.warn(`[${this.storageKeyPrefix}] Failed to parse client information:`,t),localStorage.removeItem(e);return}}async saveClientInformation(e){let t=this.getKey(`client_info`);localStorage.setItem(t,JSON.stringify(e))}async tokens(){let e=this.getKey(`tokens`),t=localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(t){console.warn(`[${this.storageKeyPrefix}] Failed to parse tokens:`,t),localStorage.removeItem(e);return}}async saveTokens(e){let t=this.getKey(`tokens`);localStorage.setItem(t,JSON.stringify(e)),localStorage.removeItem(this.getKey(`code_verifier`)),localStorage.removeItem(this.getKey(`last_auth_url`))}async saveCodeVerifier(e){let t=this.getKey(`code_verifier`);localStorage.setItem(t,e)}async codeVerifier(){let e=this.getKey(`code_verifier`),t=localStorage.getItem(e);if(!t)throw Error(`[${this.storageKeyPrefix}] Code verifier not found in storage for key ${e}. Auth flow likely corrupted or timed out.`);return t}async prepareAuthorizationUrl(e){let t=crypto.randomUUID(),n=`${this.storageKeyPrefix}:state_${t}`,r={serverUrlHash:this.serverUrlHash,expiry:Date.now()+6e5,providerOptions:{serverUrl:this.serverUrl,storageKeyPrefix:this.storageKeyPrefix,clientName:this.clientName,clientUri:this.clientUri,callbackUrl:this.callbackUrl}};localStorage.setItem(n,JSON.stringify(r)),e.searchParams.set(`state`,t);let i=TO(e.toString());return localStorage.setItem(this.getKey(`last_auth_url`),i),i}async redirectToAuthorization(e){if(this.preventAutoAuth)return;let t=await this.prepareAuthorizationUrl(e),n=`width=600,height=700,resizable=yes,scrollbars=yes,status=yes`;try{let e=window.open(t,`mcp_auth_${this.serverUrlHash}`,n);this.onPopupWindow&&this.onPopupWindow(t,n,e),!e||e.closed||e.closed===void 0?console.warn(`[${this.storageKeyPrefix}] Popup likely blocked by browser. Manual navigation might be required using the stored URL.`):(e.focus(),console.info(`[${this.storageKeyPrefix}] Redirecting to authorization URL in popup.`))}catch(e){console.error(`[${this.storageKeyPrefix}] Error opening popup window:`,e)}}getLastAttemptedAuthUrl(){let e=localStorage.getItem(this.getKey(`last_auth_url`));return e?TO(e):null}clearStorage(){let e=`${this.storageKeyPrefix}_${this.serverUrlHash}_`,t=`${this.storageKeyPrefix}:state_`,n=[],r=0;for(let r=0;r<localStorage.length;r++){let i=localStorage.key(r);if(i){if(i.startsWith(e))n.push(i);else if(i.startsWith(t))try{let e=localStorage.getItem(i);e&&JSON.parse(e).serverUrlHash===this.serverUrlHash&&n.push(i)}catch(e){console.warn(`[${this.storageKeyPrefix}] Error parsing state key ${i} during clearStorage:`,e)}}}return[...new Set(n)].forEach(e=>{localStorage.removeItem(e),r++}),r}hashString(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t).toString(16)}getKey(e){return`${this.storageKeyPrefix}_${this.serverUrlHash}_${e}`}},OO=Object.freeze({status:`aborted`});function J(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(let e in o.prototype)e in n||Object.defineProperty(n,e,{value:o.prototype[e].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var kO=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},AO={};function jO(e){return e&&Object.assign(AO,e),AO}function MO(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function NO(e,t){return typeof t==`bigint`?t.toString():t}function PO(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function FO(e){return e==null}function IO(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function LO(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r;return Number.parseInt(e.toFixed(i).replace(`.`,``))%Number.parseInt(t.toFixed(i).replace(`.`,``))/10**i}function RO(e,t,n){Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function zO(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function BO(e){return JSON.stringify(e)}var VO=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function HO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var UO=PO(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function WO(e){if(HO(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return HO(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}var GO=new Set([`string`,`number`,`symbol`]);function KO(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function qO(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function Y(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function JO(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var YO={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function XO(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&(n[e]=r.shape[e])}return qO(e,{...e._zod.def,shape:n,checks:[]})}function ZO(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete n[e]}return qO(e,{...e._zod.def,shape:n,checks:[]})}function QO(e,t){if(!WO(t))throw Error(`Invalid input to extend: expected a plain object`);return qO(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return zO(this,`shape`,n),n},checks:[]})}function $O(e,t){return qO(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return zO(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function ek(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return qO(t,{...t._zod.def,shape:i,checks:[]})}function tk(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return qO(t,{...t._zod.def,shape:i,checks:[]})}function nk(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function rk(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function ik(e){return typeof e==`string`?e:e?.message}function ak(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=ik(e.inst?._zod.def?.error?.(e))??ik(t?.error?.(e))??ik(n.customError?.(e))??ik(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function ok(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function sk(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ck=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get(){return JSON.stringify(t,NO,2)},enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},lk=J(`$ZodError`,ck),uk=J(`$ZodError`,ck,{Parent:Error});function dk(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function fk(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}var pk=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new kO;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>ak(e,a,jO())));throw VO(t,i?.callee),t}return o.value},mk=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>ak(e,a,jO())));throw VO(t,i?.callee),t}return o.value},hk=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new kO;return a.issues.length?{success:!1,error:new(e??lk)(a.issues.map(e=>ak(e,i,jO())))}:{success:!0,data:a.value}},gk=hk(uk),_k=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>ak(e,i,jO())))}:{success:!0,data:a.value}},vk=_k(uk),yk=/^[cC][^\s-]{8,}$/,bk=/^[0-9a-z]+$/,xk=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Sk=/^[0-9a-vA-V]{20}$/,Ck=/^[A-Za-z0-9]{27}$/,wk=/^[a-zA-Z0-9_-]{21}$/,Tk=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Ek=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Dk=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,Ok=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,kk=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Ak(){return new RegExp(kk,`u`)}var jk=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Mk=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,Nk=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Pk=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Fk=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Ik=/^[A-Za-z0-9_-]*$/,Lk=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,Rk=/^\+(?:[0-9]){6,14}[0-9]$/,zk=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Bk=RegExp(`^${zk}$`);function Vk(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Hk(e){return RegExp(`^${Vk(e)}$`)}function Uk(e){let t=Vk({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${zk}T(?:${r})$`)}var Wk=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Gk=/^\d+$/,Kk=/^-?\d+(?:\.\d+)?/i,qk=/true|false/i,Jk=/null/i,Yk=/^[^A-Z]*$/,Xk=/^[^a-z]*$/,Zk=J(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qk={number:`number`,bigint:`bigint`,object:`date`},$k=J(`$ZodCheckLessThan`,(e,t)=>{Zk.init(e,t);let n=Qk[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),eA=J(`$ZodCheckGreaterThan`,(e,t)=>{Zk.init(e,t);let n=Qk[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tA=J(`$ZodCheckMultipleOf`,(e,t)=>{Zk.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):LO(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nA=J(`$ZodCheckNumberFormat`,(e,t)=>{Zk.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=YO[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Gk)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),rA=J(`$ZodCheckMaxLength`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=ok(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),iA=J(`$ZodCheckMinLength`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=ok(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),aA=J(`$ZodCheckLengthEquals`,(e,t)=>{var n;Zk.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!FO(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=ok(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),oA=J(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Zk.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),sA=J(`$ZodCheckRegex`,(e,t)=>{oA.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),cA=J(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Yk,oA.init(e,t)}),lA=J(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Xk,oA.init(e,t)}),uA=J(`$ZodCheckIncludes`,(e,t)=>{Zk.init(e,t);let n=KO(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),dA=J(`$ZodCheckStartsWith`,(e,t)=>{Zk.init(e,t);let n=RegExp(`^${KO(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),fA=J(`$ZodCheckEndsWith`,(e,t)=>{Zk.init(e,t);let n=RegExp(`.*${KO(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),pA=J(`$ZodCheckOverwrite`,(e,t)=>{Zk.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),mA=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
190
190
|
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
|
|
191
191
|
`))}},hA={major:4,minor:0,patch:0},gA=J(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=hA;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=nk(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new kO;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=nk(e,t))});else{if(e.issues.length===t)continue;r||=nk(e,t)}}return i?i.then(()=>e):e};e._zod.run=(n,i)=>{let a=e._zod.parse(n,i);if(a instanceof Promise){if(i.async===!1)throw new kO;return a.then(e=>t(e,r,i))}return t(a,r,i)}}e[`~standard`]={validate:t=>{try{let n=gk(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return vk(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}}),_A=J(`$ZodString`,(e,t)=>{gA.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Wk(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),vA=J(`$ZodStringFormat`,(e,t)=>{oA.init(e,t),_A.init(e,t)}),yA=J(`$ZodGUID`,(e,t)=>{t.pattern??=Ek,vA.init(e,t)}),bA=J(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Dk(e)}else t.pattern??=Dk();vA.init(e,t)}),xA=J(`$ZodEmail`,(e,t)=>{t.pattern??=Ok,vA.init(e,t)}),SA=J(`$ZodURL`,(e,t)=>{vA.init(e,t),e._zod.check=n=>{try{let r=n.value,i=new URL(r),a=i.href;t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:Lk.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),n.value=!r.endsWith(`/`)&&a.endsWith(`/`)?a.slice(0,-1):a;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),CA=J(`$ZodEmoji`,(e,t)=>{t.pattern??=Ak(),vA.init(e,t)}),wA=J(`$ZodNanoID`,(e,t)=>{t.pattern??=wk,vA.init(e,t)}),TA=J(`$ZodCUID`,(e,t)=>{t.pattern??=yk,vA.init(e,t)}),EA=J(`$ZodCUID2`,(e,t)=>{t.pattern??=bk,vA.init(e,t)}),DA=J(`$ZodULID`,(e,t)=>{t.pattern??=xk,vA.init(e,t)}),OA=J(`$ZodXID`,(e,t)=>{t.pattern??=Sk,vA.init(e,t)}),kA=J(`$ZodKSUID`,(e,t)=>{t.pattern??=Ck,vA.init(e,t)}),AA=J(`$ZodISODateTime`,(e,t)=>{t.pattern??=Uk(t),vA.init(e,t)}),jA=J(`$ZodISODate`,(e,t)=>{t.pattern??=Bk,vA.init(e,t)}),MA=J(`$ZodISOTime`,(e,t)=>{t.pattern??=Hk(t),vA.init(e,t)}),NA=J(`$ZodISODuration`,(e,t)=>{t.pattern??=Tk,vA.init(e,t)}),PA=J(`$ZodIPv4`,(e,t)=>{t.pattern??=jk,vA.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv4`})}),FA=J(`$ZodIPv6`,(e,t)=>{t.pattern??=Mk,vA.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv6`}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),IA=J(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Nk,vA.init(e,t)}),LA=J(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Pk,vA.init(e,t),e._zod.check=n=>{let[r,i]=n.value.split(`/`);try{if(!i)throw Error();let e=Number(i);if(`${e}`!==i||e<0||e>128)throw Error();new URL(`http://[${r}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function RA(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var zA=J(`$ZodBase64`,(e,t)=>{t.pattern??=Fk,vA.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64`}),e._zod.check=n=>{RA(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function BA(e){if(!Ik.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return RA(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var VA=J(`$ZodBase64URL`,(e,t)=>{t.pattern??=Ik,vA.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64url`}),e._zod.check=n=>{BA(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),HA=J(`$ZodE164`,(e,t)=>{t.pattern??=Rk,vA.init(e,t)});function UA(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var WA=J(`$ZodJWT`,(e,t)=>{vA.init(e,t),e._zod.check=n=>{UA(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),GA=J(`$ZodNumber`,(e,t)=>{gA.init(e,t),e._zod.pattern=e._zod.bag.pattern??Kk,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),KA=J(`$ZodNumber`,(e,t)=>{nA.init(e,t),GA.init(e,t)}),qA=J(`$ZodBoolean`,(e,t)=>{gA.init(e,t),e._zod.pattern=qk,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),JA=J(`$ZodNull`,(e,t)=>{gA.init(e,t),e._zod.pattern=Jk,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{let r=t.value;return r===null||t.issues.push({expected:`null`,code:`invalid_type`,input:r,inst:e}),t}}),YA=J(`$ZodAny`,(e,t)=>{gA.init(e,t),e._zod.parse=e=>e}),XA=J(`$ZodUnknown`,(e,t)=>{gA.init(e,t),e._zod.parse=e=>e}),ZA=J(`$ZodNever`,(e,t)=>{gA.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function QA(e,t,n){e.issues.length&&t.issues.push(...rk(n,e.issues)),t.value[n]=e.value}var $A=J(`$ZodArray`,(e,t)=>{gA.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>QA(t,n,e))):QA(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function ej(e,t,n){e.issues.length&&t.issues.push(...rk(n,e.issues)),t.value[n]=e.value}function tj(e,t,n,r){e.issues.length?r[n]===void 0?n in r?t.value[n]=void 0:t.value[n]=e.value:t.issues.push(...rk(n,e.issues)):e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}var nj=J(`$ZodObject`,(e,t)=>{gA.init(e,t);let n=PO(()=>{let e=Object.keys(t.shape);for(let n of e)if(!(t.shape[n]instanceof gA))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=JO(t.shape);return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});RO(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=e=>{let t=new mA([`shape`,`payload`,`ctx`]),r=n.value,i=e=>{let t=BO(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of r.keys)a[e]=`key_${o++}`;t.write(`const newResult = {}`);for(let e of r.keys)if(r.optionalKeys.has(e)){let n=a[e];t.write(`const ${n} = ${i(e)};`);let r=BO(e);t.write(`
|
|
192
192
|
if (${n}.issues.length) {
|
|
@@ -232,4 +232,4 @@ ${F.data.oauth.issuer?`Issuer: ${F.data.oauth.issuer}`:``}`;A({title:`OAuth Setu
|
|
|
232
232
|
`));let n=[],r=e.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let e=0;e<r.length;e++){let i=r[e];e%2&&!t.newlineIsToken?n[n.length-1]+=i:n.push(i)}return n}function PV(e){return e==`.`||e==`!`||e==`?`}new class extends hV{tokenize(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(r==e.length-1){t.push(e.slice(n));break}if(PV(e[r])&&e[r+1].match(/\s/)){for(t.push(e.slice(n,r+1)),r=n=r+1;e[r+1]?.match(/\s/);)r++;t.push(e.slice(n,r+1)),n=r+1}}return t}},new class extends hV{tokenize(e){return e.split(/([{}:;,]|\s+)/)}},new class extends hV{constructor(){super(...arguments),this.tokenize=NV}get useLongestToken(){return!0}castInput(e,t){let{undefinedReplacement:n,stringifyReplacer:r=(e,t)=>t===void 0?n:t}=t;return typeof e==`string`?e:JSON.stringify(FV(e,null,null,r),null,` `)}equals(e,t,n){return super.equals(e.replace(/,([\r\n])/g,`$1`),t.replace(/,([\r\n])/g,`$1`),n)}};function FV(e,t,n,r,i){t||=[],n||=[],r&&(e=r(i===void 0?``:i,e));let a=0;for(;a<t.length;a+=1)if(t[a]===e)return n[a];let o;if(Object.prototype.toString.call(e)===`[object Array]`){for(t.push(e),o=Array(e.length),n.push(o),a=0;a<e.length;a+=1)o[a]=FV(e[a],t,n,r,String(a));return t.pop(),n.pop(),o}if(e&&e.toJSON&&(e=e.toJSON()),typeof e==`object`&&e){t.push(e),o={},n.push(o);let i=[],s;for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&i.push(s);for(i.sort(),a=0;a<i.length;a+=1)s=i[a],o[s]=FV(e[s],t,n,r,s);t.pop(),n.pop()}else o=e;return o}new class extends hV{tokenize(e){return e.slice()}join(e){return e}removeEmpty(e){return e}};var IV=3,LV=10;function RV(e){return e===``?[]:e.replace(/\n$/,``).split(`
|
|
233
233
|
`)}function zV(e,t){let n=MV(e,t),r=[],i=1,a=1;for(let e of n){let t=RV(e.value);if(!e.added&&!e.removed&&t.length>=LV){let e=t.slice(0,IV),n=t.slice(-3),o=t.length-6;for(let t of e)r.push({kind:`unchanged`,text:t,oldLine:i++,newLine:a++});o>0&&(r.push({kind:`ellipsis`,text:`${o} unchanged lines`}),i+=o,a+=o);for(let e of n)r.push({kind:`unchanged`,text:e,oldLine:i++,newLine:a++});continue}for(let n of t)e.added?r.push({kind:`added`,text:n,newLine:a++}):e.removed?r.push({kind:`removed`,text:n,oldLine:i++}):r.push({kind:`unchanged`,text:n,oldLine:i++,newLine:a++})}return r}function BV(e){return e.some(e=>e.kind===`added`||e.kind===`removed`)}var VV=`max-w-full overflow-x-auto rounded-md border border-gray-800 bg-gray-950 font-mono text-xs leading-5`;function HV(e){switch(e){case`added`:return`bg-emerald-950/70 text-emerald-100`;case`removed`:return`bg-rose-950/70 text-rose-100`;case`ellipsis`:return`bg-gray-900 text-gray-500 italic`;default:return`bg-gray-950 text-gray-300`}}function UV(e){switch(e){case`added`:return`+`;case`removed`:return`-`;case`ellipsis`:return`…`;default:return` `}}function WV({rows:e,emptyLabel:t}){return e.length===0?(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:t}):(0,V.jsx)(`div`,{className:VV,children:e.map((e,t)=>(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] gap-0 ${HV(e.kind)}`,children:[(0,V.jsx)(`span`,{className:`select-none border-r border-gray-800/80 px-2 py-0.5 text-right text-gray-600`,children:e.oldLine??``}),(0,V.jsx)(`span`,{className:`select-none border-r border-gray-800/80 px-2 py-0.5 text-right text-gray-600`,children:e.newLine??``}),(0,V.jsxs)(`div`,{className:`flex min-w-0 gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 select-none text-gray-500`,children:UV(e.kind)}),(0,V.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words`,children:e.text||` `})]})]},`${e.kind}-${t}-${e.oldLine??``}-${e.newLine??``}`))})}function GV({before:e,after:t}){let n=e.filter(e=>!t.includes(e)),r=t.filter(t=>!e.includes(t));return n.length===0&&r.length===0?null:(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-400`,children:`Triggers`}),(0,V.jsxs)(`div`,{className:`${VV} p-0`,children:[n.map(e=>(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-rose-950/70 text-rose-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`-`}),(0,V.jsx)(`span`,{children:e})]})]},`removed-${e}`)),r.map(e=>(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-emerald-950/70 text-emerald-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`+`}),(0,V.jsx)(`span`,{children:e})]})]},`added-${e}`))]})]})}function KV({preview:e}){let t=mV(e),n=zV(e.before.body,e.after.body),r=e.before.body.trim()!==e.after.body.trim()&&e.after.body.length>0&&!e.after.body.includes(e.before.body.slice(0,40))&&BV(n),i=e.before.title!==e.after.title,a=e.before.triggers.join(`
|
|
234
234
|
`)!==e.after.triggers.join(`
|
|
235
|
-
`);return(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[!t&&(0,V.jsxs)(`div`,{className:`rounded-md border border-amber-500/50 bg-amber-500/10 p-3 text-sm text-amber-100`,children:[`No change detected — ops did not alter the playbook body or triggers. Reject this proposal and re-propose with a matching list anchor or `,(0,V.jsx)(`code`,{children:`rewrite_body`}),`.`]}),r&&(0,V.jsx)(`div`,{className:`rounded-md border border-amber-500/50 bg-amber-500/10 p-3 text-sm text-amber-100`,children:`Full-body rewrite proposed — review carefully.`}),i&&(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-400`,children:`Title`}),(0,V.jsxs)(`div`,{className:`${VV} p-0`,children:[e.before.title&&(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-rose-950/70 text-rose-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`-`}),(0,V.jsx)(`span`,{children:e.before.title})]})]}),e.after.title&&(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-emerald-950/70 text-emerald-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`+`}),(0,V.jsx)(`span`,{children:e.after.title})]})]})]})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-400`,children:`Body`}),(0,V.jsx)(WV,{rows:n,emptyLabel:`No body changes.`})]}),a&&(0,V.jsx)(GV,{before:e.before.triggers,after:e.after.triggers})]})}function qV(e){if(!e)return[];try{return JSON.parse(e)}catch{return[]}}function JV({conflicts:e,title:t=`Trigger overlap warnings`}){return e.length===0?null:(0,V.jsxs)(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 p-4 text-sm text-amber-50`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-amber-200/90`,children:t}),(0,V.jsx)(`p`,{className:`mt-2 text-amber-100/90`,children:`These triggers overlap with other playbooks on the deck. Accept is still allowed — disambiguate triggers or propose a merge if the wrong playbook keeps firing.`}),(0,V.jsx)(`ul`,{className:`mt-3 space-y-2`,children:e.map(e=>(0,V.jsxs)(`li`,{className:`rounded border border-amber-500/20 bg-gray-950/60 p-3`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(fh,{variant:`outline`,className:`border-amber-400/40 text-amber-100`,children:e.level}),(0,V.jsx)(`span`,{className:`font-medium text-amber-50`,children:e.otherPlaybookTitle}),(0,V.jsx)(`span`,{className:`font-mono text-xs text-amber-200/70`,children:e.otherPlaybookId})]}),(0,V.jsxs)(`p`,{className:`mt-2 text-amber-100/90`,children:[(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Candidate:`}),` `,e.trigger]}),(0,V.jsxs)(`p`,{className:`text-amber-100/80`,children:[(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Other:`}),` `,e.otherTrigger]})]},`${e.trigger}-${e.otherPlaybookId}-${e.level}`))})]})}var YV=8,XV=[{value:`proposed`,label:`Waiting`},{value:`accepted`,label:`Accepted`},{value:`rejected`,label:`Rejected`},{value:`superseded`,label:`Superseded`},{value:`stale`,label:`Stale`},{value:`all`,label:`All`}];function ZV(e){if(!e.evidenceJson)return null;try{return JSON.parse(e.evidenceJson)}catch{return null}}function QV(e){switch(e){case`proposed`:return`border-blue-500/40 text-blue-200`;case`accepted`:return`border-emerald-500/40 text-emerald-200`;case`rejected`:return`border-rose-500/40 text-rose-200`;case`superseded`:return`border-violet-500/40 text-violet-200`;case`stale`:return`border-amber-500/40 text-amber-200`}}function $V(){let[e,t]=(0,b.useState)(null),[n,r]=(0,b.useState)(`proposed`),[i,a]=(0,b.useState)(0),{toast:o}=on(),s=Et();function c(e){t(e)}function l(e){r(e),a(0),t(null)}let{data:u=[]}=Vt({queryKey:[`/api/playbook-patches`,`proposed`],queryFn:()=>Xm(`proposed`)}),d=n===`all`?void 0:n,{data:f=[],isLoading:p}=Vt({queryKey:[`/api/playbook-patches`,n],queryFn:()=>Xm(d)}),m=Math.max(1,Math.ceil(f.length/YV)),h=Math.min(i,m-1),g=(0,b.useMemo)(()=>{let e=h*YV;return f.slice(e,e+YV)},[f,h]);(0,b.useEffect)(()=>{i!==h&&a(h)},[i,h]);let{data:_,isLoading:v,isError:y,error:x}=Vt({queryKey:[`/api/playbook-patches`,e,`preview`],queryFn:()=>Zm(e),enabled:!!e}),S=_?mV(_):!1,C=f.find(t=>t.id===e)??null,w=C?.status===`proposed`,T=Ht({mutationFn:e=>Qm(e),onSuccess:()=>{o({title:`Patch accepted`}),t(null),s.invalidateQueries({queryKey:[`/api/playbook-patches`]}),s.invalidateQueries({queryKey:[`/api/playbooks`]}),s.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:e=>{o({title:`Accept failed`,description:e.message,variant:`destructive`})}}),E=Ht({mutationFn:e=>$m(e),onSuccess:()=>{o({title:`Patch rejected`}),t(null),s.invalidateQueries({queryKey:[`/api/playbook-patches`]}),s.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:e=>{o({title:`Reject failed`,description:e.message,variant:`destructive`})}}),D=n===`proposed`?`No proposals waiting for review.`:n===`all`?`No playbook patches yet.`:`No ${n} patches.`;return(0,V.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-gray-950 text-gray-100`,children:[(0,V.jsx)(`header`,{className:`shrink-0 border-b border-gray-800 px-4 py-4 sm:px-6`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-7xl flex-wrap items-center gap-3`,children:[(0,V.jsx)(ye,{href:`/`,children:(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`text-gray-300`,children:[(0,V.jsx)(ui,{className:`mr-1 h-4 w-4`}),`Deck`]})}),(0,V.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Playbook review queue`}),(0,V.jsxs)(fh,{variant:`secondary`,children:[u.length,` waiting`]}),(0,V.jsx)(ye,{href:`/feedback-signals`,className:`ml-auto text-sm hover:underline`,style:{color:`#92E4DD`},children:`Feedback data →`})]})}),(0,V.jsxs)(`main`,{className:`mx-auto grid w-full max-w-7xl min-h-0 flex-1 gap-6 overflow-hidden px-4 py-6 sm:px-6 lg:grid-cols-[minmax(18rem,20rem)_minmax(0,1fr)] lg:items-stretch`,children:[(0,V.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-col`,children:[(0,V.jsx)(`h2`,{className:`mb-3 shrink-0 text-sm font-medium text-gray-400`,children:`Proposals`}),(0,V.jsx)(`div`,{className:`mb-3 flex shrink-0 flex-wrap gap-1`,children:XV.map(({value:e,label:t})=>{let r=n===e;return(0,V.jsx)(G,{size:`sm`,variant:r?`gold`:`outline`,className:r?void 0:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800 hover:text-gray-100`,"aria-pressed":r,onClick:()=>l(e),children:t},e)})}),(0,V.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[p&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading…`}),!p&&f.length===0&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:D}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:g.map(t=>(0,V.jsx)(`li`,{children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>c(t.id),className:`w-full rounded-lg border p-3 text-left transition ${e===t.id?`border-blue-500 bg-gray-900`:`border-gray-800 bg-gray-900/50 hover:border-gray-700`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block font-medium leading-snug`,children:t.kind===`create`?`New: ${t.displayTitle}`:t.displayTitle}),t.playbookId&&t.kind!==`create`&&(0,V.jsx)(`span`,{className:`mt-0.5 block truncate font-mono text-xs text-gray-600`,children:t.playbookId}),Ym(t.deckNames)&&(0,V.jsxs)(`span`,{className:`mt-1 block text-xs text-gray-500`,children:[`Decks: `,Ym(t.deckNames)]})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,V.jsx)(fh,{variant:`outline`,className:`shrink-0`,children:t.kind}),n!==`proposed`&&(0,V.jsx)(fh,{variant:`outline`,className:`shrink-0 ${QV(t.status)}`,children:t.status})]})]}),(0,V.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm text-gray-400`,children:t.rationale}),(0,V.jsxs)(`p`,{className:`mt-1 text-xs text-gray-600`,children:[t.source,` · `,new Date(t.createdAt).toLocaleString()]})]})},t.id))})]}),f.length>YV&&(0,V.jsxs)(`div`,{className:`mt-3 flex shrink-0 items-center justify-between gap-2 border-t border-gray-800 pt-3`,children:[(0,V.jsxs)(G,{type:`button`,size:`sm`,variant:`outline`,className:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800`,disabled:h<=0,onClick:()=>a(e=>Math.max(0,e-1)),children:[(0,V.jsx)(_i,{className:`mr-1 h-4 w-4`}),`Newer`]}),(0,V.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[h+1,` / `,m,(0,V.jsxs)(`span`,{className:`ml-1 text-gray-600`,children:[`(`,f.length,`)`]})]}),(0,V.jsxs)(G,{type:`button`,size:`sm`,variant:`outline`,className:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800`,disabled:h>=m-1,onClick:()=>a(e=>Math.min(m-1,e+1)),children:[`Older`,(0,V.jsx)(vi,{className:`ml-1 h-4 w-4`})]})]})]}),(0,V.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-col overflow-hidden`,children:[(0,V.jsx)(`h2`,{className:`mb-3 shrink-0 text-sm font-medium text-gray-400`,children:`Detail`}),!C&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Select a proposal to preview the diff.`}),C&&(0,V.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-lg border border-gray-800 bg-gray-900/50`,children:[(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4 sm:p-5`,children:(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(fh,{variant:`outline`,className:QV(C.status),children:C.status}),C.resolvedAt&&(0,V.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`Resolved `,new Date(C.resolvedAt).toLocaleString()]})]}),(0,V.jsx)(`p`,{className:`text-sm leading-relaxed text-gray-300`,children:C.rationale}),C.status===`rejected`&&C.rejectionReason&&(0,V.jsxs)(`div`,{className:`rounded-md border border-rose-500/40 bg-rose-500/10 p-3 text-sm text-rose-100`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-rose-300/80`,children:`Rejection reason`}),(0,V.jsx)(`p`,{className:`mt-1`,children:C.rejectionReason})]}),C.status===`superseded`&&C.supersededBy&&(0,V.jsxs)(`div`,{className:`rounded-md border border-violet-500/40 bg-violet-500/10 p-3 text-sm text-violet-100`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-violet-300/80`,children:`Superseded by`}),(0,V.jsx)(`button`,{type:`button`,className:`mt-1 font-mono text-sm underline-offset-2 hover:underline`,onClick:()=>{let e=C.supersededBy;r(`all`),a(0),c(e)},children:C.supersededBy})]}),(()=>{let e=ZV(C);return e?(0,V.jsxs)(`div`,{className:`rounded-md border border-gray-700 bg-gray-950 p-4 text-sm`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500`,children:`Your correction`}),(0,V.jsxs)(`p`,{className:`mt-2 italic text-gray-200`,children:[`“`,e.user_feedback_excerpt,`”`]}),e.failure_summary&&(0,V.jsx)(`p`,{className:`mt-2 text-gray-400`,children:e.failure_summary})]}):null})(),(()=>{let e=qV(C.conflictsJson),t=_?.trigger_conflicts??[],n=t.length>0?t:e;return(0,V.jsx)(JV,{conflicts:n})})(),v&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading preview…`}),y&&(0,V.jsxs)(`div`,{className:`rounded-md border border-rose-500/50 bg-rose-500/10 p-3 text-sm text-rose-100`,children:[`Preview failed —`,` `,x?.message??`could not apply ops to the current playbook.`,w?` Reject and re-propose with exact list anchors or rewrite_body.`:` Historical preview may be incomplete if the playbook changed.`]}),_&&(0,V.jsx)(KV,{preview:_}),C.status===`stale`&&(0,V.jsx)(`p`,{className:`text-sm text-amber-400`,children:`Stale — playbook changed since proposal. Re-propose from a fresh session.`})]})}),w?(0,V.jsxs)(`div`,{className:`relative z-10 shrink-0 space-y-3 border-t border-gray-800 bg-gray-950 p-4 shadow-[0_-16px_32px_rgba(0,0,0,0.55)] sm:p-5`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-400`,children:`Your decision`}),(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,V.jsx)(G,{variant:`gold`,onClick:()=>T.mutate(C.id),disabled:T.isPending||y||!S,children:`Accept`}),(0,V.jsx)(G,{variant:`destructive`,onClick:()=>E.mutate(C.id),disabled:E.isPending,children:`Reject`})]})]}):(0,V.jsxs)(`div`,{className:`shrink-0 border-t border-gray-800 bg-gray-950 px-4 py-3 text-sm text-gray-500 sm:px-5`,children:[`Read-only — already `,C.status,`. Switch to Waiting to review open proposals.`]})]})]})]})]})}var eH=`border-[#C4B643] data-[state=checked]:bg-[#C4B643] data-[state=checked]:text-[#0A0A07] data-[state=indeterminate]:bg-[#C4B643] data-[state=indeterminate]:text-[#0A0A07]`;function tH(){let{toast:e}=on(),t=Et(),[n,r]=(0,b.useState)(`open`),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(new Set),{data:u}=Vt({queryKey:[`/api/playbooks/vault`]}),d=u?.data??[],f=(0,b.useMemo)(()=>{let e=new Map;for(let t of d)e.set(t.id,t.title);return e},[d]),p={status:n===`all`?void 0:n,playbookId:i||void 0,excludeInProposal:n===`open`?!o:void 0},{data:m=[],isLoading:h}=Vt({queryKey:[`/api/feedback-signals`,p],queryFn:()=>rh(p)}),g=Ht({mutationFn:e=>ih(e),onSuccess:n=>{e({title:`Discarded ${n.discarded} signal(s)`}),l(new Set),t.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:t=>{e({title:`Discard failed`,description:t.message,variant:`destructive`})}}),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=async()=>{let t=c.size>0?m.filter(e=>c.has(e.id)):m;if(t.length!==0){if(t.some(e=>!e.id)){e({title:`Copy blocked`,description:`Every signal must include an id for tracking.`,variant:`destructive`});return}try{await navigator.clipboard.writeText(ch(t)),e({title:`Copied curation prompt`,description:`${t.length} signal id(s) included — paste into your IDE agent.`})}catch(t){e({title:`Copy failed`,description:t instanceof Error?t.message:`Clipboard unavailable`,variant:`destructive`})}}},y=[...c].filter(e=>m.find(t=>t.id===e)?.status===`open`),x=m.length>0&&m.every(e=>c.has(e.id)),S=m.some(e=>c.has(e.id));return(0,V.jsxs)(`div`,{className:`flex min-h-dvh flex-col bg-gray-950 text-gray-100`,children:[(0,V.jsx)(`header`,{className:`shrink-0 border-b border-gray-800 px-4 py-4 sm:px-6`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-7xl flex-wrap items-center gap-3`,children:[(0,V.jsx)(ye,{href:`/`,children:(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`text-gray-300`,children:[(0,V.jsx)(ui,{className:`mr-1 h-4 w-4`}),`Home`]})}),(0,V.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Feedback`}),(0,V.jsx)(fh,{variant:`outline`,children:m.length}),(0,V.jsx)(ye,{href:`/playbook-patches`,className:`ml-auto text-sm hover:underline`,style:{color:`#92E4DD`},children:`Playbook proposals →`})]})}),(0,V.jsxs)(`main`,{className:`mx-auto w-full max-w-7xl flex-1 space-y-4 px-4 py-6 sm:px-6`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-400`,children:`Durable correction data for playbook enhancement. Filter by playbook, copy rows (with ids) for an IDE agent to propose, then accept the proposal to mark feedback solved.`}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3 rounded-lg border border-gray-800 bg-gray-900/40 p-3`,children:[(0,V.jsxs)(`label`,{className:`text-xs text-gray-500`,children:[`Playbook`,(0,V.jsxs)(`select`,{className:`mt-1 block min-w-[12rem] rounded border border-gray-700 bg-gray-950 px-2 py-1.5 text-sm text-gray-100`,value:i,onChange:e=>{a(e.target.value),l(new Set)},children:[(0,V.jsx)(`option`,{value:``,children:`All`}),d.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:[[`open`,`Open`],[`actioned`,`Actioned`],[`discarded`,`Discarded`],[`all`,`All`]].map(([e,t])=>{let i=n===e;return(0,V.jsx)(G,{size:`sm`,variant:i?`gold`:`outline`,className:i?void 0:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800 hover:text-gray-100`,"aria-pressed":i,onClick:()=>{r(e),l(new Set)},children:t},e)})}),n===`open`&&(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-400`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Include already in an open proposal`]}),(0,V.jsxs)(`div`,{className:`ml-auto flex flex-wrap gap-2`,children:[(0,V.jsxs)(G,{size:`sm`,variant:`outline`,disabled:m.length===0,onClick:()=>void v(),children:[(0,V.jsx)(wi,{className:`mr-1 h-3.5 w-3.5`}),`Copy for agent`,c.size>0?` (${c.size})`:``]}),(0,V.jsxs)(G,{size:`sm`,variant:`destructive`,disabled:y.length===0||g.isPending,onClick:()=>g.mutate(y),children:[(0,V.jsx)(Hi,{className:`mr-1 h-3.5 w-3.5`}),`Discard selected`]})]})]}),h&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading…`}),!h&&m.length===0&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`No signals match these filters.`}),!h&&m.length>0&&(0,V.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-gray-800`,children:(0,V.jsxs)(`table`,{className:`w-full min-w-[48rem] text-left text-sm`,children:[(0,V.jsx)(`thead`,{className:`border-b border-gray-800 bg-gray-900/80 text-xs uppercase text-gray-500`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`w-10 px-3 py-2`,children:(0,V.jsx)(cg,{checked:x?!0:S?`indeterminate`:!1,onCheckedChange:()=>{if(x){l(new Set);return}l(new Set(m.map(e=>e.id)))},"aria-label":`Select all visible signals`,disabled:m.length===0,className:eH})}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Excerpt`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Failure`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Playbook`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Source`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`When`})]})}),(0,V.jsx)(`tbody`,{children:m.map(e=>{let t=ah(e);return(0,V.jsxs)(`tr`,{className:`border-b border-gray-800/80 align-top`,children:[(0,V.jsx)(`td`,{className:`px-3 py-2`,children:(0,V.jsx)(cg,{checked:c.has(e.id),onCheckedChange:()=>_(e.id),"aria-label":`Select ${e.id}`,className:eH})}),(0,V.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,V.jsx)(`p`,{className:`font-mono text-[11px] text-gray-600`,children:e.id}),(0,V.jsxs)(`p`,{className:`text-gray-200`,children:[`“`,e.userFeedbackExcerpt,`”`]}),t&&(0,V.jsx)(fh,{variant:`outline`,className:`mt-1 text-[10px]`,children:`In proposal`})]}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-400`,children:e.failureSummary}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-300`,children:e.candidatePlaybookId?f.get(e.candidatePlaybookId)??e.candidatePlaybookId:`—`}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-500`,children:e.source}),(0,V.jsx)(`td`,{className:`px-3 py-2 whitespace-nowrap text-gray-500`,children:new Date(e.createdAt).toLocaleString()})]},e.id)})})]})})]})]})}function nH(e){return e instanceof Ut?e.errorCode===`GRANT_REQUIRED`||e.errorCode===`DASHBOARD_REQUIRED`?{message:`This browser is not signed in to the Agent Deck dashboard. Run agent-deck open, then open this approval link again.`,retryable:!0}:e.errorCode===`ADMIN_CHALLENGE_EXPIRED`?{message:`This approval request expired or was already used. Ask the agent to request admin elevation again.`,retryable:!1}:e.errorCode===`SESSION_INVALID`?{message:`The agent session for this request is gone. Ask the agent to reconnect and request admin elevation again.`,retryable:!1}:{message:e.message||`Approval failed`,retryable:!0}:e instanceof TypeError?{message:`Could not reach Agent Deck. Check that it is running (agent-deck status) and try again.`,retryable:!0}:{message:e instanceof Error&&e.message?e.message:`Approval failed`,retryable:!0}}function rH(){let e=new URLSearchParams(window.location.search),t=e.get(`challenge`)??``,n=e.get(`session`)??``,[r,i]=(0,b.useState)(`idle`),[a,o]=(0,b.useState)(``),[s,c]=(0,b.useState)(!0);(0,b.useEffect)(()=>{(!t||!n)&&(i(`error`),c(!1),o(`This link is incomplete. Ask the agent to request admin elevation again.`))},[t,n]);async function l(){if(t&&n){i(`loading`);try{await H(`POST`,`/api/trusted-session/admin/approve`,{challengeId:t,runtimeSessionId:n}),i(`success`),o(`Admin elevation approved for this MCP session. Return to the agent.`)}catch(e){let t=nH(e);i(`error`),c(t.retryable),o(t.message)}}}return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-6 bg-muted/30`,children:(0,V.jsxs)(_O,{className:`w-full max-w-md`,children:[(0,V.jsxs)(vO,{children:[(0,V.jsx)(yO,{children:`Approve agent-admin elevation`}),(0,V.jsx)(bO,{children:`Grants ephemeral deck-admin mode to one MCP session (30-minute lease). This does not change the folder's deck assignment.`})]}),(0,V.jsxs)(xO,{className:`space-y-4`,children:[t&&n?(0,V.jsxs)(`dl`,{className:`text-sm space-y-1 text-muted-foreground`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Session `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:n})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Challenge `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:t})]})]}):null,r===`success`?(0,V.jsx)(`p`,{role:`status`,className:`text-sm text-green-700 dark:text-green-400`,children:a}):r===`error`?(0,V.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a}):null,r!==`success`&&t&&n&&(r!==`error`||s)?(0,V.jsx)(G,{onClick:()=>void l(),disabled:r===`loading`,className:`w-full`,children:r===`loading`?`Approving…`:`Approve elevation`}):null]})]})})}function iH(){return(0,V.jsxs)(xe,{children:[(0,V.jsx)(ve,{path:`/`,component:gO}),(0,V.jsx)(ve,{path:`/oauth/callback`,component:wO}),(0,V.jsx)(ve,{path:`/playbook-patches`,component:$V}),(0,V.jsx)(ve,{path:`/feedback-signals`,component:tH}),(0,V.jsx)(ve,{path:`/admin/approve`,component:rH}),(0,V.jsx)(ve,{path:`/mcp-test`,component:pV}),(0,V.jsx)(ve,{component:CO})]})}function aH(){let[e,t]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{let e=!1;return qt().finally(()=>{e||t(!0)}),()=>{e=!0}},[]),e?(0,V.jsx)(Dt,{client:Kt,children:(0,V.jsxs)(Tl,{children:[(0,V.jsx)(Qa,{}),(0,V.jsx)(iH,{})]})}):(0,V.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-[#0B1220] text-sm text-gray-300`,children:`Loading AgentDeck...`})}(0,x.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(b.StrictMode,{children:(0,V.jsx)(aH,{})}));
|
|
235
|
+
`);return(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[!t&&(0,V.jsxs)(`div`,{className:`rounded-md border border-amber-500/50 bg-amber-500/10 p-3 text-sm text-amber-100`,children:[`No change detected — ops did not alter the playbook body or triggers. Reject this proposal and re-propose with a matching list anchor or `,(0,V.jsx)(`code`,{children:`rewrite_body`}),`.`]}),r&&(0,V.jsx)(`div`,{className:`rounded-md border border-amber-500/50 bg-amber-500/10 p-3 text-sm text-amber-100`,children:`Full-body rewrite proposed — review carefully.`}),i&&(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-400`,children:`Title`}),(0,V.jsxs)(`div`,{className:`${VV} p-0`,children:[e.before.title&&(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-rose-950/70 text-rose-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`-`}),(0,V.jsx)(`span`,{children:e.before.title})]})]}),e.after.title&&(0,V.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[3rem_3rem_minmax(0,1fr)] bg-emerald-950/70 text-emerald-100`,children:[(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsx)(`span`,{className:`border-r border-gray-800/80 px-2 py-0.5`}),(0,V.jsxs)(`div`,{className:`flex gap-2 px-2 py-0.5`,children:[(0,V.jsx)(`span`,{className:`w-3 shrink-0 text-gray-500`,children:`+`}),(0,V.jsx)(`span`,{children:e.after.title})]})]})]})]}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-400`,children:`Body`}),(0,V.jsx)(WV,{rows:n,emptyLabel:`No body changes.`})]}),a&&(0,V.jsx)(GV,{before:e.before.triggers,after:e.after.triggers})]})}function qV(e){if(!e)return[];try{return JSON.parse(e)}catch{return[]}}function JV({conflicts:e,title:t=`Trigger overlap warnings`}){return e.length===0?null:(0,V.jsxs)(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 p-4 text-sm text-amber-50`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-amber-200/90`,children:t}),(0,V.jsx)(`p`,{className:`mt-2 text-amber-100/90`,children:`These triggers overlap with other playbooks on the deck. Accept is still allowed — disambiguate triggers or propose a merge if the wrong playbook keeps firing.`}),(0,V.jsx)(`ul`,{className:`mt-3 space-y-2`,children:e.map(e=>(0,V.jsxs)(`li`,{className:`rounded border border-amber-500/20 bg-gray-950/60 p-3`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(fh,{variant:`outline`,className:`border-amber-400/40 text-amber-100`,children:e.level}),(0,V.jsx)(`span`,{className:`font-medium text-amber-50`,children:e.otherPlaybookTitle}),(0,V.jsx)(`span`,{className:`font-mono text-xs text-amber-200/70`,children:e.otherPlaybookId})]}),(0,V.jsxs)(`p`,{className:`mt-2 text-amber-100/90`,children:[(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Candidate:`}),` `,e.trigger]}),(0,V.jsxs)(`p`,{className:`text-amber-100/80`,children:[(0,V.jsx)(`span`,{className:`text-amber-200/80`,children:`Other:`}),` `,e.otherTrigger]})]},`${e.trigger}-${e.otherPlaybookId}-${e.level}`))})]})}var YV=8,XV=[{value:`proposed`,label:`Waiting`},{value:`accepted`,label:`Accepted`},{value:`rejected`,label:`Rejected`},{value:`superseded`,label:`Superseded`},{value:`stale`,label:`Stale`},{value:`all`,label:`All`}];function ZV(e){if(!e.evidenceJson)return null;try{return JSON.parse(e.evidenceJson)}catch{return null}}function QV(e){switch(e){case`proposed`:return`border-blue-500/40 text-blue-200`;case`accepted`:return`border-emerald-500/40 text-emerald-200`;case`rejected`:return`border-rose-500/40 text-rose-200`;case`superseded`:return`border-violet-500/40 text-violet-200`;case`stale`:return`border-amber-500/40 text-amber-200`}}function $V(){let[e,t]=(0,b.useState)(null),[n,r]=(0,b.useState)(`proposed`),[i,a]=(0,b.useState)(0),{toast:o}=on(),s=Et();function c(e){t(e)}function l(e){r(e),a(0),t(null)}let{data:u=[]}=Vt({queryKey:[`/api/playbook-patches`,`proposed`],queryFn:()=>Xm(`proposed`)}),d=n===`all`?void 0:n,{data:f=[],isLoading:p}=Vt({queryKey:[`/api/playbook-patches`,n],queryFn:()=>Xm(d)}),m=Math.max(1,Math.ceil(f.length/YV)),h=Math.min(i,m-1),g=(0,b.useMemo)(()=>{let e=h*YV;return f.slice(e,e+YV)},[f,h]);(0,b.useEffect)(()=>{i!==h&&a(h)},[i,h]);let{data:_,isLoading:v,isError:y,error:x}=Vt({queryKey:[`/api/playbook-patches`,e,`preview`],queryFn:()=>Zm(e),enabled:!!e}),S=_?mV(_):!1,C=f.find(t=>t.id===e)??null,w=C?.status===`proposed`,T=Ht({mutationFn:e=>Qm(e),onSuccess:()=>{o({title:`Patch accepted`}),t(null),s.invalidateQueries({queryKey:[`/api/playbook-patches`]}),s.invalidateQueries({queryKey:[`/api/playbooks`]}),s.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:e=>{o({title:`Accept failed`,description:e.message,variant:`destructive`})}}),E=Ht({mutationFn:e=>$m(e),onSuccess:()=>{o({title:`Patch rejected`}),t(null),s.invalidateQueries({queryKey:[`/api/playbook-patches`]}),s.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:e=>{o({title:`Reject failed`,description:e.message,variant:`destructive`})}}),D=n===`proposed`?`No proposals waiting for review.`:n===`all`?`No playbook patches yet.`:`No ${n} patches.`;return(0,V.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden bg-gray-950 text-gray-100`,children:[(0,V.jsx)(`header`,{className:`shrink-0 border-b border-gray-800 px-4 py-4 sm:px-6`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-7xl flex-wrap items-center gap-3`,children:[(0,V.jsx)(ye,{href:`/`,children:(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`text-gray-300`,children:[(0,V.jsx)(ui,{className:`mr-1 h-4 w-4`}),(0,V.jsx)(`span`,{className:`font-ui-display`,children:`Deck`})]})}),(0,V.jsx)(`h1`,{className:`font-ui-display text-lg font-semibold`,children:`Playbook review queue`}),(0,V.jsxs)(fh,{variant:`secondary`,children:[u.length,` waiting`]}),(0,V.jsx)(ye,{href:`/feedback-signals`,className:`ml-auto text-sm hover:underline`,style:{color:`#92E4DD`},children:`Feedback data →`})]})}),(0,V.jsxs)(`main`,{className:`mx-auto grid w-full max-w-7xl min-h-0 flex-1 gap-6 overflow-hidden px-4 py-6 sm:px-6 lg:grid-cols-[minmax(18rem,20rem)_minmax(0,1fr)] lg:items-stretch`,children:[(0,V.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-col`,children:[(0,V.jsx)(`h2`,{className:`mb-3 shrink-0 text-sm font-medium text-gray-400`,children:`Proposals`}),(0,V.jsx)(`div`,{className:`mb-3 flex shrink-0 flex-wrap gap-1`,children:XV.map(({value:e,label:t})=>{let r=n===e;return(0,V.jsx)(G,{size:`sm`,variant:r?`gold`:`outline`,className:r?void 0:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800 hover:text-gray-100`,"aria-pressed":r,onClick:()=>l(e),children:t},e)})}),(0,V.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:[p&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading…`}),!p&&f.length===0&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:D}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:g.map(t=>(0,V.jsx)(`li`,{children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>c(t.id),className:`w-full rounded-lg border p-3 text-left transition ${e===t.id?`border-blue-500 bg-gray-900`:`border-gray-800 bg-gray-900/50 hover:border-gray-700`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block font-medium leading-snug`,children:t.kind===`create`?`New: ${t.displayTitle}`:t.displayTitle}),t.playbookId&&t.kind!==`create`&&(0,V.jsx)(`span`,{className:`mt-0.5 block truncate font-mono text-xs text-gray-600`,children:t.playbookId}),Ym(t.deckNames)&&(0,V.jsxs)(`span`,{className:`mt-1 block text-xs text-gray-500`,children:[`Decks: `,Ym(t.deckNames)]})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,V.jsx)(fh,{variant:`outline`,className:`shrink-0`,children:t.kind}),n!==`proposed`&&(0,V.jsx)(fh,{variant:`outline`,className:`shrink-0 ${QV(t.status)}`,children:t.status})]})]}),(0,V.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm text-gray-400`,children:t.rationale}),(0,V.jsxs)(`p`,{className:`mt-1 text-xs text-gray-600`,children:[t.source,` · `,new Date(t.createdAt).toLocaleString()]})]})},t.id))})]}),f.length>YV&&(0,V.jsxs)(`div`,{className:`mt-3 flex shrink-0 items-center justify-between gap-2 border-t border-gray-800 pt-3`,children:[(0,V.jsxs)(G,{type:`button`,size:`sm`,variant:`outline`,className:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800`,disabled:h<=0,onClick:()=>a(e=>Math.max(0,e-1)),children:[(0,V.jsx)(_i,{className:`mr-1 h-4 w-4`}),`Newer`]}),(0,V.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[h+1,` / `,m,(0,V.jsxs)(`span`,{className:`ml-1 text-gray-600`,children:[`(`,f.length,`)`]})]}),(0,V.jsxs)(G,{type:`button`,size:`sm`,variant:`outline`,className:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800`,disabled:h>=m-1,onClick:()=>a(e=>Math.min(m-1,e+1)),children:[`Older`,(0,V.jsx)(vi,{className:`ml-1 h-4 w-4`})]})]})]}),(0,V.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-col overflow-hidden`,children:[(0,V.jsx)(`h2`,{className:`mb-3 shrink-0 text-sm font-medium text-gray-400`,children:`Detail`}),!C&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Select a proposal to preview the diff.`}),C&&(0,V.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-lg border border-gray-800 bg-gray-900/50`,children:[(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4 sm:p-5`,children:(0,V.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(fh,{variant:`outline`,className:QV(C.status),children:C.status}),C.resolvedAt&&(0,V.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`Resolved `,new Date(C.resolvedAt).toLocaleString()]})]}),(0,V.jsx)(`p`,{className:`text-sm leading-relaxed text-gray-300`,children:C.rationale}),C.status===`rejected`&&C.rejectionReason&&(0,V.jsxs)(`div`,{className:`rounded-md border border-rose-500/40 bg-rose-500/10 p-3 text-sm text-rose-100`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-rose-300/80`,children:`Rejection reason`}),(0,V.jsx)(`p`,{className:`mt-1`,children:C.rejectionReason})]}),C.status===`superseded`&&C.supersededBy&&(0,V.jsxs)(`div`,{className:`rounded-md border border-violet-500/40 bg-violet-500/10 p-3 text-sm text-violet-100`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-violet-300/80`,children:`Superseded by`}),(0,V.jsx)(`button`,{type:`button`,className:`mt-1 font-mono text-sm underline-offset-2 hover:underline`,onClick:()=>{let e=C.supersededBy;r(`all`),a(0),c(e)},children:C.supersededBy})]}),(()=>{let e=ZV(C);return e?(0,V.jsxs)(`div`,{className:`rounded-md border border-gray-700 bg-gray-950 p-4 text-sm`,children:[(0,V.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500`,children:`Your correction`}),(0,V.jsxs)(`p`,{className:`mt-2 italic text-gray-200`,children:[`“`,e.user_feedback_excerpt,`”`]}),e.failure_summary&&(0,V.jsx)(`p`,{className:`mt-2 text-gray-400`,children:e.failure_summary})]}):null})(),(()=>{let e=qV(C.conflictsJson),t=_?.trigger_conflicts??[],n=t.length>0?t:e;return(0,V.jsx)(JV,{conflicts:n})})(),v&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading preview…`}),y&&(0,V.jsxs)(`div`,{className:`rounded-md border border-rose-500/50 bg-rose-500/10 p-3 text-sm text-rose-100`,children:[`Preview failed —`,` `,x?.message??`could not apply ops to the current playbook.`,w?` Reject and re-propose with exact list anchors or rewrite_body.`:` Historical preview may be incomplete if the playbook changed.`]}),_&&(0,V.jsx)(KV,{preview:_}),C.status===`stale`&&(0,V.jsx)(`p`,{className:`text-sm text-amber-400`,children:`Stale — playbook changed since proposal. Re-propose from a fresh session.`})]})}),w?(0,V.jsxs)(`div`,{className:`relative z-10 shrink-0 space-y-3 border-t border-gray-800 bg-gray-950 p-4 shadow-[0_-16px_32px_rgba(0,0,0,0.55)] sm:p-5`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-400`,children:`Your decision`}),(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,V.jsx)(G,{variant:`gold`,onClick:()=>T.mutate(C.id),disabled:T.isPending||y||!S,children:`Accept`}),(0,V.jsx)(G,{variant:`destructive`,onClick:()=>E.mutate(C.id),disabled:E.isPending,children:`Reject`})]})]}):(0,V.jsxs)(`div`,{className:`shrink-0 border-t border-gray-800 bg-gray-950 px-4 py-3 text-sm text-gray-500 sm:px-5`,children:[`Read-only — already `,C.status,`. Switch to Waiting to review open proposals.`]})]})]})]})]})}var eH=`border-[#C4B643] data-[state=checked]:bg-[#C4B643] data-[state=checked]:text-[#0A0A07] data-[state=indeterminate]:bg-[#C4B643] data-[state=indeterminate]:text-[#0A0A07]`;function tH(){let{toast:e}=on(),t=Et(),[n,r]=(0,b.useState)(`open`),[i,a]=(0,b.useState)(``),[o,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(new Set),{data:u}=Vt({queryKey:[`/api/playbooks/vault`]}),d=u?.data??[],f=(0,b.useMemo)(()=>{let e=new Map;for(let t of d)e.set(t.id,t.title);return e},[d]),p={status:n===`all`?void 0:n,playbookId:i||void 0,excludeInProposal:n===`open`?!o:void 0},{data:m=[],isLoading:h}=Vt({queryKey:[`/api/feedback-signals`,p],queryFn:()=>rh(p)}),g=Ht({mutationFn:e=>ih(e),onSuccess:n=>{e({title:`Discarded ${n.discarded} signal(s)`}),l(new Set),t.invalidateQueries({queryKey:[`/api/feedback-signals`]})},onError:t=>{e({title:`Discard failed`,description:t.message,variant:`destructive`})}}),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=async()=>{let t=c.size>0?m.filter(e=>c.has(e.id)):m;if(t.length!==0){if(t.some(e=>!e.id)){e({title:`Copy blocked`,description:`Every signal must include an id for tracking.`,variant:`destructive`});return}try{await navigator.clipboard.writeText(ch(t)),e({title:`Copied curation prompt`,description:`${t.length} signal id(s) included — paste into your IDE agent.`})}catch(t){e({title:`Copy failed`,description:t instanceof Error?t.message:`Clipboard unavailable`,variant:`destructive`})}}},y=[...c].filter(e=>m.find(t=>t.id===e)?.status===`open`),x=m.length>0&&m.every(e=>c.has(e.id)),S=m.some(e=>c.has(e.id));return(0,V.jsxs)(`div`,{className:`flex min-h-dvh flex-col bg-gray-950 text-gray-100`,children:[(0,V.jsx)(`header`,{className:`shrink-0 border-b border-gray-800 px-4 py-4 sm:px-6`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-7xl flex-wrap items-center gap-3`,children:[(0,V.jsx)(ye,{href:`/`,children:(0,V.jsxs)(G,{variant:`ghost`,size:`sm`,className:`text-gray-300`,children:[(0,V.jsx)(ui,{className:`mr-1 h-4 w-4`}),`Home`]})}),(0,V.jsx)(`h1`,{className:`font-ui-display text-lg font-semibold`,children:`Feedback`}),(0,V.jsx)(fh,{variant:`outline`,children:m.length}),(0,V.jsx)(ye,{href:`/playbook-patches`,className:`ml-auto text-sm hover:underline`,style:{color:`#92E4DD`},children:`Playbook proposals →`})]})}),(0,V.jsxs)(`main`,{className:`mx-auto w-full max-w-7xl flex-1 space-y-4 px-4 py-6 sm:px-6`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-400`,children:`Durable correction data for playbook enhancement. Filter by playbook, copy rows (with ids) for an IDE agent to propose, then accept the proposal to mark feedback solved.`}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3 rounded-lg border border-gray-800 bg-gray-900/40 p-3`,children:[(0,V.jsxs)(`label`,{className:`text-xs text-gray-500`,children:[`Playbook`,(0,V.jsxs)(`select`,{className:`mt-1 block min-w-[12rem] rounded border border-gray-700 bg-gray-950 px-2 py-1.5 text-sm text-gray-100`,value:i,onChange:e=>{a(e.target.value),l(new Set)},children:[(0,V.jsx)(`option`,{value:``,children:`All`}),d.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:[[`open`,`Open`],[`actioned`,`Actioned`],[`discarded`,`Discarded`],[`all`,`All`]].map(([e,t])=>{let i=n===e;return(0,V.jsx)(G,{size:`sm`,variant:i?`gold`:`outline`,className:i?void 0:`border-gray-600 bg-transparent text-gray-300 hover:bg-gray-800 hover:text-gray-100`,"aria-pressed":i,onClick:()=>{r(e),l(new Set)},children:t},e)})}),n===`open`&&(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-400`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Include already in an open proposal`]}),(0,V.jsxs)(`div`,{className:`ml-auto flex flex-wrap gap-2`,children:[(0,V.jsxs)(G,{size:`sm`,variant:`outline`,disabled:m.length===0,onClick:()=>void v(),children:[(0,V.jsx)(wi,{className:`mr-1 h-3.5 w-3.5`}),`Copy for agent`,c.size>0?` (${c.size})`:``]}),(0,V.jsxs)(G,{size:`sm`,variant:`destructive`,disabled:y.length===0||g.isPending,onClick:()=>g.mutate(y),children:[(0,V.jsx)(Hi,{className:`mr-1 h-3.5 w-3.5`}),`Discard selected`]})]})]}),h&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Loading…`}),!h&&m.length===0&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500`,children:`No signals match these filters.`}),!h&&m.length>0&&(0,V.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-gray-800`,children:(0,V.jsxs)(`table`,{className:`w-full min-w-[48rem] text-left text-sm`,children:[(0,V.jsx)(`thead`,{className:`border-b border-gray-800 bg-gray-900/80 text-xs uppercase text-gray-500`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`w-10 px-3 py-2`,children:(0,V.jsx)(cg,{checked:x?!0:S?`indeterminate`:!1,onCheckedChange:()=>{if(x){l(new Set);return}l(new Set(m.map(e=>e.id)))},"aria-label":`Select all visible signals`,disabled:m.length===0,className:eH})}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Excerpt`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Failure`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Playbook`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`Source`}),(0,V.jsx)(`th`,{className:`px-3 py-2`,children:`When`})]})}),(0,V.jsx)(`tbody`,{children:m.map(e=>{let t=ah(e);return(0,V.jsxs)(`tr`,{className:`border-b border-gray-800/80 align-top`,children:[(0,V.jsx)(`td`,{className:`px-3 py-2`,children:(0,V.jsx)(cg,{checked:c.has(e.id),onCheckedChange:()=>_(e.id),"aria-label":`Select ${e.id}`,className:eH})}),(0,V.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,V.jsx)(`p`,{className:`font-mono text-[11px] text-gray-600`,children:e.id}),(0,V.jsxs)(`p`,{className:`text-gray-200`,children:[`“`,e.userFeedbackExcerpt,`”`]}),t&&(0,V.jsx)(fh,{variant:`outline`,className:`mt-1 text-[10px]`,children:`In proposal`})]}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-400`,children:e.failureSummary}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-300`,children:e.candidatePlaybookId?f.get(e.candidatePlaybookId)??e.candidatePlaybookId:`—`}),(0,V.jsx)(`td`,{className:`px-3 py-2 text-gray-500`,children:e.source}),(0,V.jsx)(`td`,{className:`px-3 py-2 whitespace-nowrap text-gray-500`,children:new Date(e.createdAt).toLocaleString()})]},e.id)})})]})})]})]})}function nH(e){return e instanceof Ut?e.errorCode===`GRANT_REQUIRED`||e.errorCode===`DASHBOARD_REQUIRED`?{message:`This browser is not signed in to the Agent Deck dashboard. Run agent-deck open, then open this approval link again.`,retryable:!0}:e.errorCode===`ADMIN_CHALLENGE_EXPIRED`?{message:`This approval request expired or was already used. Ask the agent to request admin elevation again.`,retryable:!1}:e.errorCode===`SESSION_INVALID`?{message:`The agent session for this request is gone. Ask the agent to reconnect and request admin elevation again.`,retryable:!1}:{message:e.message||`Approval failed`,retryable:!0}:e instanceof TypeError?{message:`Could not reach Agent Deck. Check that it is running (agent-deck status) and try again.`,retryable:!0}:{message:e instanceof Error&&e.message?e.message:`Approval failed`,retryable:!0}}function rH(){let e=new URLSearchParams(window.location.search),t=e.get(`challenge`)??``,n=e.get(`session`)??``,[r,i]=(0,b.useState)(`idle`),[a,o]=(0,b.useState)(``),[s,c]=(0,b.useState)(!0);(0,b.useEffect)(()=>{(!t||!n)&&(i(`error`),c(!1),o(`This link is incomplete. Ask the agent to request admin elevation again.`))},[t,n]);async function l(){if(t&&n){i(`loading`);try{await H(`POST`,`/api/trusted-session/admin/approve`,{challengeId:t,runtimeSessionId:n}),i(`success`),o(`Admin elevation approved for this MCP session. Return to the agent.`)}catch(e){let t=nH(e);i(`error`),c(t.retryable),o(t.message)}}}return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-6 bg-muted/30`,children:(0,V.jsxs)(_O,{className:`w-full max-w-md`,children:[(0,V.jsxs)(vO,{children:[(0,V.jsx)(yO,{children:`Approve agent-admin elevation`}),(0,V.jsx)(bO,{children:`Grants ephemeral deck-admin mode to one MCP session (30-minute lease). This does not change the folder's deck assignment.`})]}),(0,V.jsxs)(xO,{className:`space-y-4`,children:[t&&n?(0,V.jsxs)(`dl`,{className:`text-sm space-y-1 text-muted-foreground`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Session `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:n})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Challenge `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:t})]})]}):null,r===`success`?(0,V.jsx)(`p`,{role:`status`,className:`text-sm text-green-700 dark:text-green-400`,children:a}):r===`error`?(0,V.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:a}):null,r!==`success`&&t&&n&&(r!==`error`||s)?(0,V.jsx)(G,{onClick:()=>void l(),disabled:r===`loading`,className:`w-full`,children:r===`loading`?`Approving…`:`Approve elevation`}):null]})]})})}function iH(e){return e instanceof Ut?e.errorCode===`GRANT_REQUIRED`||e.errorCode===`DASHBOARD_REQUIRED`?{message:`This browser is not signed in to the Agent Deck dashboard. Run agent-deck open, then open this approval link again.`,retryable:!0}:e.errorCode===`DECK_SWITCH_EXPIRED`||e.status===410?{message:`This deck-switch request expired. The session and workspace default were not changed. Ask the agent to request the switch again.`,retryable:!1}:e.errorCode===`DECK_SWITCH_CONSUMED`||e.status===409?{message:`This deck-switch request was already resolved. The switch was not applied twice — check the current deck before requesting again.`,retryable:!1}:e.errorCode===`RESOURCE_OUT_OF_SCOPE`?{message:`This approval link does not match the requesting session. Only the matching session's request can be approved here — ask the agent for a fresh link if needed.`,retryable:!1}:e.errorCode===`SESSION_INVALID`?{message:`The agent session for this request is gone. Ask the agent to reconnect and request the deck switch again.`,retryable:!1}:e.status===404?{message:`This deck-switch request was not found. It may have been cleaned up. Ask the agent to request the switch again.`,retryable:!1}:{message:e.message||`Approval failed`,retryable:!0}:e instanceof TypeError?{message:`Could not reach Agent Deck. Check that it is running (agent-deck status) and try again.`,retryable:!0}:{message:e instanceof Error&&e.message?e.message:`Approval failed`,retryable:!0}}function aH(){let e=new URLSearchParams(window.location.search);return{requestId:(e.get(`request`)??e.get(`requestId`)??``).trim(),runtimeSessionId:(e.get(`session`)??e.get(`runtimeSessionId`)??``).trim()}}function oH(e){return e===`expired`?`This deck-switch request expired. The session and workspace default were not changed. Ask the agent to request the switch again.`:e===`declined`?`This deck-switch request was already declined. Nothing was changed.`:`This deck-switch request was already resolved. The switch was not applied twice — check the current deck before requesting again.`}function sH(e){let t=e.deckName?` “${e.deckName}”`:``;return e.decision===`session`?`Approved for this session only. This session now uses${t}. The workspace default was not changed.`:e.decision===`workspace-default`?`Approved. Future sessions${e.workspaceRoot?` in ${e.workspaceRoot}`:``} will use${t} as the new default. This session was switched too.`:`Declined. Nothing was changed — the session and workspace default are untouched.`}function cH(){let[{requestId:e,runtimeSessionId:t}]=(0,b.useState)(aH),[n,r]=(0,b.useState)(`loading`),[i,a]=(0,b.useState)(null),[o,s]=(0,b.useState)(``),[c,l]=(0,b.useState)(!0),[u,d]=(0,b.useState)(null),f=(0,b.useRef)(!1),p=(0,b.useCallback)(async()=>{if(!e){r(`error`),l(!1),s(`This link is incomplete. Ask the agent to request the deck switch again.`);return}r(`loading`),s(``);try{let t=(await(await H(`GET`,`/api/trusted-session/deck-switch/${e}`)).json()).data;if(!t||t.requestId!==e)throw Error(`Approval lookup returned an unexpected response`);a(t),t.status===`pending`?r(`pending`):(r(`error`),l(!1),s(oH(t.status)))}catch(e){let t=iH(e);r(`error`),l(t.retryable),s(t.message)}},[e]);(0,b.useEffect)(()=>{p()},[p]);async function m(n){if(f.current)return;let a=t||i?.runtimeSessionId||``;if(!e||!a){r(`error`),l(!1),s(`This link is incomplete. Ask the agent to request the deck switch again.`);return}f.current=!0,d(n),r(`submitting`);try{let t=await(await H(`POST`,`/api/trusted-session/deck-switch/${e}/resolve`,{runtimeSessionId:a,decision:n})).json(),o={decision:n,deckName:t.data?.deckName??i?.requestedDeckName,workspaceRoot:t.data?.workspaceRoot??i?.workspaceRoot};s(sH(o)),r(`success`)}catch(e){let t=iH(e);l(t.retryable),s(t.message),t.retryable&&i?r(`pending`):r(`error`)}finally{f.current=!1,d(null)}}function h(){s(``),i&&c?r(`pending`):p()}let g=n===`loading`||n===`submitting`,_=i?.currentDeckName??i?.currentDeckId,v=i?.requestedDeckName??i?.requestedDeckId,y=t||i?.runtimeSessionId;return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-6 bg-muted/30`,children:(0,V.jsxs)(_O,{className:`w-full max-w-md`,children:[(0,V.jsxs)(vO,{children:[(0,V.jsx)(yO,{children:`Approve deck switch`}),(0,V.jsx)(bO,{children:`Choose whether the requested deck applies to this session only or becomes the workspace default. Declining leaves everything unchanged.`})]}),(0,V.jsxs)(xO,{className:`space-y-4`,children:[i&&(_||v)?(0,V.jsxs)(`dl`,{className:`text-sm space-y-1 text-muted-foreground`,children:[_?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Current deck `}),(0,V.jsx)(`dd`,{className:`inline`,children:_})]}):null,v?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Requested deck `}),(0,V.jsx)(`dd`,{className:`inline`,children:v})]}):null,i.workspaceRoot?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Workspace `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:i.workspaceRoot})]}):null,y?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`inline font-medium text-foreground`,children:`Session `}),(0,V.jsx)(`dd`,{className:`inline font-mono text-xs`,children:y})]}):null]}):e?(0,V.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Request `,(0,V.jsx)(`span`,{className:`font-mono text-xs`,children:e})]}):null,n===`loading`?(0,V.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading the deck-switch request…`}):null,n===`success`?(0,V.jsx)(`p`,{role:`status`,className:`text-sm text-green-700 dark:text-green-400`,children:o}):null,(n===`error`||n===`pending`)&&o?(0,V.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:o}):null,(n===`pending`||n===`submitting`)&&i?(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(G,{onClick:()=>void m(`session`),disabled:g,className:`w-full`,children:u===`session`?`Approving…`:`This session only`}),(0,V.jsx)(G,{onClick:()=>void m(`workspace-default`),disabled:g,variant:`secondary`,className:`w-full`,children:u===`workspace-default`?`Approving…`:`This workspace by default`}),(0,V.jsx)(G,{onClick:()=>void m(`decline`),disabled:g,variant:`outline`,className:`w-full`,children:u===`decline`?`Declining…`:`Decline`})]}):null,n===`error`?c?(0,V.jsx)(G,{onClick:h,variant:`outline`,className:`w-full`,children:`Try again`}):(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No further action is possible on this link. You can close this tab.`}):null,n===`success`?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You can close this tab and return to the agent.`}):null]})]})})}function lH(){return(0,V.jsxs)(xe,{children:[(0,V.jsx)(ve,{path:`/`,component:gO}),(0,V.jsx)(ve,{path:`/oauth/callback`,component:wO}),(0,V.jsx)(ve,{path:`/playbook-patches`,component:$V}),(0,V.jsx)(ve,{path:`/feedback-signals`,component:tH}),(0,V.jsx)(ve,{path:`/admin/approve`,component:rH}),(0,V.jsx)(ve,{path:`/deck-switch/approve`,component:cH}),(0,V.jsx)(ve,{path:`/mcp-test`,component:pV}),(0,V.jsx)(ve,{component:CO})]})}function uH(){let[e,t]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{let e=!1;return qt().finally(()=>{e||t(!0)}),()=>{e=!0}},[]),e?(0,V.jsx)(Dt,{client:Kt,children:(0,V.jsxs)(Tl,{children:[(0,V.jsx)(Qa,{}),(0,V.jsx)(lH,{})]})}):(0,V.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-[#0B1220] text-sm text-gray-300`,children:`Loading AgentDeck...`})}(0,x.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(b.StrictMode,{children:(0,V.jsx)(uH,{})}));
|