@nextclaw/ui 0.5.46 → 0.5.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{ChannelsList-C5IzoBSZ.js → ChannelsList-B6N0kXyK.js} +1 -1
- package/dist/assets/ChatPage-DsDFvVQX.js +32 -0
- package/dist/assets/CronConfig-Cbz6V8MU.js +1 -0
- package/dist/assets/DocBrowser-hQzP4Iai.js +1 -0
- package/dist/assets/{MarketplacePage-DmDTJ27k.js → MarketplacePage-DMoWoU1y.js} +1 -1
- package/dist/assets/{ModelConfig-DQ1d3Dtn.js → ModelConfig-BXjF-qbA.js} +1 -1
- package/dist/assets/ProvidersList-D3hfY5U7.js +1 -0
- package/dist/assets/RuntimeConfig-DJ7qIejp.js +1 -0
- package/dist/assets/{SecretsConfig-DlNYyu9I.js → SecretsConfig-BFDeNvwV.js} +2 -2
- package/dist/assets/{SessionsConfig-Dt9heKTD.js → SessionsConfig-CJF7lPkX.js} +2 -2
- package/dist/assets/{card-KmfXQ4Bm.js → card-BREZdIEb.js} +1 -1
- package/dist/assets/{index-BhpPLO5K.js → index-uTbQ-MAY.js} +2 -2
- package/dist/assets/{label-iF47BkaM.js → label-CzMB2yjV.js} +1 -1
- package/dist/assets/{logos-C8Yako2a.js → logos-vVtRUuoo.js} +1 -1
- package/dist/assets/{page-layout-sZk-HtoA.js → page-layout-B07kdurB.js} +1 -1
- package/dist/assets/{switch-BnYsX3uS.js → switch-Cr6cemeT.js} +1 -1
- package/dist/assets/{tabs-custom-BEBNjTRA.js → tabs-custom-BzcvgsvR.js} +1 -1
- package/dist/assets/{useConfig-DJ_KEVx0.js → useConfig-B4Y6cGwc.js} +1 -1
- package/dist/assets/{useConfirmDialog-BwqRK1uy.js → useConfirmDialog-Dc5WHCUf.js} +1 -1
- package/dist/assets/{vendor-DfLizrKM.js → vendor-Dh04PGww.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/components/chat/ChatConversationPanel.tsx +148 -0
- package/src/components/chat/ChatPage.tsx +80 -353
- package/src/components/chat/ChatSessionsSidebar.tsx +100 -0
- package/src/components/chat/useChatStreamController.ts +268 -0
- package/dist/assets/ChatPage-BEBmDqtw.js +0 -32
- package/dist/assets/CronConfig-BdLVPoNw.js +0 -1
- package/dist/assets/DocBrowser-DzsZUzgQ.js +0 -1
- package/dist/assets/ProvidersList-snuzM5CK.js +0 -1
- package/dist/assets/RuntimeConfig-BSDP51k6.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as x,j as e,a9 as Ce,aa as Pe,a7 as pe,a5 as ie,ab as xe,ac as Se,C as De,ad as Ee,ae as re,_ as Me,K as Le}from"./vendor-DfLizrKM.js";import{I as K,u as ye,a as fe,b as ge,g as ke,h as Be,i as Te,j as Ke}from"./useConfig-DJ_KEVx0.js";import{B as T,P as Ie,a as $e}from"./page-layout-sZk-HtoA.js";import{L as z}from"./label-iF47BkaM.js";import{c as X,t,S as Fe,a as _e,b as Oe,d as Re,e as ze}from"./index-BhpPLO5K.js";import{C as He,a as We,S as je,b as Ge,c as Ve,L as Ue,g as qe}from"./logos-C8Yako2a.js";import{h as q}from"./config-hints-CApS3K_7.js";import{T as Qe}from"./tabs-custom-BEBNjTRA.js";function Xe({maskedValue:s,isSet:a,className:r,value:i,onChange:y,placeholder:b,...f}){const[c,u]=x.useState(!1),[g,p]=x.useState(!1),A=typeof i=="string"&&i.length>0,S=a&&!A&&!g;return e.jsxs("div",{className:"relative",children:[S?e.jsx("div",{onClick:()=>p(!0),className:X("flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-500 cursor-text items-center pr-12",r),children:"••••••••••••"}):e.jsx(K,{type:c?"text":"password",className:X("pr-12",r),value:i,onChange:y,onBlur:()=>{A||p(!1)},placeholder:b,autoFocus:g,...f}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:(a||A)&&e.jsx(T,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(!c),children:c?e.jsx(Ce,{className:"h-4 w-4"}):e.jsx(Pe,{className:"h-4 w-4"})})})]})}function Ye({value:s,onChange:a,className:r}){const i=s?Object.entries(s):[],y=(c,u,g)=>{const p=[...i];p[c]=[u,g],a(Object.fromEntries(p))},b=()=>{a({...s,"":""})},f=c=>{const u=i.filter((g,p)=>p!==c);a(Object.fromEntries(u))};return e.jsxs("div",{className:X("space-y-2",r),children:[i.map(([c,u],g)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{type:"text",value:c,onChange:p=>y(g,p.target.value,u),placeholder:t("headerName"),className:"flex-1"}),e.jsx(K,{type:"text",value:u,onChange:p=>y(g,c,p.target.value),placeholder:t("headerValue"),className:"flex-1"}),e.jsx(T,{type:"button",variant:"ghost",size:"icon",onClick:()=>f(g),children:e.jsx(pe,{className:"h-4 w-4 text-red-500"})})]},g)),e.jsxs(T,{type:"button",variant:"outline",size:"sm",onClick:b,children:[e.jsx(ie,{className:"h-4 w-4 mr-2"}),t("add")]})]})}function Q(s){if(!s)return null;const a=Object.entries(s).map(([r,i])=>[r.trim(),i]).filter(([r])=>r.length>0);return a.length===0?null:Object.fromEntries(a)}function he(s,a){const r=Q(s),i=Q(a);if(r===null&&i===null)return!0;if(!r||!i)return!1;const y=Object.entries(r).sort(([f],[c])=>f.localeCompare(c)),b=Object.entries(i).sort(([f],[c])=>f.localeCompare(c));return y.length!==b.length?!1:y.every(([f,c],u)=>f===b[u][0]&&c===b[u][1])}function ne(s){if(!s||s.length===0)return[];const a=new Set;for(const r of s){const i=r.trim();i&&a.add(i)}return[...a]}function Je(s,a){const r=s.trim();if(!r||!a.trim())return r;const i=`${a.trim()}/`;return r.startsWith(i)?r.slice(i.length):r}function J(s,a){let r=s.trim();if(!r)return"";for(const i of a){const y=i.trim();y&&(r=Je(r,y))}return r.trim()}function le(s,a){return s.length!==a.length?!1:s.every((r,i)=>r===a[i])}function Ze(s,a){const r=[...s];for(const i of a)r.includes(i)||r.push(i);return r}function es(s,a){return a.length===0?s:a.every(i=>!s.includes(i))?Ze(s,a):a}function ss(s,a){return le(s,a)?[]:s}function ts({providerName:s,onProviderDeleted:a}){const{data:r}=ye(),{data:i}=fe(),{data:y}=ge(),b=ke(),f=Be(),c=Te(),[u,g]=x.useState(""),[p,A]=x.useState(""),[S,H]=x.useState(null),[L,C]=x.useState("auto"),[w,I]=x.useState([]),[d,m]=x.useState(""),[N,v]=x.useState(""),[D,$]=x.useState(!1),[k,B]=x.useState(!1),l=i==null?void 0:i.providers.find(n=>n.name===s),o=s?r==null?void 0:r.providers[s]:null,Y=y==null?void 0:y.uiHints,F=!!(l!=null&&l.isCustom),_=s?q(`providers.${s}.apiKey`,Y):void 0,E=s?q(`providers.${s}.apiBase`,Y):void 0,Z=s?q(`providers.${s}.extraHeaders`,Y):void 0,ee=s?q(`providers.${s}.wireApi`,Y):void 0,oe=(l==null?void 0:l.displayName)||s||"",O=((o==null?void 0:o.displayName)||"").trim()||oe,be=N.trim()||O||s||t("providersSelectPlaceholder"),ce=(l==null?void 0:l.modelPrefix)||s||"",R=x.useMemo(()=>ne([ce,s||""]),[ce,s]),se=(l==null?void 0:l.defaultApiBase)||"",W=(o==null?void 0:o.apiBase)||se,te=Q((o==null?void 0:o.extraHeaders)||null),G=(o==null?void 0:o.wireApi)||(l==null?void 0:l.defaultWireApi)||"auto",ae=x.useMemo(()=>ne(((l==null?void 0:l.defaultModels)??[]).map(n=>J(n,R))),[l==null?void 0:l.defaultModels,R]),de=x.useMemo(()=>ne(((o==null?void 0:o.models)??[]).map(n=>J(n,R))),[o==null?void 0:o.models,R]),V=x.useMemo(()=>es(ae,de),[ae,de]);s==="minimax"?t("providerApiBaseHelpMinimax"):E!=null&&E.help||t("providerApiBaseHelp"),x.useEffect(()=>{if(!s){g(""),A(""),H(null),C("auto"),I([]),m(""),v("");return}g(""),A(W),H((o==null?void 0:o.extraHeaders)||null),C(G),I(V),m(""),v(O)},[s,W,o==null?void 0:o.extraHeaders,G,V,O]);const me=x.useMemo(()=>{if(!s)return!1;const n=u.trim().length>0,j=p.trim()!==W.trim(),P=!he(S,te),h=l!=null&&l.supportsWireApi?L!==G:!1,M=!le(w,V),U=F?N.trim()!==O:!1;return n||j||P||h||M||U},[s,F,N,O,u,p,W,S,te,l==null?void 0:l.supportsWireApi,L,G,w,V]),ue=()=>{const n=J(d,R);if(n){if(w.includes(n)){m("");return}I(j=>[...j,n]),m("")}},Ne=n=>{if(n.preventDefault(),!s)return;const j={},P=u.trim(),h=p.trim(),M=Q(S),U=N.trim();F&&U!==O&&(j.displayName=U.length>0?U:null),P.length>0&&(j.apiKey=P),h!==W.trim()&&(j.apiBase=h.length>0&&h!==se?h:null),he(M,te)||(j.extraHeaders=M),l!=null&&l.supportsWireApi&&L!==G&&(j.wireApi=L),le(w,V)||(j.models=ss(w,ae)),b.mutate({provider:s,data:j})},ve=async()=>{if(!s)return;const n=w.find(h=>h.trim().length>0)??"",j=J(n,R),P={apiBase:p.trim(),extraHeaders:Q(S),model:j||null};u.trim().length>0&&(P.apiKey=u.trim()),l!=null&&l.supportsWireApi&&(P.wireApi=L);try{const h=await c.mutateAsync({provider:s,data:P});if(h.success){re.success(`${t("providerTestConnectionSuccess")} (${h.latencyMs}ms)`);return}const M=[`provider=${h.provider}`,`latency=${h.latencyMs}ms`];h.model&&M.push(`model=${h.model}`),re.error(`${t("providerTestConnectionFailed")}: ${h.message} | ${M.join(" | ")}`)}catch(h){const M=h instanceof Error?h.message:String(h);re.error(`${t("providerTestConnectionFailed")}: ${M}`)}},we=async()=>{if(!(!s||!F||!window.confirm(t("providerDeleteConfirm"))))try{await f.mutateAsync({provider:s}),a==null||a(s)}catch{}};if(!s||!l||!o)return e.jsx("div",{className:He,children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:t("providersSelectTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("providersSelectDescription")})]})});const Ae=o.apiKeySet?t("statusReady"):t("statusSetup");return e.jsxs("div",{className:We,children:[e.jsx("div",{className:"border-b border-gray-100 px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"truncate text-lg font-semibold text-gray-900",children:be}),e.jsxs("div",{className:"flex items-center gap-3",children:[F&&e.jsx("button",{type:"button",onClick:we,disabled:f.isPending,className:"text-gray-400 hover:text-red-500 transition-colors",title:t("providerDelete"),children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx(je,{status:o.apiKeySet?"ready":"setup",label:Ae})]})]})}),e.jsxs("form",{onSubmit:Ne,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:[F&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"providerDisplayName",className:"text-sm font-medium text-gray-900",children:t("providerDisplayName")}),e.jsx(K,{id:"providerDisplayName",type:"text",value:N,onChange:n=>v(n.target.value),placeholder:oe||t("providerDisplayNamePlaceholder"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:t("providerDisplayNameHelpShort")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"apiKey",className:"text-sm font-medium text-gray-900",children:(_==null?void 0:_.label)??t("apiKey")}),e.jsx(Xe,{id:"apiKey",value:u,isSet:o.apiKeySet,onChange:n=>g(n.target.value),placeholder:(_==null?void 0:_.placeholder)??t("enterApiKey"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:t("leaveBlankToKeepUnchanged")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"apiBase",className:"text-sm font-medium text-gray-900",children:(E==null?void 0:E.label)??t("apiBase")}),e.jsx(K,{id:"apiBase",type:"text",value:p,onChange:n=>A(n.target.value),placeholder:se||(E==null?void 0:E.placeholder)||"https://api.example.com",className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:t("providerApiBaseHelpShort")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(z,{className:"text-sm font-medium text-gray-900",children:t("providerModelsTitle")}),!k&&e.jsxs("button",{type:"button",onClick:()=>B(!0),className:"text-xs text-primary hover:text-primary/80 font-medium flex items-center gap-1",children:[e.jsx(ie,{className:"h-3 w-3"}),t("providerAddModel")]})]}),k&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{value:d,onChange:n=>m(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),ue()),n.key==="Escape"&&(B(!1),m(""))},placeholder:t("providerModelInputPlaceholder"),className:"flex-1 rounded-xl",autoFocus:!0}),e.jsx(T,{type:"button",size:"sm",onClick:ue,disabled:d.trim().length===0,children:t("add")}),e.jsx(T,{type:"button",size:"sm",variant:"ghost",onClick:()=>{B(!1),m("")},children:e.jsx(xe,{className:"h-4 w-4"})})]}),w.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center",children:[e.jsx("p",{className:"text-sm text-gray-500",children:t("providerModelsEmptyShort")}),!k&&e.jsx("button",{type:"button",onClick:()=>B(!0),className:"mt-2 text-sm text-primary hover:text-primary/80 font-medium",children:t("providerAddFirstModel")})]}):e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(n=>e.jsxs("div",{className:"group inline-flex max-w-full items-center gap-1 rounded-full border border-gray-200 bg-white px-3 py-1.5",children:[e.jsx("span",{className:"max-w-[180px] truncate text-sm text-gray-800 sm:max-w-[240px]",children:n}),e.jsx("button",{type:"button",onClick:()=>I(j=>j.filter(P=>P!==n)),className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 transition-opacity hover:bg-gray-100 hover:text-gray-600 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100","aria-label":t("remove"),children:e.jsx(xe,{className:"h-3 w-3"})})]},n))})]}),e.jsxs("div",{className:"border-t border-gray-100 pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>$(!D),className:"flex w-full items-center justify-between text-sm text-gray-600 hover:text-gray-900 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Se,{className:"h-3.5 w-3.5"}),t("providerAdvancedSettings")]}),e.jsx(De,{className:`h-4 w-4 transition-transform ${D?"rotate-180":""}`})]}),D&&e.jsxs("div",{className:"mt-4 space-y-5",children:[l.supportsWireApi&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"wireApi",className:"text-sm font-medium text-gray-900",children:(ee==null?void 0:ee.label)??t("wireApi")}),e.jsxs(Fe,{value:L,onValueChange:n=>C(n),children:[e.jsx(_e,{className:"rounded-xl",children:e.jsx(Oe,{})}),e.jsx(Re,{children:(l.wireApiOptions||["auto","chat","responses"]).map(n=>e.jsx(ze,{value:n,children:n==="chat"?t("wireApiChat"):n==="responses"?t("wireApiResponses"):t("wireApiAuto")},n))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{className:"text-sm font-medium text-gray-900",children:(Z==null?void 0:Z.label)??t("extraHeaders")}),e.jsx(Ye,{value:S,onChange:H}),e.jsx("p",{className:"text-xs text-gray-500",children:t("providerExtraHeadersHelpShort")})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 px-6 py-4",children:[e.jsxs(T,{type:"button",variant:"outline",size:"sm",onClick:ve,disabled:c.isPending,children:[e.jsx(Ee,{className:"mr-1.5 h-4 w-4"}),c.isPending?t("providerTestingConnection"):t("providerTestConnection")]}),e.jsx(T,{type:"submit",disabled:b.isPending||!me,children:b.isPending?t("saving"):me?t("save"):t("unchanged")})]})]})]})}function as(s){if(!s)return null;try{const a=new URL(s),r=a.pathname&&a.pathname!=="/"?a.pathname:"";return`${a.host}${r}`}catch{return s.replace(/^https?:\/\//,"")}}function xs(){const{data:s}=ye(),{data:a}=fe(),{data:r}=ge(),i=Ke(),[y,b]=x.useState("installed"),[f,c]=x.useState(),[u,g]=x.useState(""),p=r==null?void 0:r.uiHints,A=(a==null?void 0:a.providers)??[],S=(s==null?void 0:s.providers)??{},H=A.filter(d=>{var m;return(m=S[d.name])==null?void 0:m.apiKeySet}).length,L=[{id:"installed",label:t("providersTabConfigured"),count:H},{id:"all",label:t("providersTabAll"),count:A.length}],C=x.useMemo(()=>{const d=(a==null?void 0:a.providers)??[],m=(s==null?void 0:s.providers)??{},N=u.trim().toLowerCase();return d.filter(v=>{var D;return y==="installed"?!!((D=m[v.name])!=null&&D.apiKeySet):!0}).filter(v=>{var k,B;return N?(((B=(k=m[v.name])==null?void 0:k.displayName)==null?void 0:B.trim())||v.displayName||v.name).toLowerCase().includes(N)||v.name.toLowerCase().includes(N):!0})},[a,s,y,u]);x.useEffect(()=>{if(C.length===0){c(void 0);return}C.some(m=>m.name===f)||c(C[0].name)},[C,f]);const w=f,I=async()=>{try{const d=await i.mutateAsync({data:{}});b("all"),g(""),c(d.name)}catch{}};return!s||!a?e.jsx("div",{className:"p-8",children:t("providersLoading")}):e.jsxs(Ie,{children:[e.jsx($e,{title:t("providersPageTitle"),description:t("providersPageDescription")}),e.jsxs("div",{className:Ge,children:[e.jsxs("section",{className:Ve,children:[e.jsxs("div",{className:"border-b border-gray-100 px-4 pt-4 pb-3 space-y-3",children:[e.jsx(Qe,{tabs:L,activeTab:y,onChange:b,className:"mb-0"}),e.jsxs(T,{type:"button",variant:"outline",className:"w-full justify-center",onClick:I,disabled:i.isPending,children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),i.isPending?t("saving"):t("providerAddCustom")]})]}),e.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(Me,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx(K,{value:u,onChange:d=>g(d.target.value),placeholder:t("providersFilterPlaceholder"),className:"h-10 rounded-xl pl-9"})]})}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[C.map(d=>{var o;const m=s.providers[d.name],N=!!(m!=null&&m.apiKeySet),v=w===d.name,D=((o=m==null?void 0:m.displayName)==null?void 0:o.trim())||d.displayName||d.name,$=q(`providers.${d.name}`,p),k=(m==null?void 0:m.apiBase)||d.defaultApiBase||"",l=as(k)||($==null?void 0:$.help)||t("providersDefaultDescription");return e.jsx("button",{type:"button",onClick:()=>c(d.name),className:X("w-full rounded-xl border p-2.5 text-left transition-all",v?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Ue,{name:d.name,src:qe(d.name),className:X("h-10 w-10 rounded-lg border",N?"border-primary/30 bg-white":"border-gray-200/70 bg-white"),imgClassName:"h-5 w-5 object-contain",fallback:e.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500",children:d.name[0]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:D}),e.jsx("p",{className:"line-clamp-1 text-[11px] text-gray-500",children:l})]})]}),e.jsx(je,{status:N?"ready":"setup",label:N?t("statusReady"):t("statusSetup"),className:"min-w-[56px] justify-center"})]})},d.name)}),C.length===0&&e.jsxs("div",{className:"flex h-full min-h-[220px] flex-col items-center justify-center rounded-xl border border-dashed border-gray-200 bg-gray-50/70 py-10 text-center",children:[e.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-lg bg-white",children:e.jsx(Le,{className:"h-5 w-5 text-gray-300"})}),e.jsx("p",{className:"text-sm font-medium text-gray-700",children:t("providersNoMatch")})]})]})]}),e.jsx(ts,{providerName:w,onProviderDeleted:d=>{d===f&&c(void 0)}})]})]})}export{xs as ProvidersList};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as u,j as e,a7 as X,a5 as Y,ak as le,ae as Z}from"./vendor-DfLizrKM.js";import{u as ce,b as oe,m as de,I as d}from"./useConfig-DJ_KEVx0.js";import{P as ie,a as me,B as N}from"./page-layout-sZk-HtoA.js";import{C as B,a as M,b as O,c as R,d as $}from"./card-KmfXQ4Bm.js";import{S as he}from"./switch-BnYsX3uS.js";import{t,S as H,a as ee,b as ae,d as se,e as P}from"./index-BhpPLO5K.js";import{h as T}from"./config-hints-CApS3K_7.js";const ue=[{value:"main",label:"main"},{value:"per-peer",label:"per-peer"},{value:"per-channel-peer",label:"per-channel-peer"},{value:"per-account-channel-peer",label:"per-account-channel-peer"}];function pe(){return{id:"",default:!1,workspace:"",model:"",contextTokens:void 0,maxToolIterations:void 0}}function xe(){return{agentId:"",match:{channel:"",accountId:""}}}function te(i){const w=i.trim();if(!w)return;const p=Number.parseInt(w,10);return Number.isFinite(p)?p:void 0}function ye(){const{data:i,isLoading:w}=ce(),{data:p}=oe(),_=de(),[S,y]=u.useState([]),[z,b]=u.useState([]),[D,L]=u.useState("per-channel-peer"),[q,K]=u.useState(0),[F,V]=u.useState(2e5);u.useEffect(()=>{var a,r,n;i&&(y((i.agents.list??[]).map(s=>({id:s.id??"",default:!!s.default,workspace:s.workspace??"",model:s.model??"",contextTokens:s.contextTokens,maxToolIterations:s.maxToolIterations}))),b((i.bindings??[]).map(s=>{var c,l,o;return{agentId:s.agentId??"",match:{channel:((c=s.match)==null?void 0:c.channel)??"",accountId:((l=s.match)==null?void 0:l.accountId)??"",peer:(o=s.match)!=null&&o.peer?{kind:s.match.peer.kind,id:s.match.peer.id}:void 0}}})),L(((a=i.session)==null?void 0:a.dmScope)??"per-channel-peer"),K(((n=(r=i.session)==null?void 0:r.agentToAgent)==null?void 0:n.maxPingPongTurns)??0),V(i.agents.defaults.contextTokens??2e5))},[i]);const x=p==null?void 0:p.uiHints,h=T("session.dmScope",x),g=T("session.agentToAgent.maxPingPongTurns",x),j=T("agents.defaults.contextTokens",x),A=T("agents.list.*.contextTokens",x),f=T("agents.list",x),v=T("bindings",x),re=u.useMemo(()=>{const a=new Set(["main"]);return S.forEach(r=>{const n=r.id.trim();n&&a.add(n)}),a},[S]),I=(a,r)=>{y(n=>n.map((s,c)=>c===a?{...s,...r}:s))},k=(a,r)=>{b(n=>n.map((s,c)=>c===a?r:s))},ne=()=>{try{const a=S.map((s,c)=>{var m,C;const l=s.id.trim();if(!l)throw new Error(t("agentIdRequiredError").replace("{index}",String(c)));const o={id:l};return s.default&&(o.default=!0),(m=s.workspace)!=null&&m.trim()&&(o.workspace=s.workspace.trim()),(C=s.model)!=null&&C.trim()&&(o.model=s.model.trim()),typeof s.contextTokens=="number"&&(o.contextTokens=Math.max(1e3,s.contextTokens)),typeof s.maxToolIterations=="number"&&(o.maxToolIterations=s.maxToolIterations),o}),r=a.map(s=>s.id).filter((s,c,l)=>l.indexOf(s)!==c);if(r.length>0){Z.error(`${t("duplicateAgentId")}: ${r[0]}`);return}const n=z.map((s,c)=>{var G,J,Q,W;const l=s.agentId.trim(),o=s.match.channel.trim(),m=((G=s.match.accountId)==null?void 0:G.trim())??"",C=(J=s.match.peer)==null?void 0:J.kind,U=((W=(Q=s.match.peer)==null?void 0:Q.id)==null?void 0:W.trim())??"";if(!l)throw new Error(t("bindingAgentIdRequired").replace("{index}",String(c)));if(!re.has(l))throw new Error(`${t("bindingAgentIdNotFound").replace("{index}",String(c))}: ${l}`);if(!o)throw new Error(t("bindingChannelRequired").replace("{index}",String(c)));const E={agentId:l,match:{channel:o}};if(m&&(E.match.accountId=m),C){if(!U)throw new Error(t("bindingPeerIdRequired").replace("{index}",String(c)));E.match.peer={kind:C,id:U}}return E});_.mutate({data:{agents:{defaults:{contextTokens:Math.max(1e3,F)},list:a},bindings:n,session:{dmScope:D,agentToAgent:{maxPingPongTurns:Math.min(5,Math.max(0,q))}}}})}catch(a){const r=a instanceof Error?a.message:String(a);Z.error(r)}};return w||!i?e.jsx("div",{className:"p-8 text-gray-400",children:t("runtimeLoading")}):e.jsxs(ie,{className:"space-y-6",children:[e.jsx(me,{title:t("runtimePageTitle"),description:t("runtimePageDescription")}),e.jsxs(B,{children:[e.jsxs(M,{children:[e.jsx(O,{children:(h==null?void 0:h.label)??t("dmScope")}),e.jsx(R,{children:(h==null?void 0:h.help)??t("dmScopeHelp")})]}),e.jsxs($,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(j==null?void 0:j.label)??t("defaultContextTokens")}),e.jsx(d,{type:"number",min:1e3,step:1e3,value:F,onChange:a=>V(Math.max(1e3,Number.parseInt(a.target.value,10)||1e3))}),e.jsx("p",{className:"text-xs text-gray-500",children:(j==null?void 0:j.help)??t("defaultContextTokensHelp")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(h==null?void 0:h.label)??t("dmScope")}),e.jsxs(H,{value:D,onValueChange:a=>L(a),children:[e.jsx(ee,{children:e.jsx(ae,{})}),e.jsx(se,{children:ue.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(g==null?void 0:g.label)??t("maxPingPongTurns")}),e.jsx(d,{type:"number",min:0,max:5,value:q,onChange:a=>K(Math.max(0,Number.parseInt(a.target.value,10)||0))}),e.jsx("p",{className:"text-xs text-gray-500",children:(g==null?void 0:g.help)??t("maxPingPongTurnsHelp")})]})]})]}),e.jsxs(B,{children:[e.jsxs(M,{children:[e.jsx(O,{children:(f==null?void 0:f.label)??t("agentList")}),e.jsx(R,{children:(f==null?void 0:f.help)??t("agentListHelp")})]}),e.jsxs($,{className:"space-y-3",children:[S.map((a,r)=>e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(d,{value:a.id,onChange:n=>I(r,{id:n.target.value}),placeholder:t("agentIdPlaceholder")}),e.jsx(d,{value:a.workspace??"",onChange:n=>I(r,{workspace:n.target.value}),placeholder:t("workspaceOverridePlaceholder")}),e.jsx(d,{value:a.model??"",onChange:n=>I(r,{model:n.target.value}),placeholder:t("modelOverridePlaceholder")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsx(d,{type:"number",min:1e3,step:1e3,value:a.contextTokens??"",onChange:n=>I(r,{contextTokens:te(n.target.value)}),placeholder:(A==null?void 0:A.label)??t("contextTokensPlaceholder")}),e.jsx(d,{type:"number",min:1,value:a.maxToolIterations??"",onChange:n=>I(r,{maxToolIterations:te(n.target.value)}),placeholder:t("maxToolsPlaceholder")})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx(he,{checked:!!a.default,onCheckedChange:n=>{if(!n){I(r,{default:!1});return}y(s=>s.map((c,l)=>({...c,default:l===r})))}}),e.jsx("span",{children:t("defaultAgent")})]}),e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:()=>y(n=>n.filter((s,c)=>c!==r)),children:[e.jsx(X,{className:"h-4 w-4 mr-1"}),t("remove")]})]})]},`${r}-${a.id}`)),e.jsxs(N,{type:"button",variant:"outline",onClick:()=>y(a=>[...a,pe()]),children:[e.jsx(Y,{className:"h-4 w-4 mr-2"}),t("addAgent")]})]})]}),e.jsxs(B,{children:[e.jsxs(M,{children:[e.jsx(O,{children:(v==null?void 0:v.label)??t("bindings")}),e.jsx(R,{children:(v==null?void 0:v.help)??t("bindingsHelp")})]}),e.jsxs($,{className:"space-y-3",children:[z.map((a,r)=>{var s,c;const n=((s=a.match.peer)==null?void 0:s.kind)??"";return e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(d,{value:a.agentId,onChange:l=>k(r,{...a,agentId:l.target.value}),placeholder:t("targetAgentIdPlaceholder")}),e.jsx(d,{value:a.match.channel,onChange:l=>k(r,{...a,match:{...a.match,channel:l.target.value}}),placeholder:t("channelPlaceholder")}),e.jsx(d,{value:a.match.accountId??"",onChange:l=>k(r,{...a,match:{...a.match,accountId:l.target.value}}),placeholder:t("accountIdOptionalPlaceholder")}),e.jsxs(H,{value:n||"__none__",onValueChange:l=>{var m;const o=l==="__none__"?"":l;if(!o){k(r,{...a,match:{...a.match,peer:void 0}});return}k(r,{...a,match:{...a.match,peer:{kind:o,id:((m=a.match.peer)==null?void 0:m.id)??""}}})},children:[e.jsx(ee,{children:e.jsx(ae,{})}),e.jsxs(se,{children:[e.jsx(P,{value:"__none__",children:t("peerKindOptional")}),e.jsx(P,{value:"direct",children:"direct"}),e.jsx(P,{value:"group",children:"group"}),e.jsx(P,{value:"channel",children:"channel"})]})]}),e.jsx(d,{value:((c=a.match.peer)==null?void 0:c.id)??"",onChange:l=>k(r,{...a,match:{...a.match,peer:n?{kind:n,id:l.target.value}:void 0}}),placeholder:t("peerIdPlaceholder")})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:()=>b(l=>l.filter((o,m)=>m!==r)),children:[e.jsx(X,{className:"h-4 w-4 mr-1"}),t("remove")]})})]},`${r}-${a.agentId}`)}),e.jsxs(N,{type:"button",variant:"outline",onClick:()=>b(a=>[...a,xe()]),children:[e.jsx(Y,{className:"h-4 w-4 mr-2"}),t("addBinding")]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(N,{type:"button",onClick:ne,disabled:_.isPending,children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),_.isPending?t("saving"):t("saveRuntimeSettings")]})})]})}export{ye as RuntimeConfig};
|