module.exports=[192824,a=>{"use strict";var b=a.i(603784),c=a.i(917145);async function*d(a,d){let f=d?.model??(0,b.getModel)(),g=d?.max_tokens??(0,b.getMaxTokens)(),h="u">typeof sessionStorage?(0,c.getServerUrl)():"",i=await fetch("/api/claude-proxy",{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",...h?{"x-bl-server":h}:{}},body:JSON.stringify({messages:a,model:f,max_tokens:g}),signal:d?.signal});if(503===i.status)throw new e("AI not available — configure the org API key in Settings → Claude AI.",503);if(!i.ok)throw new e(`Proxy returned HTTP ${i.status}`,i.status);let j=i.body?.getReader();if(!j)throw new e("Response body is not readable",0);let k=new TextDecoder,l="";try{for(;;){let{done:a,value:b}=await j.read();if(a)break;let c=(l+=k.decode(b,{stream:!0})).split("\n");for(let a of(l=c.pop()??"",c)){if(!a.startsWith("data: "))continue;let b=a.slice(6).trim();if("[DONE]"===b)return;try{let a=JSON.parse(b);if("text"===a.type&&a.text)yield a.text;else if("stop"===a.type&&a.stop_reason)d?.onStop?.(a.stop_reason);else if("error"===a.type)throw new e(a.message??"Upstream error",0)}catch(a){if(a instanceof e)throw a}}}}finally{j.releaseLock()}}class e extends Error{statusCode;constructor(a,b){super(a),this.statusCode=b,this.name="ClaudeStreamError"}}a.s(["ClaudeStreamError",0,e,"claudeStream",0,d])},179598,a=>{"use strict";let b=(0,a.i(170106).default)("wand",[["path",{d:"M15 4V2",key:"z1p9b7"}],["path",{d:"M15 16v-2",key:"px0unx"}],["path",{d:"M8 9h2",key:"1g203m"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M17.8 11.8 19 13",key:"yihg8r"}],["path",{d:"M15 9h.01",key:"x1ddxp"}],["path",{d:"M17.8 6.2 19 5",key:"fd4us0"}],["path",{d:"m3 21 9-9",key:"1jfql5"}],["path",{d:"M12.2 6.2 11 5",key:"i3da3b"}]]);a.s(["WandIcon",0,b],179598)},551446,a=>{"use strict";var b=a.i(187924),c=a.i(572131),d=a.i(179598),e=a.i(823292),f=a.i(340695),g=a.i(205522),h=a.i(965733),i=a.i(685390),j=a.i(192824),k=a.i(7791),l=a.i(484999),m=a.i(603784);a.s(["TemplateGeneratePanel",0,function({side:a,dataType:n,text:o,setText:p}){(0,i.useCompactMode)();let[q]=(0,c.useState)(()=>(0,m.getEnabled)()),[r,s]=(0,c.useState)(!1),[t,u]=(0,c.useState)(""),[v,w]=(0,c.useState)(""),[x,y]=(0,c.useState)(!1),z=(0,c.useRef)(null),A=(0,c.useRef)(0);if((0,c.useEffect)(()=>()=>{z.current?.abort()},[]),!q)return null;function B(){A.current++,z.current?.abort(),z.current=null}function C(a){s(a),a||(B(),y(!1),w(""),u(""))}async function D(){B();let b=new AbortController;z.current=b;let c=A.current;y(!0),w("");let d=[{role:"user",content:(0,l.buildSampleMessagePrompt)(n,a,t)}],f=(0,m.getModel)();try{let a=(0,k.pickFastModel)(await (0,k.getClaudeAiModels)());a&&(f=a)}catch{}if(A.current===c)try{for await(let a of(0,j.claudeStream)(d,{signal:b.signal,model:f,max_tokens:1500})){if(A.current!==c)return;w(b=>b+a)}}catch{A.current===c&&e.toast.error("Sample generation failed. Check your API key in AI Settings.")}finally{A.current===c&&y(!1)}}return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("button",{onClick:()=>s(!0),className:"px-1.5 py-0.5 text-xs rounded border border-border hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300 transition-colors cursor-pointer whitespace-nowrap flex items-center gap-1",title:"Generate a synthetic sample message with AI","aria-label":"Generate with AI",children:(0,b.jsx)(d.WandIcon,{className:"w-3 h-3"})}),(0,b.jsx)(h.Dialog,{open:r,onOpenChange:C,children:(0,b.jsxs)(h.DialogContent,{className:"sm:max-w-2xl",children:[(0,b.jsx)(h.DialogHeader,{children:(0,b.jsxs)(h.DialogTitle,{children:["Generate Sample Message (",n,")"]})}),(0,b.jsxs)("div",{className:"flex flex-col gap-2 min-h-0 min-w-0",children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)(g.Input,{value:t,onChange:a=>u(a.target.value),placeholder:"HL7V2"===n?"e.g. ADT^A01 discharge message (optional)":"Describe the sample message (optional)",disabled:x,onKeyDown:a=>{"Enter"!==a.key||x||(a.preventDefault(),D())}}),(0,b.jsx)(f.Button,{size:"sm",onClick:()=>void D(),disabled:x,children:x?"Generating…":"Generate"})]}),(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"The sample uses fictional data only — no real patient information."}),(v||x)&&(0,b.jsx)("pre",{"aria-label":"Generated sample preview",className:"max-h-56 min-w-0 max-w-full overflow-auto rounded border border-border bg-muted p-2 text-xs font-mono whitespace-pre-wrap break-all"+(x?" animate-pulse":""),children:(0,l.stripCodeFence)(v)||"Generating…"})]}),(0,b.jsxs)(h.DialogFooter,{children:[(0,b.jsx)(f.Button,{variant:"outline",size:"sm",onClick:()=>C(!1),children:"Cancel"}),(0,b.jsx)(f.Button,{size:"sm",onClick:function(){p((0,l.stripCodeFence)(v)),(0,e.toast)("Template replaced",{action:{label:"Undo",onClick:()=>p(o)}}),C(!1)},disabled:x||!v.trim(),children:"Apply"})]})]})})]})}])}];

//# sourceMappingURL=_0bybqd6._.js.map