1import{w as H,r as u,j as e,a as $,c as R,P as pe,d as xe,h as L,s as b}from"./index-BV8gqper.js";import{R as he,I as ve,c as X,S as ge}from"./index-CAM_BDfV.js";import{u as be}from"./index-CbwL7TKW.js";import{u as je}from"./index-BKnyxcFf.js";import{u as _e}from"./index-BFM6NqUU.js";import{B as j}from"./button-CbiezTUZ.js";import{I as E}from"./input-B7f56973.js";import{T as q}from"./textarea-DoUzYxd_.js";import{S as z}from"./switch-CCGX1T4k.js";import{L as k}from"./label-B8uXX_ln.js";import{u as N}from"./index-BEZ7Pntx.js";import{L as G}from"./loader-circle-_xQYSkbi.js";import{T as B}from"./trash-2-Bgz3WvZi.js";import{P as O}from"./plus-B5fleOar.js";import"./index-CATdHTte.js";import"./index-1yCp-cuc.js";import"./index-CvvDWUCh.js";const K=H("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);const U=H("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);var M="Tabs",[ye]=xe(M,[X]),Y=X(),[Ne,D]=ye(M),J=u.forwardRef((o,n)=>{const{__scopeTabs:i,value:c,onValueChange:l,defaultValue:h,orientation:m="horizontal",dir:v,activationMode:_="automatic",...y}=o,p=be(v),[f,g]=je({prop:c,onChange:l,defaultProp:h??"",caller:M});return e.jsx(Ne,{scope:i,baseId:_e(),value:f,onValueChange:g,orientation:m,dir:p,activationMode:_,children:e.jsx($.div,{dir:p,"data-orientation":m,...y,ref:n})})});J.displayName=M;var Q="TabsList",W=u.forwardRef((o,n)=>{const{__scopeTabs:i,loop:c=!0,...l}=o,h=D(Q,i),m=Y(i);return e.jsx(he,{asChild:!0,...m,orientation:h.orientation,dir:h.dir,loop:c,children:e.jsx($.div,{role:"tablist","aria-orientation":h.orientation,...l,ref:n})})});W.displayName=Q;var Z="TabsTrigger",ee=u.forwardRef((o,n)=>{const{__scopeTabs:i,value:c,disabled:l=!1,...h}=o,m=D(Z,i),v=Y(i),_=se(m.baseId,c),y=ae(m.baseId,c),p=c===m.value;return e.jsx(ve,{asChild:!0,...v,focusable:!l,active:p,children:e.jsx($.button,{type:"button",role:"tab","aria-selected":p,"aria-controls":y,"data-state":p?"active":"inactive","data-disabled":l?"":void 0,disabled:l,id:_,...h,ref:n,onMouseDown:R(o.onMouseDown,f=>{!l&&f.button===0&&f.ctrlKey===!1?m.onValueChange(c):f.preventDefault()}),onKeyDown:R(o.onKeyDown,f=>{[" ","Enter"].includes(f.key)&&m.onValueChange(c)}),onFocus:R(o.onFocus,()=>{const f=m.activationMode!=="manual";!p&&!l&&f&&m.onValueChange(c)})})})});ee.displayName=Z;var te="TabsContent",re=u.forwardRef((o,n)=>{const{__scopeTabs:i,value:c,forceMount:l,children:h,...m}=o,v=D(te,i),_=se(v.baseId,c),y=ae(v.baseId,c),p=c===v.value,f=u.useRef(p);return u.useEffect(()=>{const g=requestAnimationFrame(()=>f.current=!1);return()=>cancelAnimationFrame(g)},[]),e.jsx(pe,{present:l||p,children:({present:g})=>e.jsx($.div,{"data-state":p?"active":"inactive","data-orientation":v.orientation,role:"tabpanel","aria-labelledby":_,hidden:!g,id:y,tabIndex:0,...m,ref:n,style:{...o.style,animationDuration:f.current?"0s":void 0},children:g&&h})})});re.displayName=te;function se(o,n){return`${o}-trigger-${n}`}function ae(o,n){return`${o}-content-${n}`}var we=J,oe=W,ne=ee,ie=re;const ke=we,ce=u.forwardRef(({className:o,...n},i)=>e.jsx(oe,{ref:i,className:L("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",o),...n}));ce.displayName=oe.displayName;const S=u.forwardRef(({className:o,...n},i)=>e.jsx(ne,{ref:i,className:L("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",o),...n}));S.displayName=ne.displayName;const I=u.forwardRef(({className:o,...n},i)=>e.jsx(ie,{ref:i,className:L("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",o),...n}));I.displayName=ie.displayName;const Ce=[{value:"",label:"â без инÑÑÑÑменÑа â"},{value:"get_crypto_prices",label:"get_crypto_prices (ÑенÑ)"},{value:"search_forecast_articles",label:"search_forecast_articles (пÑогнозÑ)"},{value:"search_articles",label:"search_articles (обÑий поиÑк)"},{value:"lookup_glossary",label:"lookup_glossary (глоÑÑаÑий)"}];function Oe(){const[o,n]=u.useState([]),[i,c]=u.useState([]),[l,h]=u.useState(60),[m,v]=u.useState(!0),[_,y]=u.useState(!1);async function p(){v(!0);const[t,r,a]=await Promise.all([b.from("klavdiya_prompt_sections").select("*").order("sort_order"),b.from("klavdiya_prompt_scenarios").select("*").order("sort_order"),b.from("site_settings").select("value").eq("key","klavdiya_prompt_cache_ttl_seconds").maybeSingle()]);t.error&&N.error("СекÑии: "+t.error.message),r.error&&N.error("СÑенаÑии: "+r.error.message),n(t.data||[]),c(r.data||[]);const s=parseInt(a.data?.value??"",10);h(Number.isFinite(s)&&s>0?s:60),v(!1)}u.useEffect(()=>{p()},[]);const f=u.useMemo(()=>{const t=[];o.filter(a=>a.enabled).sort((a,s)=>a.sort_order-s.sort_order).forEach(a=>t.push(`# ${a.title} 2${a.body}`));const r=i.filter(a=>a.enabled).sort((a,s)=>a.sort_order-s.sort_order);
2if(r.length){const a=r.map(s=>{const d=(s.triggers||[]).map(T=>`«${T}»`).join(", "),x=s.tool_name?` â инÑÑÑÑÐ¼ÐµÐ½Ñ \`${s.tool_name}\``:"";return`- ${s.name}${x} 3 ТÑиггеÑÑ: ${d||"â"} 4 ${s.instruction||""}`.trim()});t.push(`# СÑандаÑÑнÑе ÑÑенаÑии запÑоÑов 5${a.join(` 6`)}`)}return t.join(` 7 8`)},[o,i]);function g(t,r){n(a=>a.map(s=>s.id===t?{...s,...r}:s))}function F(t,r){n(a=>{const s=[...a].sort((w,A)=>w.sort_order-A.sort_order),d=s.findIndex(w=>w.id===t),x=d+r;if(d<0||x<0||x>=s.length)return a;const T=s[d].sort_order,P=s[x].sort_order;return s[d]={...s[d],sort_order:P},s[x]={...s[x],sort_order:T},s})}async function le(){const t=Math.max(0,...o.map(d=>d.sort_order))+10,r=`section_${Date.now()}`,{data:a,error:s}=await b.from("klavdiya_prompt_sections").insert({key:r,title:"ÐÐ¾Ð²Ð°Ñ ÑекÑиÑ",body:"",sort_order:t}).select().single();if(s)return N.error(s.message);n(d=>[...d,a])}async function de(t){if(!confirm("УдалиÑÑ ÑекÑиÑ?"))return;const{error:r}=await b.from("klavdiya_prompt_sections").delete().eq("id",t);if(r)return N.error(r.message);n(a=>a.filter(s=>s.id!==t))}function C(t,r){c(a=>a.map(s=>s.id===t?{...s,...r}:s))}function V(t,r){c(a=>{const s=[...a].sort((w,A)=>w.sort_order-A.sort_order),d=s.findIndex(w=>w.id===t),x=d+r;if(d<0||x<0||x>=s.length)return a;const T=s[d].sort_order,P=s[x].sort_order;return s[d]={...s[d],sort_order:P},s[x]={...s[x],sort_order:T},s})}async function me(){const t=Math.max(0,...i.map(s=>s.sort_order))+10,{data:r,error:a}=await b.from("klavdiya_prompt_scenarios").insert({name:"ÐовÑй ÑÑенаÑий",triggers:[],instruction:"",sort_order:t}).select().single();if(a)return N.error(a.message);c(s=>[...s,r])}async function ue(t){if(!confirm("УдалиÑÑ ÑÑенаÑий?"))return;const{error:r}=await b.from("klavdiya_prompt_scenarios").delete().eq("id",t);if(r)return N.error(r.message);c(a=>a.filter(s=>s.id!==t))}async function fe(){y(!0);try{for(const r of o){const{error:a}=await b.from("klavdiya_prompt_sections").update({title:r.title,body:r.body,enabled:r.enabled,sort_order:r.sort_order}).eq("id",r.id);if(a)throw a}for(const r of i){const{error:a}=await b.from("klavdiya_prompt_scenarios").update({name:r.name,triggers:r.triggers,instruction:r.instruction,tool_name:r.tool_name||null,enabled:r.enabled,sort_order:r.sort_order}).eq("id",r.id);if(a)throw a}const{error:t}=await b.from("site_settings").upsert({key:"klavdiya_prompt_cache_ttl_seconds",value:String(l)},{onConflict:"key"});if(t)throw t;N.success(`Ð¡Ð¾Ñ Ñанено. ÐÐ·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¿ÑименÑÑÑÑ Ð² ÑеÑение ${l<60?l+" Ñек":Math.round(l/60)+" мин"} (ÐºÐµÑ Ð¿ÑомпÑа).`)}catch(t){N.error("ÐÑибка ÑÐ¾Ñ ÑанениÑ: "+(t?.message||t))}finally{y(!1)}}return m?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(G,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-serif font-bold",children:"ÐÑомпÑÑ Ðлавдии"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"СиÑÑемнÑй пÑÐ¾Ð¼Ð¿Ñ ÐÐ-ÑедакÑоÑа и ÑÑандаÑÑнÑе ÑÑенаÑии запÑоÑов"})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"text-xs text-muted-foreground whitespace-nowrap",children:"ÐÐµÑ Ð¿ÑомпÑа"}),e.jsxs("select",{value:l,onChange:t=>h(parseInt(t.target.value,10)),className:"h-9 border border-input rounded-md px-2 text-sm bg-background",title:"Ðак долго edge function деÑÐ¶Ð¸Ñ ÑобÑаннÑй пÑÐ¾Ð¼Ð¿Ñ Ð² памÑÑи. ÐенÑÑе â Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¿ÑименÑÑÑÑÑ Ð±ÑÑÑÑее, но ÐÐ ÑиÑаеÑÑÑ ÑаÑе.",children:[e.jsx("option",{value:30,children:"30 Ñек"}),e.jsx("option",{value:60,children:"1 мин"}),e.jsx("option",{value:300,children:"5 мин"}),e.jsx("option",{value:900,children:"15 мин"})]})]}),e.jsxs(j,{onClick:fe,disabled:_,children:[_?e.jsx(G,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(ge,{className:"h-4 w-4 mr-1"}),"Ð¡Ð¾Ñ ÑаниÑÑ Ð²ÑÑ"]})]})]}),e.jsxs(ke,{defaultValue:"sections",children:[e.jsxs(ce,{children:[e.jsxs(S,{value:"sections",children:["СекÑии пÑомпÑа (",o.length,")"]}),e.jsxs(S,{value:"scenarios",children:["СÑенаÑии (",i.length,")"]}),e.jsx(S,{value:"preview",children:"ÐÑедпÑоÑмоÑÑ"})]}),e.jsxs(I,{value:"sections",className:"space-y-3",children:[o.sort((t,r)=>t.sort_order-r.sort_order).map(t=>e.jsxs("div",{className:"border border-border rounded p-3 space-y-2 bg-card",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{value:t.title,onChange:r=>g(t.id,{title:r.target.value}),className:"font-medium"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>F(t.id,-1),children:e.jsx(U,{className:"h-4 w-4"})}),e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>F(t.id,1),children:e.jsx(K,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center gap-1 px-2",children:[e.jsx(z,{checked:t.enabled,onCheckedChange:r=>g(t.id,{enabled:r})}),e.jsx(k,{className:"text-xs text-muted-foreground",children:"вкл"})]}),e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>de(t.id),children:e.jsx(B,{className:"h-4 w-4 text-destructive"})})]})]}),e.jsx(q,{value:t.body,onChange:r=>g(t.id,{body:r.target.value}),rows:Math.max(4,Math.min(20,(t.body.match(/\n/g)?.length||0)+2)),className:"font-mono text-sm"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["key: ",e.jsx("code",{children:t.key})]})]},t.id)),e.jsxs(j,{variant:"outline",onClick:le,children:[e.jsx(O,{className:"h-4 w-4 mr-1"})," ÐобавиÑÑ ÑекÑиÑ"]})]}),e.jsxs(I,{value:"scenarios",className:"space-y-3",children:[i.sort((t,r)=>t.sort_order-r.sort_order).map(t=>e.jsxs("div",{className:"border border-border rounded p-3 space-y-2 bg-card",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{value:t.name,onChange:r=>C(t.id,{name:r.target.value}),className:"font-medium"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>V(t.id,-1),children:e.jsx(U,{className:"h-4 w-4"})}),e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>V(t.id,1),children:e.jsx(K,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center gap-1 px-2",children:[e.jsx(z,{checked:t.enabled,onCheckedChange:r=>C(t.id,{enabled:r})}),e.jsx(k,{className:"text-xs text-muted-foreground",children:"вкл"})]}),e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>ue(t.id),children:e.jsx(B,{className:"h-4 w-4 text-destructive"})})]})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-xs",children:"ТÑиггеÑ-ÑÑÐ°Ð·Ñ (ÑеÑез запÑÑÑÑ)"}),e.jsx(E,{value:(t.triggers||[]).join(", "),onChange:r=>C(t.id,{triggers:r.target.value.split(",").map(a=>
8a.trim()).filter(Boolean)}),placeholder:"ÐºÐ°ÐºÐ°Ñ Ñена, ÑколÑко ÑÑоиÑ, кÑÑÑ"})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-xs",children:"ÐнÑÑÑÑменÑ"}),e.jsx("select",{value:t.tool_name||"",onChange:r=>C(t.id,{tool_name:r.target.value||null}),className:"w-full h-10 border border-input rounded-md px-3 text-sm bg-background",children:Ce.map(r=>e.jsx("option",{value:r.value,children:r.label},r.value))})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-xs",children:"ÐнÑÑÑÑкÑÐ¸Ñ Ð¼Ð¾Ð´ÐµÐ»Ð¸"}),e.jsx(q,{value:t.instruction,onChange:r=>C(t.id,{instruction:r.target.value}),rows:3,placeholder:"Ðогда видиÑÑ Ñакой запÑÐ¾Ñ â вÑзови инÑÑÑÑÐ¼ÐµÐ½Ñ X Ñ Ð¿Ð°ÑамеÑÑами Y, оÑÐ²ÐµÑ Ð¾ÑоÑми Ñак-Ñо."})]})]},t.id)),e.jsxs(j,{variant:"outline",onClick:me,children:[e.jsx(O,{className:"h-4 w-4 mr-1"})," ÐобавиÑÑ ÑÑенаÑий"]})]}),e.jsx(I,{value:"preview",children:e.jsxs("div",{className:"border border-border rounded p-3 bg-muted/30",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-2",children:"Так вÑглÑÐ´Ð¸Ñ ÑиналÑнÑй system prompt (без блока «ÐÐÐТÐÐСТ ÐРСТÐТÐл, коÑоÑÑй добавлÑеÑÑÑ Ð½Ð° каждÑй запÑÐ¾Ñ Ð¾ÑделÑно)"}),e.jsx("pre",{className:"whitespace-pre-wrap text-xs font-mono leading-relaxed",children:f})]})})]})]})}export{Oe 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.