1import{X as _,Y as C,Z as P,_ as w,r as n,j as e,K as k,$ as i,B as u,a0 as c,a1 as T}from"./index-KkoT--wm.js";import{T as j}from"./textarea-Z1pEoW_D.js";import{S as E}from"./switch-7Cwm30HW.js";import{S as A,a as I,b as L,c as O,d as V,e as B,f as R}from"./select-K_8a4ryX.js";import{e as U,S as D}from"./aiCost-TxmD82Wi.js";import{P as g}from"./PageContainer-Bxab-5a3.js";import{S as M}from"./save-CIZE3nGU.js";import{P as F}from"./play-BXnzWYBL.js";import"./index-CnIxGKKI.js";import"./index-BdQq_4o_.js";import"./arrow-left-CpRyp-pH.js";function W(){const{id:l}=_(),{data:v=[]}=C(),p=P(),m=w(),a=v.find(s=>s.id===l),[r,o]=n.useState({name:"",description:"",category:"",model:"google/gemini-3-flash-preview",system_prompt:"",prompt_template:"",is_active:!0}),[d,f]=n.useState({}),[x,y]=n.useState("");n.useEffect(()=>{a&&o({name:a.name,description:a.description??"",category:a.category??"",model:a.model,system_prompt:a.system_prompt,prompt_template:a.prompt_template,is_active:a.is_active})},[a==null?void 0:a.id]);const h=n.useMemo(()=>U(r.system_prompt,r.prompt_template),[r.system_prompt,r.prompt_template]),N=()=>{l&&p.mutate({id:l,...r,description:r.description||null,category:r.category||null})},S=async()=>{if(a)try{const s=await m.mutateAsync({promptName:a.name,variables:d});y(typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(s,null,2))}catch(s){T.error(s instanceof Error?s.message:"Test failed")}};return a?e.jsxs(g,{backTo:"/admin/ai/prompts",backLabel:"Back to prompts",title:a.name,description:a.description??"Edit prompt template, model and variables.",action:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(E,{checked:r.is_active,onCheckedChange:s=>o(t=>({...t,is_active:s}))}),e.jsx(i,{className:"text-sm",children:"Active"})]}),e.jsxs(u,{onClick:N,disabled:p.isPending,children:[e.jsx(M,{className:"mr-2 h-4 w-4"})," Save"]})]}),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Name"}),e.jsx(c,{value:r.name,onChange:s=>o(t=>({...t,name:s.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Category"}),e.jsx(c,{value:r.category,onChange:s=>o(t=>({...t,category:s.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Description"}),e.jsx(c,{value:r.description,onChange:s=>o(t=>({...t,description:s.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"Model"}),e.jsxs(A,{value:r.model,onValueChange:s=>o(t=>({...t,model:s})),children:[e.jsx(I,{children:e.jsx(L,{})}),e.jsx(O,{children:D.map(s=>e.jsxs(V,{children:[e.jsx(B,{children:s.label}),s.models.map(t=>e.jsx(R,{value:t.id,children:t.name},t.id))]},s.provider))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"System prompt"}),e.jsx(j,{value:r.system_prompt,onChange:s=>o(t=>({...t,system_prompt:s.target.value})),rows:4,className:"font-mono text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:"User prompt template"}),e.jsx(j,{value:r.prompt_template,onChange:s=>o(t=>({...t,prompt_template:s.target.value})),rows:8,className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Use ",e.jsx("code",{children:"{{variable}}"})," placeholders."]})]}),e.jsxs("div",{className:"rounded-md border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Test run"}),e.jsxs(u,{size:"sm",onClick:S,disabled:m.isPending,children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),m.isPending?"Runningâ¦":"Run test"]})]}),h.length>0?e.jsx("div",{className:"space-y-2",children:h.map(s=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(i,{className:"text-xs",children:s}),e.jsx(c,{value:d[s]??"",onChange:t=>f(b=>({...b,[s]:t.target.value})),placeholder:`Value for {{${s}}}`})]},s))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No variables in this prompt."}),x&&e.jsxs("div",{children:[e.jsx(i,{className:"text-xs",children:"Output"}),e.jsx("pre",{className:"mt-1 max-h-80 overflow-auto rounded bg-muted p-3 text-xs whitespace-pre-wrap",children:x})]})]})]}):e.jsx(g,{backTo:"/admin/ai/prompts",backLabel:"Back to prompts",children:e.jsx(k,{})})}
1export{W as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.