import{j as e,i as r,r as Ie,t as Le,w as ie,z as Ce}from"./vendor-ui-BUsIib4b.js";import{r as t,u as de}from"./vendor-react-C0ZmnAiH.js";import{p as ke,O as Ne,y as Pe,s as ae,v as Te,J as De,P as W,B as H}from"./index-ccpu5IUx.js";import{o as D}from"./Circle.es-BgVv0ZAg.js";import{s as Ze,o as oe}from"./FileText.es-BWetNRZf.js";import{u as Re,S as Ue,o as ce}from"./secrets_box-DVizgAYL.js";import{e as Oe}from"./Plus.es-Wcn0FiuG.js";import{e as me}from"./Question.es-38Jktdxv.js";import{b as _e,u as Be}from"./header-BxYiJFj2.js";import{c as qe,u as K,a as Y}from"./vendor-query-CD5rVjAu.js";import{A as pe,b as X,u as Q}from"./vendor-utils-DwtcRXMR.js";import{s as We,o as ue}from"./XCircle.es-BU2UFlpm.js";import{C as he}from"./use_metric-JQcwAm9V.js";import{s as Ke}from"./CloudArrowUp.es-BmQ-p2fP.js";import{U as re}from"./index-C_2p6STl.js";import{u as Qe}from"./use_show_toast-CuYK1CaH.js";import{T as Ve,a as xe,b as fe,c as ge}from"./tooltip-bxA1RoBu.js";import{E as Ge}from"./endpoint_box-0yzcR_7l.js";import{U as Je}from"./index-CvNY0Ztw.js";const Ye=new Map([["bold",t.createElement(t.Fragment,null,t.createElement("path",{d:"M248.23,112.31A20,20,0,0,0,232,104H220V88a20,20,0,0,0-20-20H132L105.34,48a20.12,20.12,0,0,0-12-4H40A20,20,0,0,0,20,64V208a12,12,0,0,0,12,12H211.1a12,12,0,0,0,11.33-8l28.49-81.47.06-.17A20,20,0,0,0,248.23,112.31ZM92,68l28.8,21.6A12,12,0,0,0,128,92h68v12H69.77a20,20,0,0,0-18.94,13.58L44,137.15V68ZM202.59,196H48.89l23.72-68H226.37Z"}))],["duotone",t.createElement(t.Fragment,null,t.createElement("path",{d:"M208,88v24H69.77a8,8,0,0,0-7.59,5.47L32,208V64a8,8,0,0,1,8-8H93.33a8,8,0,0,1,4.8,1.6L128,80h72A8,8,0,0,1,208,88Z",opacity:"0.2"}),t.createElement("path",{d:"M245,110.64A16,16,0,0,0,232,104H216V88a16,16,0,0,0-16-16H130.67L102.94,51.2a16.14,16.14,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V208a8,8,0,0,0,8,8H211.1a8,8,0,0,0,7.59-5.47l28.49-85.47A16.05,16.05,0,0,0,245,110.64ZM93.34,64,123.2,86.4A8,8,0,0,0,128,88h72v16H69.77a16,16,0,0,0-15.18,10.94L40,158.7V64Zm112,136H43.1l26.67-80H232Z"}))],["fill",t.createElement(t.Fragment,null,t.createElement("path",{d:"M245,110.64A16,16,0,0,0,232,104H216V88a16,16,0,0,0-16-16H130.67L102.94,51.2a16.14,16.14,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V208h0a8,8,0,0,0,8,8H211.1a8,8,0,0,0,7.59-5.47l28.49-85.47A16.05,16.05,0,0,0,245,110.64ZM93.34,64,123.2,86.4A8,8,0,0,0,128,88h72v16H69.77a16,16,0,0,0-15.18,10.94L40,158.7V64Z"}))],["light",t.createElement(t.Fragment,null,t.createElement("path",{d:"M243.36,111.81A14,14,0,0,0,232,106H214V88a14,14,0,0,0-14-14H130L101.74,52.8a14.06,14.06,0,0,0-8.4-2.8H40A14,14,0,0,0,26,64V208a6,6,0,0,0,6,6H211.1a6,6,0,0,0,5.69-4.1l28.49-85.47A14,14,0,0,0,243.36,111.81ZM40,62H93.34a2,2,0,0,1,1.2.4L124.4,84.8A6,6,0,0,0,128,86h72a2,2,0,0,1,2,2v18H69.77a14,14,0,0,0-13.28,9.57L38,171V64A2,2,0,0,1,40,62Zm193.9,58.63L206.78,202H40.33l27.54-82.63a2,2,0,0,1,1.9-1.37H232a2,2,0,0,1,1.9,2.63Z"}))],["regular",t.createElement(t.Fragment,null,t.createElement("path",{d:"M245,110.64A16,16,0,0,0,232,104H216V88a16,16,0,0,0-16-16H130.67L102.94,51.2a16.14,16.14,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V208h0a8,8,0,0,0,8,8H211.1a8,8,0,0,0,7.59-5.47l28.49-85.47A16.05,16.05,0,0,0,245,110.64ZM93.34,64,123.2,86.4A8,8,0,0,0,128,88h72v16H69.77a16,16,0,0,0-15.18,10.94L40,158.7V64Zm112,136H43.1l26.67-80H232Z"}))],["thin",t.createElement(t.Fragment,null,t.createElement("path",{d:"M241.72,113a11.88,11.88,0,0,0-9.73-5H212V88a12,12,0,0,0-12-12H129.33l-28.8-21.6a12.05,12.05,0,0,0-7.2-2.4H40A12,12,0,0,0,28,64V208a4,4,0,0,0,4,4H211.09a4,4,0,0,0,3.79-2.74l28.49-85.47A11.86,11.86,0,0,0,241.72,113ZM40,60H93.33a4,4,0,0,1,2.4.8L125.6,83.2a4,4,0,0,0,2.4.8h72a4,4,0,0,1,4,4v20H69.76a12,12,0,0,0-11.38,8.21L36,183.35V64A4,4,0,0,1,40,60Zm195.78,61.26L208.2,204H37.55L66,118.74A4,4,0,0,1,69.76,116H232a4,4,0,0,1,3.79,5.26Z"}))]]),Xe=new Map([["bold",t.createElement(t.Fragment,null,t.createElement("path",{d:"M152,92a36,36,0,1,0-36-36A36,36,0,0,0,152,92Zm0-48a12,12,0,1,1-12,12A12,12,0,0,1,152,44Zm76,93.4a12,12,0,0,1-7,10.91,66,66,0,0,1-21.47,3.78c-14,0-34.25-3.82-59.77-19a177,177,0,0,1-10.27,21C153.12,162.83,188,183.8,188,232a12,12,0,0,1-24,0c0-18.69-6.95-33.06-21.26-43.94-9.16-7-19.55-11-27.43-13.34-.81,1-1.64,2-2.5,2.95-20,22.87-44.82,34.76-72.25,34.76a97.33,97.33,0,0,1-9.75-.49,12,12,0,1,1,2.39-23.88c52.3,5.22,77.48-45.92,85.79-67.75C84.8,102.46,63.74,118.78,63.51,119a12,12,0,0,1-15-18.72C50.08,99,88,69.44,142.75,106.62c43.1,29.31,68.1,19.92,68.5,19.76a12,12,0,0,1,16.75,11Z"}))],["duotone",t.createElement(t.Fragment,null,t.createElement("path",{d:"M176,56a24,24,0,1,1-24-24A24,24,0,0,1,176,56Z",opacity:"0.2"}),t.createElement("path",{d:"M152,88a32,32,0,1,0-32-32A32,32,0,0,0,152,88Zm0-48a16,16,0,1,1-16,16A16,16,0,0,1,152,40Zm67.31,100.68c-.61.28-7.49,3.28-19.67,3.28-13.85,0-34.55-3.88-60.69-20a169.31,169.31,0,0,1-15.41,32.34,104.29,104.29,0,0,1,31.31,15.81C173.92,186.65,184,207.35,184,232a8,8,0,0,1-16,0c0-41.7-34.69-56.71-54.14-61.85-.55.7-1.12,1.41-1.69,2.1-19.64,23.8-44.25,36.18-71.63,36.18A92.29,92.29,0,0,1,31.2,208,8,8,0,0,1,32.8,192c25.92,2.59,48.47-7.49,67-30,12.49-15.14,21-33.61,25.25-47C86.13,92.34,61.27,111.63,61,111.84A8,8,0,1,1,51,99.36c1.5-1.2,37.22-29,89.51,6.57,45.47,30.91,71.93,20.31,72.18,20.19a8,8,0,1,1,6.63,14.56Z"}))],["fill",t.createElement(t.Fragment,null,t.createElement("path",{d:"M120,56a32,32,0,1,1,32,32A32,32,0,0,1,120,56Zm103.28,74.08a8,8,0,0,0-10.6-4c-.25.12-26.71,10.72-72.18-20.19-52.29-35.54-88-7.77-89.51-6.57a8,8,0,1,0,10,12.48c.26-.21,25.12-19.5,64.07,3.27-4.25,13.35-12.76,31.82-25.25,47-18.56,22.48-41.11,32.56-67,30A8,8,0,0,0,31.2,208a92.29,92.29,0,0,0,9.34.47c27.38,0,52-12.38,71.63-36.18.57-.69,1.14-1.4,1.69-2.1C133.31,175.29,168,190.3,168,232a8,8,0,0,0,16,0c0-24.65-10.08-45.35-29.15-59.86a104.29,104.29,0,0,0-31.31-15.81A169.31,169.31,0,0,0,139,124c26.14,16.09,46.84,20,60.69,20,12.18,0,19.06-3,19.67-3.28A8,8,0,0,0,223.28,130.08Z"}))],["light",t.createElement(t.Fragment,null,t.createElement("path",{d:"M152,86a30,30,0,1,0-30-30A30,30,0,0,0,152,86Zm0-48a18,18,0,1,1-18,18A18,18,0,0,1,152,38Zm66.49,100.86c-.59.27-7.17,3.13-18.88,3.13-13.86,0-34.9-4-61.73-21a165.89,165.89,0,0,1-17.43,36.51c9.43,2.78,22,7.72,33.19,16.26C172.46,188.05,182,207.65,182,232a6,6,0,0,1-12,0c0-44-37.23-59.18-56.91-64.11q-1.2,1.55-2.46,3.09c-19.25,23.31-43.34,35.45-70.11,35.45A90.72,90.72,0,0,1,31.4,206,6,6,0,0,1,32.6,194c26.63,2.66,49.77-7.66,68.77-30.69,13.16-15.94,21.94-35.51,26.08-49.15-40.51-24.52-66.59-4.78-67.72-3.89a6,6,0,0,1-7.48-9.38c.37-.3,9.39-7.43,24.76-10,13.86-2.31,35.92-1.3,62.36,16.67,47.14,32,73.88,20.47,74.14,20.35a6,6,0,1,1,5,10.92Z"}))],["regular",t.createElement(t.Fragment,null,t.createElement("path",{d:"M152,88a32,32,0,1,0-32-32A32,32,0,0,0,152,88Zm0-48a16,16,0,1,1-16,16A16,16,0,0,1,152,40Zm67.31,100.68c-.61.28-7.49,3.28-19.67,3.28-13.85,0-34.55-3.88-60.69-20a169.31,169.31,0,0,1-15.41,32.34,104.29,104.29,0,0,1,31.31,15.81C173.92,186.65,184,207.35,184,232a8,8,0,0,1-16,0c0-41.7-34.69-56.71-54.14-61.85-.55.7-1.12,1.41-1.69,2.1-19.64,23.8-44.25,36.18-71.63,36.18A92.29,92.29,0,0,1,31.2,208,8,8,0,0,1,32.8,192c25.92,2.58,48.47-7.49,67-30,12.49-15.14,21-33.61,25.25-47C86.13,92.35,61.27,111.63,61,111.84A8,8,0,1,1,51,99.36c1.5-1.2,37.22-29,89.51,6.57,45.47,30.91,71.93,20.31,72.18,20.19a8,8,0,1,1,6.63,14.56Z"}))],["thin",t.createElement(t.Fragment,null,t.createElement("path",{d:"M152,84a28,28,0,1,0-28-28A28,28,0,0,0,152,84Zm0-48a20,20,0,1,1-20,20A20,20,0,0,1,152,36Zm65.66,101c-.57.26-6.84,3-18.08,3-13.86,0-35.25-4.15-62.81-22.16a162.59,162.59,0,0,1-19.49,40.78c9.47,2.56,23.08,7.5,35.14,16.67,18.3,13.92,27.58,33,27.58,56.68a4,4,0,0,1-8,0c0-15.89-5.88-53.77-59.7-66.37q-1.56,2.06-3.22,4.08c-18.85,22.83-42.42,34.72-68.6,34.72q-4.4,0-8.89-.45a4,4,0,1,1,.8-8c27.33,2.73,51.06-7.83,70.52-31.41,13.82-16.74,22.89-37.44,26.9-51.32-42.84-26.69-71-4.8-71.32-4.57a4,4,0,1,1-5-6.24c.36-.29,9-7.1,23.84-9.58,13.5-2.27,35-1.26,60.91,16.34,25,17,44.41,21.64,56.29,22.56,12.75,1,19.77-2,19.84-2.05a4,4,0,0,1,3.29,7.29Z"}))]]),Ae=t.forwardRef((s,n)=>t.createElement(ke,{ref:n,...s,weights:Ye}));Ae.displayName="FolderOpenIcon";const ze=t.forwardRef((s,n)=>t.createElement(ke,{ref:n,...s,weights:Xe}));ze.displayName="PersonSimpleRunIcon";var et={VITE_API_HOST_URL:"https://modelworks.ai/api"};const V=et.VITE_API_HOST_URL,G=s=>{if(s instanceof pe&&s.response)switch(s.response.status){case 400:return"Bad Request: Invalid prompt data";case 401:return"Unauthorized: Invalid session token";case 404:return"Not Found: The requested prompt was not found";default:return`Error: ${s.response.statusText}`}return console.error("Error:",s),"An unexpected error occurred"},$e=async(s,n)=>{var l;try{return(await s.get(`${V}/circuit-versions/${n}/prompts`)).data.payload.prompts}catch(a){if(a instanceof pe&&((l=a.response)==null?void 0:l.status)===404)return[];throw new Error(G(a))}},Se=async(s,n,l)=>{try{return(await s.post(`${V}/circuit-versions/${n}/prompts`,l)).data.payload}catch(a){throw new Error(G(a))}},Me=async(s,n,l,a)=>{try{return(await s.put(`${V}/circuit-versions/${n}/prompts/${encodeURIComponent(l)}`,a)).data.payload}catch(m){throw new Error(G(m))}},Ee=async(s,n,l)=>{try{await s.delete(`${V}/circuit-versions/${n}/prompts/${encodeURIComponent(l)}`)}catch(a){throw new Error(G(a))}},tt=async(s,n,l)=>{try{return(await s.get(`${V}/circuit-versions/${n}/prompts/${encodeURIComponent(l)}`)).data.payload}catch(a){throw new Error(G(a))}},He=async(s,n)=>{var l;try{return(await s.get(`${V}/circuit-versions/${n}/prompts/check`)).data.payload}catch(a){if(a instanceof pe&&((l=a.response)==null?void 0:l.status)===404)return{satisfied:[],missing:[]};throw new Error(G(a))}},le={mem:X({}),disk:Ne("aihub.prompt.state",{},void 0,{getOnInit:!0})},Fe=(s,n)=>`${s}:${n}`,st=(s,n)=>X(l=>{const a=l(le.mem),m=Fe(s,n);return a[m]||{satisfied:[],missing:[]}}),nt=(s,n)=>X(null,(l,a,m)=>{const h=l(le.mem),v=Fe(s,n),w=h[v]||{satisfied:[],missing:[]};a(le.mem,{...h,[v]:{...w,...m}})}),rt=()=>{const[s,n]=Q(ae),l=de(),a=qe(),m=Pe({navigate:l,setState:n}),h=d=>{var o,j;return Y({queryKey:["prompts",d],queryFn:async()=>d?$e(m,d):[],enabled:!!((j=(o=s.session)==null?void 0:o.disk)!=null&&j.sessionToken)&&!!d})},v=(d,o)=>{var j,f;return Y({queryKey:["prompt",d,o],queryFn:async()=>{if(!d||!o)throw new Error("Missing required parameters");return tt(m,d,o)},enabled:!!((f=(j=s.session)==null?void 0:j.disk)!=null&&f.sessionToken)&&!!d&&!!o})},w=K({mutationFn:async({circuitVersionUid:d,prompt:o})=>Se(m,d,o),onSuccess:(d,o)=>{a.invalidateQueries({queryKey:["prompts",o.circuitVersionUid]})}}),A=K({mutationFn:async({circuitVersionUid:d,name:o,updates:j})=>Me(m,d,o,j),onSuccess:(d,o)=>{a.invalidateQueries({queryKey:["prompts",o.circuitVersionUid]})}}),p=K({mutationFn:async({circuitVersionUid:d,name:o})=>Ee(m,d,o),onSuccess:(d,o)=>{a.invalidateQueries({queryKey:["prompts",o.circuitVersionUid]})}});return{usePromptsByCircuitVersionQuery:h,usePromptByNameQuery:v,usePromptCheckQuery:d=>{var o,j;return Y({queryKey:["checkPrompts",d],queryFn:async()=>d?He(m,d):null,enabled:!!((j=(o=s.session)==null?void 0:o.disk)!=null&&j.sessionToken)&&!!d})},createPrompt:w.mutate,updatePrompt:A.mutate,deletePrompt:p.mutate,isCreating:w.isPending,isUpdating:A.isPending,isDeleting:p.isPending}},ot=(s,n)=>{var M,P,i,g;const[l,a]=Q(ae),m=de(),h=Pe({navigate:m,setState:a}),v=t.useMemo(()=>n?st(s,n):null,[s,n]),w=t.useMemo(()=>n?nt(s,n):null,[s,n]),A=t.useMemo(()=>X({satisfied:[],missing:[]}),[]),p=t.useMemo(()=>X(null,()=>{}),[]),[c]=Q(v||A),[,d]=Q(w||p),o=["checkPrompts",n],{data:j,isLoading:f,error:z,refetch:$}=Y({queryKey:o,enabled:!!((P=(M=l.session)==null?void 0:M.disk)!=null&&P.sessionToken)&&!!n,queryFn:async()=>{if(!n)throw new Error("Missing required parameters");const y=await He(h,n);return d({satisfied:y.satisfied,missing:y.missing}),y}}),{data:x,isLoading:C,error:k}=Y({queryKey:["prompts",n],queryFn:async()=>{if(!n)throw new Error("Circuit version UID is missing");return $e(h,n)},enabled:!!((g=(i=l.session)==null?void 0:i.disk)!=null&&g.sessionToken)&&!!n}),S=K({mutationFn:async({circuitVersionUid:y,prompt:u})=>Se(h,y,u),onSuccess:async()=>{await $()}}),I=K({mutationFn:async({circuitVersionUid:y,name:u,updates:b})=>Me(h,y,u,b),onSuccess:async()=>{await $()}}),F=K({mutationFn:async({circuitVersionUid:y,name:u})=>Ee(h,y,u),onSuccess:async()=>{await $()}});return{prompts:x,promptCheck:j,promptData:c,refetchPromptCheck:$,isLoading:C,isCheckingPrompts:f,error:k,checkPromptsError:z,createPrompt:S.mutate,createPromptAsync:S.mutateAsync,updatePrompt:I.mutate,deletePrompt:F.mutate,isCreatingPrompt:S.isPending,isUpdatingPrompt:I.isPending,isDeletingPrompt:F.isPending}},it=r.div`
	border: 2px dashed ${s=>s.$isDraggingOver?"#aaa":"#777"};
	border-radius: 10px;
	margin-top: 12px;
	padding: 20px;
	cursor: pointer;
	transition: all 0.3s ease;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;

	&:hover {
		border-color: #aaa;
	}
`,at=r.input`
	display: none;
`,ct=r.div`
	display: flex;
	align-items: center;
	padding: 10px;
	border: 1px solid #444;
	border-radius: 5px;
	margin-top: 10px;
	background-color: #0a0a0a;
`,lt=r.div`
	margin-right: 15px;
	color: #ffffff;
	font-size: 24px;
`,dt=r.div`
	flex-grow: 1;
	color: #ffffff;
`,pt=r.button`
	background: none;
	border: none;
	color: #555;
	font-size: 24px;
	cursor: pointer;
	transition: color 0.3s ease;

	&:hover {
		color: #ffffff;
	}
`,mt=r.p`
	font-size: 0.8rem;
	color: #9ca3af;
	margin-top: 4px;
`,ut=r.div`
	margin-top: 12px;
	border: 1px solid #333;
	border-radius: 6px;
	overflow: hidden;
	max-height: 200px;
	overflow-y: auto;
`,ht=r.div`
	padding: 8px 12px;
	background-color: #1a1a1a;
	border-bottom: 1px solid #333;
	font-size: 11px;
	color: #888;
`,xt=r.pre`
	padding: 12px;
	margin: 0;
	font-size: 12px;
	color: #ccc;
	white-space: pre-wrap;
	word-wrap: break-word;
	font-family: 'Courier New', Courier, monospace;
`,ft=r.div`
	font-family: 'Courier New', Courier, monospace;
	font-size: 14px;
	color: white;
	background-color: #0a0a0a;
	padding: 8px 12px;
	border-radius: 6px;
	border: 1px solid #333;
`,gt=({isOpen:s,onClose:n,promptRequirement:l,onSubmit:a,isSubmitting:m})=>{const[h,v]=t.useState(l.description||""),[w,A]=t.useState(null),[p,c]=t.useState(""),[d,o]=t.useState(!1),j=t.useRef(null),f=t.useMemo(()=>!!w&&!!p&&!m,[w,p,m]),z=t.useCallback(()=>{v(""),A(null),c(""),o(!1)},[]),$=t.useCallback(()=>{z(),n()},[z,n]),x=t.useCallback(i=>{const g=new FileReader;g.onload=y=>{var b;const u=(b=y.target)==null?void 0:b.result;typeof u=="string"&&c(u)},g.onerror=()=>{c("")},g.readAsText(i)},[]),C=t.useCallback(i=>{i.name.endsWith(".md")||i.name.endsWith(".txt")||i.type==="text/markdown"||i.type==="text/plain"?(A(i),x(i)):(A(i),c(""))},[x]),k=t.useCallback(i=>{var y;const g=(y=i.target.files)==null?void 0:y[0];g&&C(g)},[C]),S=t.useCallback(i=>{i.preventDefault(),o(!0)},[]),I=t.useCallback(i=>{i.preventDefault(),o(!1)},[]),F=t.useCallback(i=>{i.preventDefault(),o(!1);const g=i.dataTransfer.files[0];g&&C(g)},[C]),M=t.useCallback(()=>{A(null),c("")},[]),P=t.useCallback(()=>{f&&p&&(a(l.key,h,p),z())},[f,p,a,l.key,h,z]);return e.jsx(Te,{open:s,onOpenChange:i=>{i||$()},title:"Provide Prompt",subtitle:"Upload a markdown file to provide this prompt.",maxWidth:"md",contentClassName:"relative",showCancel:!0,cancelText:"Cancel",onCancel:$,cancelDisabled:m,cancelVariant:"outline",actionText:m?"Uploading…":"Upload Prompt",onAction:P,actionDisabled:!f,actionLoading:m,actionVariant:"default",buttonSize:"lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Prompt Name"}),e.jsx("div",{className:"mt-1",children:e.jsx(ft,{children:l.key})}),l.description&&e.jsx("div",{className:"mt-2 text-xs text-zinc-500",children:l.description})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Description (optional)"}),e.jsx(De,{value:h,onChange:i=>v(i.target.value),placeholder:"Add a description for this prompt...",disabled:m,className:"mt-1 min-h-[80px] w-full resize-none border-zinc-800 bg-zinc-950 text-zinc-100 placeholder:text-zinc-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-zinc-300",children:"Prompt File"}),w?e.jsxs(e.Fragment,{children:[e.jsxs(ct,{children:[e.jsx(lt,{children:e.jsx(Ze,{size:24})}),e.jsx(dt,{children:w.name}),e.jsx(pt,{onClick:M,type:"button",children:e.jsx(We,{size:16})})]}),p&&e.jsxs(ut,{children:[e.jsx(ht,{children:"Preview"}),e.jsx(xt,{children:p})]})]}):e.jsxs(it,{$isDraggingOver:d,onClick:()=>{var i;return(i=j.current)==null?void 0:i.click()},onDragOver:S,onDragLeave:I,onDrop:F,children:[e.jsx(Ke,{size:48}),e.jsx("p",{style:{marginTop:"12px"},children:"Click to upload or drag and drop"}),e.jsx(mt,{children:"Only .md or .txt files are accepted."}),e.jsx(at,{ref:j,type:"file",accept:".md,.txt,.markdown",onChange:k})]})]}),m&&e.jsx("div",{className:"text-xs text-zinc-500",children:"Uploading prompt…"})]})})},jt=r.div`
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 16px;
	margin-bottom: 16px;
	font-size: 11px;
	color: #cccccc;
`,je=r.div`
	display: flex;
	align-items: center;
	gap: 6px;
`,ye=r.span`
	font-size: 11px;
	color: #bbbbbb;
`,yt=r.div`
	margin: 5px 0 15px 0;
	font-size: 12px;
	color: white;
`,bt=r.div`
	display: flex;
	align-items: center;
	padding: 12px 0;
	position: relative;

	&:not(:last-child) {
		margin-bottom: 5px;
	}

	background-color: #090909;
`,vt=r.div`
	margin-right: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 28px;
	line-height: 0;
`,wt=r.div`
	display: flex;
	flex-direction: column;
	color: #ccc;
	flex-grow: 1;
`,Ct=r.span`
	font-weight: bold;
`,kt=r.div`
	display: flex;
	align-items: center;
	margin-top: 4px;
`,Pt=r.span`
	font-size: 12px;
	color: #ddd;
	font-family: 'Courier New', Courier, monospace;
	font-weight: 600;
	overflow-wrap: anywhere;
`,At=r.span`
	font-size: 14px;
	color: #888;
	margin-top: 2px;
	font-weight: normal;
`,zt=r.div`
	display: flex;
	align-items: center;
	gap: 8px;
	margin-left: 16px;
`,$t=r.div`
	display: inline-flex;
`,St=({circuit:s,circuitVersion:n,showEmptyState:l=!1,isOwner:a})=>{const m=n.detected_prompts??[],[h]=Q(ae),v=h.user.disk.currentUser,w=n.state===he.STAGING,A=(v==null?void 0:v.uid)===s.user_uid,p=!s.is_private||A,{promptData:c,refetchPromptCheck:d,isCheckingPrompts:o,createPromptAsync:j,isCreatingPrompt:f,prompts:z}=ot(n.circuitUid,n.uid),[$,x]=t.useState(!1),[C,k]=t.useState(null),{showToast:S}=Qe();if(t.useEffect(()=>{n.uid&&d()},[n.uid,d]),n.state===he.DEACTIVATED||o)return null;const I=u=>{k(u),x(!0)},F=()=>{x(!1),k(null)},M=async(u,b,L)=>{try{await j({circuitVersionUid:n.uid,prompt:{name:u,description:b,prompt:L}}),S({message:"Prompt uploaded successfully",color:"green"}),F()}catch(E){S({message:`Failed to upload prompt: ${E}`,color:"red"})}},P=u=>{const b=z==null?void 0:z.find(T=>T.name===u.key);if(!b)return;const L=new Blob([b.prompt],{type:"text/markdown"}),E=URL.createObjectURL(L),N=document.createElement("a");N.href=E,N.download=`${u.key}.md`,document.body.appendChild(N),N.click(),document.body.removeChild(N),URL.revokeObjectURL(E)},i=(u,b)=>e.jsxs(xe,{children:[e.jsx(fe,{asChild:!0,children:e.jsx("span",{style:{display:"inline-flex",alignItems:"center"},children:b})}),e.jsx(ge,{className:"border-zinc-800 bg-zinc-950 text-zinc-100",children:u})]}),g=()=>e.jsxs(xe,{children:[e.jsx(fe,{asChild:!0,children:e.jsx($t,{children:e.jsx(H,{type:"button",variant:"secondary",className:"h-7 px-3 text-xs opacity-50 cursor-not-allowed",disabled:!0,children:"Provide"})})}),e.jsx(ge,{className:"border-zinc-800 bg-zinc-950 text-zinc-100",children:"Prompts can only be modified when circuit is in Staging state"})]}),y=u=>{var ee,te;const b=u.key,L=((ee=c==null?void 0:c.satisfied)==null?void 0:ee.some(J=>J.key===b))??!1,E=((te=c==null?void 0:c.missing)==null?void 0:te.some(J=>J.key===b))??!1,N=`${u.circuit_name}`;let T;return E?T=i("Prompt is missing and must be provided",e.jsx(ue,{size:24,weight:"fill",color:"#ff4d4f"})):L?T=i("Prompt is provided",e.jsx(W,{size:24,weight:"fill",color:"#10b981"})):T=i("Prompt state unknown",e.jsx(oe,{size:24,weight:"duotone",color:"#999999"})),e.jsxs(bt,{children:[e.jsx(vt,{children:T}),e.jsxs(wt,{children:[e.jsx(Ct,{children:N}),e.jsx(kt,{children:e.jsx(Pt,{children:b})}),u.description&&e.jsx(At,{children:u.description})]}),e.jsxs(zt,{children:[E&&v&&w&&e.jsx(H,{type:"button",variant:"secondary",className:"h-7 px-3 text-xs",onClick:()=>I(u),children:"Provide"}),E&&v&&!w&&g(),L&&v&&p&&e.jsxs(H,{type:"button",variant:"outline",className:"h-7 px-3 text-xs border-zinc-700 text-white hover:bg-accent hover:text-white",onClick:()=>P(u),children:[e.jsx(_e,{size:14,className:"mr-1"}),"Download"]})]})]},`${u.circuit_uid}-${u.circuit_version_uid}-${b}`)};return m.length===0?l?e.jsx("div",{style:{marginTop:8},children:e.jsx(re,{title:"No Prompts Required",message:"This circuit version does not declare any prompts.",phosphorIcon:oe})}):null:e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{delayDuration:150,children:[m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(yt,{children:"Prompts for this Circuit"}),e.jsxs(jt,{children:[e.jsxs(je,{children:[e.jsx(ue,{size:16,weight:"fill",color:"#ff4d4f"}),e.jsx(ye,{children:"Missing & required"})]}),e.jsxs(je,{children:[e.jsx(W,{size:16,weight:"fill",color:"#10b981"}),e.jsx(ye,{children:"Provided"})]})]})]}),m.map(y)]}),C&&e.jsx(gt,{isOpen:$,onClose:F,promptRequirement:C,onSubmit:M,isSubmitting:f})]})},Mt=r.div`
	font-size: 24px;
	font-weight: bold;
	color: #ffffff;
	filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.1));
`,Et=r.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
`,Ht=r.div`
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
`,Ft=r.div`
  display: flex;
  flex-direction: column;
  align-items: flex-start;
`,It=r.div`
  font-size: 11px;
  font-weight: bold;
  color: #aaa;
  line-height: 1.2;
  margin-bottom: 1px;
`,Lt=r.div`
  font-size: 13px;
  color: #ffffff;
  line-height: 1.2;
`,Nt=r(Le)`
	border: ${s=>s.$showBorder?"1px solid #333":"none"};
	border-radius: ${s=>s.$showBorder?"8px":"0"};
	padding: 16px;
	background: #0a0a0a;
`,Tt=r(ie)`
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid #333;
  padding-bottom: 12px;
`,Dt=r(ie)`
  gap: 16px;
  align-items: center;
`,se=r.button`
	all: unset;
	cursor: pointer;
	font-weight: bold;
	font-size: 18px;
	color: ${s=>s.$active&&s.$isAuthor?"#FF8C00":"#ffffff"};
	position: relative;
	padding: 4px 2px;
	border-radius: 4px;
	box-shadow: ${({$active:s})=>s?"inset 0 2px 4px rgba(0, 0, 0, 0.5)":"none"};
	filter: ${s=>s.$active&&s.$isAuthor?"drop-shadow(0 0 8px rgba(255, 140, 0, 0.3))":"none"};

	&::after {
		content: '';
		position: absolute;
		left: 0;
		right: 0;
		bottom: -12px;
		height: 2px;
		background: ${s=>s.$active&&s.$isAuthor?"#FF8C00":s.$active?"#ffffff":"transparent"};
		border-radius: 2px;
	}
`,Zt=Ie`
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
`,be=r.span`
  position: absolute;
  top: -4px;
  right: -8px;
  width: 10px;
  height: 10px;
  pointer-events: none;
`,ve=r.span`
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: #ff4d4f;
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.25);
`,we=r.span`
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: #ff4d4f;
  opacity: 0.5;
  animation: ${Zt} 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
`,ne=r.div`
  & > *:first-of-type {
    border-top: none;
  }
`,Z=r(ie)`
  justify-content: space-between; /* pushes button to the right edge */
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid #333;
`,R=r(ie)`
  align-items: center;
  gap: 12px;
  min-width: 0; /* allow text to wrap nicely */
`,q=r.div`
  display: flex;
  align-items: center;
  justify-content: flex-end; /* ensure any visible button is right-justified */
  gap: 8px;
  min-width: 200px; /* helps keep a stable right column for buttons */
`,U=r.div`
  display: flex;
  flex-direction: column;
  min-width: 0;
`,O=r(Ce)`
  font-weight: bold;
  color: #ffffff;
`,_=r(Ce)`
  font-size: 14px;
  color: #888888;
`,B=r.div`
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: ${s=>s.checked?"rgba(33, 254, 192, 0.84)":"#888888"};
`,os=({author:s,circuit:n,circuitVersionUid:l,showBorder:a=!0,showHeader:m=!0})=>{const h=de(),{useCircuitVersionByIdQuery:v}=Be(),{usePromptCheckQuery:w}=rt(),[A]=Q(ae),p=A.user.disk.currentUser??null,{data:c,isLoading:d}=v(l),{secretCheck:o,isCheckingSecrets:j}=Re(n.uid,c==null?void 0:c.uid),{data:f,isLoading:z}=w(c==null?void 0:c.uid),$=j||z,x=!!c,C=(c==null?void 0:c.state)==="RUNNING",k=t.useMemo(()=>!x||!Array.isArray(o==null?void 0:o.missing)?!1:o.missing.length===0,[x,o]),S=t.useMemo(()=>x?Array.isArray(o==null?void 0:o.missing)&&o.missing.length>0:!1,[x,o]),I=t.useMemo(()=>f?f.satisfied.length>0||f.missing.length>0:!1,[f]),F=t.useMemo(()=>f?f.missing.length>0:!1,[f]),M=t.useMemo(()=>f?f.missing.length===0:!0,[f]),P=!!p&&p.uid===s.uid,[i,g]=t.useState("setup"),[y,u]=t.useState(!1),b=x&&k&&M&&C;if(t.useEffect(()=>{b&&!y&&(g("endpoints"),u(!0))},[b,y]),d||$)return null;const L=()=>{if(!p){h("/login");return}h(`/${s.username}/${n.name}/versions`)},E=()=>{if(!p){h("/login");return}h(`/${s.username}/${n.name}/settings/secrets`)},N=()=>{h("/login")},T=()=>{h(`/${s.username}/${n.name}/api`)},ee=()=>e.jsxs(e.Fragment,{children:[e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:!1,children:e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Login to ModelWorks"}),e.jsx(_,{children:"Login to ModelWorks to use this circuit. To get started, get an API key."})]})]}),e.jsx(q,{children:e.jsx(H,{onClick:N,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:"Login"})})]}),e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:!1,children:e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Explore endpoints"}),e.jsx(_,{children:"ModelWorks allows apps to access LLMs and MCP servers worldwide easily in any datacenter, securely and privately."})]})]}),e.jsx(q,{children:e.jsx(H,{onClick:T,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:"View API docs"})})]}),e.jsx(Z,{children:e.jsxs(R,{children:[e.jsx(B,{checked:!1,children:e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Secrets"}),e.jsx(_,{children:"Override default secrets and set up your own for better billing and security."})]})]})})]}),te=()=>e.jsxs(e.Fragment,{children:[e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:k,children:k?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Provide Required Secrets"}),e.jsx(_,{children:"Override secrets used by this circuit to control billing and security."})]})]}),e.jsx(q,{children:!k&&x&&e.jsxs(H,{onClick:E,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:[e.jsx(ce,{size:16}),"Add Secrets"]})})]}),e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:x,children:x?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Explore endpoints"}),e.jsx(_,{children:"Use the HTTP endpoints to call this circuit from your apps and workflows."})]})]}),e.jsx(q,{children:x&&e.jsx(H,{onClick:T,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:"Open API Playground"})})]})]}),J=()=>e.jsxs(e.Fragment,{children:[e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:x,children:x?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Configure circuit.json file"}),e.jsx(_,{children:"Set up your circuit.json and commit it with your repo to define behavior and metadata."})]})]}),e.jsx(q,{children:!x&&e.jsxs(H,{onClick:L,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:[e.jsx(Oe,{size:16}),"Add Version"]})})]}),e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:k,children:k?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Set up secrets"}),e.jsx(_,{children:"Configure circuit and user secrets so runs are secure, auditable, and billable."})]})]}),e.jsx(q,{children:!k&&x&&e.jsxs(H,{onClick:E,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:[e.jsx(ce,{size:16,className:"mr-2"}),"Add Secrets"]})})]}),I&&e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:M,children:M?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Configure prompts"}),e.jsx(_,{children:"Set up prompts for this circuit version to provide context to the LLM."})]})]}),e.jsx(q,{children:!M&&x&&e.jsxs(H,{onClick:()=>g("prompts"),variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:[e.jsx(oe,{size:16,className:"mr-2"}),"Add Prompts"]})})]}),e.jsxs(Z,{children:[e.jsxs(R,{children:[e.jsx(B,{checked:C,children:C?e.jsx(W,{size:20}):e.jsx(D,{size:20})}),e.jsxs(U,{children:[e.jsx(O,{children:"Light Circuit"}),e.jsx(_,{children:"Run sample executions to validate and showcase your circuit before enabling it. You will need 3 public runs to light the circuit."})]})]}),e.jsx(q,{children:x&&!C&&e.jsxs(H,{onClick:L,variant:"outline",className:"border-gray-700 text-white hover:bg-accent hover:text-white",size:"sm",children:[e.jsx(ze,{size:16,className:"mr-2"}),"Execute Runs"]})})]})]});return e.jsxs(Nt,{$showBorder:a,children:[m&&e.jsxs(Et,{children:[e.jsx(Mt,{children:"Control Panel"}),p&&e.jsxs(Ht,{children:[e.jsx(Je,{size:24,username:p.username}),e.jsxs(Ft,{children:[e.jsx(It,{children:p.name}),e.jsxs(Lt,{children:["@",p.username]})]})]})]}),e.jsx(Tt,{children:e.jsxs(Dt,{children:[e.jsx(se,{$active:i==="setup",$isAuthor:P,onClick:()=>g("setup"),children:P?"Admin Setup":"Circuit Setup"}),e.jsx(se,{$active:i==="endpoints",onClick:()=>g("endpoints"),children:"Endpoints"}),p&&P&&I&&e.jsxs(se,{$active:i==="prompts",onClick:()=>g("prompts"),"aria-label":F?"Prompts (attention needed)":"Prompts",children:["Prompts",F&&e.jsxs(be,{children:[e.jsx(ve,{}),e.jsx(we,{})]})]}),p&&e.jsxs(se,{$active:i==="secrets",onClick:()=>g("secrets"),"aria-label":S?"Secrets (attention needed)":"Secrets",children:["Secrets",S&&e.jsxs(be,{children:[e.jsx(ve,{}),e.jsx(we,{})]})]})]})}),i==="setup"&&e.jsxs(ne,{children:[!p&&ee(),p&&!P&&te(),p&&P&&J()]}),i==="endpoints"&&e.jsxs(ne,{children:[c&&e.jsx(Ge,{circuitVersion:c,hideRunningState:!0,showDocumentationCTA:!0,user:s,circuit:n,hideFrame:!0,hideHeader:!0}),!c&&e.jsx(re,{title:"Missing Primary Version",message:"Upload and light a valid Circuit to create the endpoints.",phosphorIcon:Ae,secondaryIcon:me})]}),p&&P&&i==="prompts"&&e.jsxs(ne,{children:[c&&e.jsx(St,{circuit:n,circuitVersion:c,isOwner:P,showEmptyState:!0}),!c&&e.jsx(re,{title:"Missing Primary Version",message:"Upload and light a valid Circuit to configure prompts.",phosphorIcon:oe})]}),p&&i==="secrets"&&e.jsxs(ne,{children:[c&&e.jsx("div",{children:e.jsx(Ue,{circuit:n,circuitVersion:c,showHeader:!1,framed:!1})}),!c&&e.jsx(re,{title:"Missing Primary Version",message:"Upload and light a valid Circuit to configure secrets.",phosphorIcon:ce,secondaryIcon:me})]})]})};export{os as A};