import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{c as r,l as i}from"./vendor-react-Cts2Wj-s.js";import{$ as a,Q as o,X as s,at as c,d as l,f as u,h as d,i as f,l as p,nt as m,p as h,pt as g,rt as _,s as v,u as y}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{ot as b,st as x,t as S}from"./vendor-mui-icons-606Bohdn.js";import{_ as C,h as w,i as T,p as E,s as D,v as O}from"./ui-BLXHSX1T.js";import{n as k}from"./help-DeFmOHyq.js";import{n as A,t as j}from"./api-DOzDCdFb.js";var M=e(n(),1),N=t(),P={docs:`primary`,code:`success`,knowledge:`warning`,tasks:`neutral`,skills:`primary`,files:`neutral`,context:`neutral`,"cross-graph":`error`};function F(e){let t={},n=e.inputSchema?.properties||{};for(let[e,r]of Object.entries(n))r.default===void 0?t[e]=``:t[e]=String(r.default);return t}function I(e,t){let n=e.trim();if(n!==``){if(t.type===`number`||t.type===`integer`){let e=Number(n);return isNaN(e)?void 0:e}if(t.type===`boolean`)return n===`true`;if(t.type===`array`)try{return JSON.parse(n)}catch{return n.split(`,`).map(e=>e.trim()).filter(Boolean)}if(t.type===`object`)try{return JSON.parse(n)}catch{return}return n}}function L(e){return e.enum?e.enum.join(` | `):e.type===`array`&&e.items?.type?`${e.items.type}[]`:e.type||`any`}function R(){let{projectId:e,toolName:t}=i(),n=r(),{palette:R}=g(),[z,B]=(0,M.useState)(null),[V,H]=(0,M.useState)(!0),[U,W]=(0,M.useState)({}),[G,K]=(0,M.useState)(!1),[q,J]=(0,M.useState)(null);(0,M.useEffect)(()=>{!e||!t||(H(!0),A(e,t).then(e=>{B(e),W(F(e))}).finally(()=>H(!1)))},[e,t]);let Y=(0,M.useCallback)(async()=>{if(!(!e||!t||!z)){K(!0),J(null);try{let n=z.inputSchema?.properties||{},r={};for(let[e,t]of Object.entries(U)){let i=I(t,n[e]||{});i!==void 0&&(r[e]=i)}J(await j(e,t,r))}catch(e){J({result:[{type:`text`,text:e instanceof Error?e.message:`Unknown error`}],isError:!0,duration:0})}finally{K(!1)}}},[e,t,z,U]);if(V)return(0,N.jsx)(o,{sx:{display:`flex`,justifyContent:`center`,py:8},children:(0,N.jsx)(c,{})});if(!z)return(0,N.jsx)(T,{icon:(0,N.jsx)(x,{}),title:`Tool not found`});let X=z.inputSchema?.properties||{},Z=new Set(z.inputSchema?.required||[]),Q=q?q.result.map(e=>e.text||``).join(`
`):``,$=Q;try{$=JSON.stringify(JSON.parse(Q),null,2)}catch{}return(0,N.jsxs)(o,{children:[(0,N.jsx)(E,{breadcrumbs:[{label:`Tools`,to:`/${e}/tools`},{label:z.name}]}),(0,N.jsxs)(o,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,N.jsx)(O,{title:`Info`,children:(0,N.jsxs)(o,{sx:{display:`flex`,flexDirection:`column`,gap:1.5},children:[(0,N.jsxs)(o,{sx:{display:`flex`,alignItems:`center`,gap:1.5},children:[(0,N.jsx)(m,{variant:`h6`,fontWeight:700,sx:{fontFamily:`monospace`},children:z.name}),(0,N.jsx)(C,{label:z.category,color:P[z.category]||`neutral`}),(0,N.jsx)(w,{value:z.name})]}),(0,N.jsx)(m,{variant:`body2`,sx:{color:R.custom.textMuted},children:z.description})]})}),(0,N.jsx)(O,{title:`Parameters (${Object.keys(X).length})`,children:Object.keys(X).length===0?(0,N.jsx)(m,{variant:`body2`,sx:{color:R.custom.textMuted},children:`This tool takes no parameters.`}):(0,N.jsx)(y,{children:(0,N.jsxs)(h,{size:`small`,children:[(0,N.jsx)(p,{children:(0,N.jsxs)(v,{children:[(0,N.jsx)(l,{children:`Name`}),(0,N.jsx)(l,{children:`Type`}),(0,N.jsx)(l,{children:`Required`}),(0,N.jsx)(l,{children:`Description`})]})}),(0,N.jsx)(u,{children:Object.entries(X).map(([e,t])=>(0,N.jsxs)(v,{children:[(0,N.jsx)(l,{children:(0,N.jsx)(m,{variant:`body2`,sx:{fontFamily:`monospace`,fontWeight:600},children:e})}),(0,N.jsx)(l,{children:(0,N.jsx)(a,{label:L(t),size:`small`,variant:`outlined`})}),(0,N.jsx)(l,{children:Z.has(e)?(0,N.jsx)(m,{variant:`body2`,color:`error`,fontWeight:600,children:`Yes`}):(0,N.jsx)(m,{variant:`body2`,sx:{color:R.custom.textMuted},children:`No`})}),(0,N.jsx)(l,{children:(0,N.jsx)(m,{variant:`body2`,sx:{color:R.custom.textMuted},children:t.description||`-`})})]},e))})]})})}),(0,N.jsx)(O,{title:`Playground`,action:(0,N.jsx)(s,{variant:`contained`,size:`small`,startIcon:G?(0,N.jsx)(c,{size:16,color:`inherit`}):(0,N.jsx)(S,{}),onClick:Y,disabled:G,children:G?`Running...`:`Execute`}),children:(0,N.jsx)(o,{sx:{display:`flex`,flexDirection:`column`,gap:1.5},children:Object.keys(X).length===0?(0,N.jsx)(m,{variant:`body2`,sx:{color:R.custom.textMuted},children:`No parameters required. Click Execute to run.`}):Object.entries(X).map(([e,t])=>{if(t.type===`boolean`)return(0,N.jsxs)(o,{children:[(0,N.jsx)(D,{children:e}),(0,N.jsx)(d,{checked:U[e]===`true`,onChange:t=>W(n=>({...n,[e]:String(t.target.checked)})),size:`small`})]},e);let n=t.type===`array`||t.type===`object`||e===`content`||e===`description`;return(0,N.jsxs)(o,{children:[(0,N.jsx)(D,{required:Z.has(e),children:e}),(0,N.jsx)(f,{value:U[e]||``,onChange:t=>W(n=>({...n,[e]:t.target.value})),size:`small`,fullWidth:!0,multiline:n,minRows:n?2:void 0,helperText:t.description,placeholder:t.enum?t.enum.join(` | `):t.type===`array`?`["item1", "item2"] or item1, item2`:t.type===`number`||t.type===`integer`?`0`:void 0,slotProps:{input:{sx:{fontFamily:`monospace`,fontSize:`0.875rem`}}}})]},e)})})}),q&&(0,N.jsxs)(O,{title:`Response`,action:(0,N.jsxs)(o,{sx:{display:`flex`,alignItems:`center`,gap:1.5},children:[(0,N.jsxs)(m,{variant:`caption`,sx:{color:R.custom.textMuted},children:[q.duration,`ms`]}),Q&&(0,N.jsx)(w,{value:$})]}),children:[q.isError&&(0,N.jsx)(_,{severity:`error`,sx:{mb:1.5},children:`Tool returned an error`}),(0,N.jsx)(o,{component:`pre`,sx:{m:0,p:1.5,bgcolor:R.custom.surfaceMuted,borderRadius:1,overflow:`auto`,maxHeight:500,fontFamily:`monospace`,fontSize:`0.8125rem`,lineHeight:1.5,whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:$||`(empty response)`})]}),t&&k(t).length>0&&(0,N.jsx)(O,{title:`Related Guides`,children:(0,N.jsx)(o,{sx:{display:`flex`,flexWrap:`wrap`,gap:1},children:k(t).map(t=>(0,N.jsx)(a,{icon:(0,N.jsx)(b,{}),label:t.title,size:`small`,variant:`outlined`,clickable:!0,onClick:()=>n(`/${e}/help/${t.id}`)},t.id))})})]})]})}export{R as default};