@markus-global/cli 0.12.0-rc.2 → 0.12.0
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/dist/commands/start.js +1 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +3340 -3463
- package/dist/web-ui/assets/{AsyncState-D1MjBziR.js → AsyncState-Czik5FUM.js} +1 -1
- package/dist/web-ui/assets/{CommentInput-DoDCJB56.js → CommentInput-BsaOrj2g.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-BQ77yvOJ.js → ContentRenderer-Cl9-dJ-4.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-DvNGiVma.js → DeliverableShareModal-wgdeaboz.js} +1 -1
- package/dist/web-ui/assets/{Deliverables-z8y1RoIc.js → Deliverables-Czrn3ezy.js} +2 -2
- package/dist/web-ui/assets/{Notifications-D1IJbilh.js → Notifications-BoxombIH.js} +1 -1
- package/dist/web-ui/assets/{Search-n_NvkmUl.js → Search-D9FOOaVc.js} +1 -1
- package/dist/web-ui/assets/{SendToChat-C8yyyTBL.js → SendToChat-D95-I-fu.js} +1 -1
- package/dist/web-ui/assets/{Settings-D45ydMkM.js → Settings-DvknF2D-.js} +1 -1
- package/dist/web-ui/assets/{Store-C-lknVpt.js → Store-CVTUuEyr.js} +1 -1
- package/dist/web-ui/assets/{Switch-DAAFfXa0.js → Switch-CJm0Y6Ab.js} +1 -1
- package/dist/web-ui/assets/{Team-YRwejXFx.js → Team-CnQniCUA.js} +44 -44
- package/dist/web-ui/assets/{Work-CWxUln1b.js → Work-Dmxua6PP.js} +6 -6
- package/dist/web-ui/assets/{arc-DaVDBvVJ.js → arc-BLg_pCBM.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-RI4xfXsq.js → architectureDiagram-3BPJPVTR-Cmx-kPk8.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-3m9lt9Tv.js → blockDiagram-GPEHLZMM-C7M18dlD.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-C3uJ8ygg.js → c4Diagram-AAUBKEIU-Cfwl8fbI.js} +1 -1
- package/dist/web-ui/assets/channel-0w5HoIsN.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-BAFOp_1Q.js → chunk-2J33WTMH-C5mU_TTU.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-Dl4hewAE.js → chunk-4BX2VUAB-CQCbo-ag.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-BEZs165b.js → chunk-55IACEB6-4c3wqJwT.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-D40hw6dx.js → chunk-727SXJPM-DXdlGwqz.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-Db0w70qS.js → chunk-AQP2D5EJ-K192souI.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-DSXWhRDm.js → chunk-FMBD7UC4-D5Q3CYrz.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-DHMvwtzx.js → chunk-ND2GUHAM-qNuRMI8p.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-CzsZVugR.js → chunk-QZHKN3VN-BkmKoVv4.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C7BIpwAA.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C7BIpwAA.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-Dp3zgnT2.js → cose-bilkent-S5V4N54A-Cc-LCylz.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-IbXphJ2p.js → dagre-BM42HDAG-CcbGFoMh.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-Dr80j8n6.js → diagram-2AECGRRQ-BMK1aNmF.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-BarMHyaM.js → diagram-5GNKFQAL-DLZ1Dlob.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-BLxNHwEs.js → diagram-KO2AKTUF-DgF4N3Vp.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-dpjJXsFX.js → diagram-LMA3HP47-Dj6Rsgtz.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-B-AZz5xs.js → diagram-OG6HWLK6-B33vd8GS.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-B9xb3lVY.js → docx-preview-Cbe9vyIJ.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-b55Ez0GT.js → erDiagram-TEJ5UH35-C0ArR1aG.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-C-7BGCm3.js → flowDiagram-I6XJVG4X-wdN-ujEZ.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BW47InmE.js → ganttDiagram-6RSMTGT7-BUKw6wm1.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-YmWaJOLB.js → gitGraphDiagram-PVQCEYII-DU3TBBvN.js} +1 -1
- package/dist/web-ui/assets/index-Ci5bUF3m.js +883 -0
- package/dist/web-ui/assets/{index-DD3NMntN.css → index-D4zDaGe4.css} +1 -1
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-BYnK_hKC.js → infoDiagram-5YYISTIA-Dk634Bq4.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-FJ8nEqaM.js → ishikawaDiagram-YF4QCWOH-BE5upFcq.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-Ufh7z6pn.js → journeyDiagram-JHISSGLW-C_fU89IU.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-BKU0dWlO.js → kanban-definition-UN3LZRKU-DCPTTiVV.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-sMPs34mJ.js → mermaid.core-CwgDshh9.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-Csa43MLU.js → mindmap-definition-RKZ34NQL-B1O4o7mE.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CUdusImI.js → pieDiagram-4H26LBE5-HKc1yZ37.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-DL80bobR.js → quadrantDiagram-W4KKPZXB-DSJ8Nt1Y.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-1b7FWXut.js → requirementDiagram-4Y6WPE33-Bnk4zXkX.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-D5bCHLyF.js → sankeyDiagram-5OEKKPKP-DW5T8bfU.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CwbH4Qmn.js → sequenceDiagram-3UESZ5HK-D80T-VQ2.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-BBseKBV0.js → stateDiagram-AJRCARHV-DbMI2WnT.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BxYWXdlm.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-Pamw3ZAk.js → timeline-definition-PNZ67QCA-m1796nxN.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-BRlYubXq.js → vennDiagram-CIIHVFJN-uQ9kkGtM.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-Cpejr3QL.js → wardley-L42UT6IY-Bwp548d-.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-D9mX9POT.js → wardleyDiagram-YWT4CUSO-D1Dcm5Tb.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-BZMvL0gm.js → xychartDiagram-2RQKCTM6-CRhoH3Re.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/architecture/mailbox-audit-checklist.md +194 -0
- package/docs/architecture/mailbox-system.md +374 -74
- package/docs/records/page-switch-jank-2026-10-23.md +174 -0
- package/package.json +1 -1
- package/dist/web-ui/assets/channel-BSxKSPBW.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BXPDTPh-.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BXPDTPh-.js +0 -1
- package/dist/web-ui/assets/index-tXN2M_eu.js +0 -883
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-jcfX_Wlv.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{u as xe,r as o,j as e,J as fs,l as F,k as ti,y as si,a0 as ri,a1 as ni,h as Ot,a2 as oa,a3 as ai,a4 as ii,w as oi,a5 as li,v as la,a6 as di,a7 as ci,a8 as ui,a9 as dn,aa as mi,n as ms,P as br,_ as xi,ab as gi,a as fi,b as pi,c as hi,ac as cn,ad as bi,ae as un,i as yi,o as Us}from"./index-tXN2M_eu.js";import{L as vi}from"./AsyncState-D1MjBziR.js";import{i as ji,S as bs}from"./Switch-DAAFfXa0.js";function Ni(t,r){for(var i=0;i<r.length;i++){const a=r[i];if(typeof a!="string"&&!Array.isArray(a)){for(const n in a)if(n!=="default"&&!(n in t)){const s=Object.getOwnPropertyDescriptor(a,n);s&&Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>a[n]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}function wi(t){return t>=1e6?`${(t/1e6).toFixed(t%1e6===0?0:1)}M`:t>=1e3?`${(t/1e3).toFixed((t%1e3===0,0))}K`:String(t)}function ki(t){return t.maxInputTokens>0||t.inputCostPer1MTokens>0||t.outputCostPer1MTokens>0}function Ks(t){if(t.tier)return t.tier;const r=t.id.toLowerCase(),i=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,a=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;return/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(r)?"pro":i.test(r)?"max":a.test(r)?"base":"pro"}const mn={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30"};function da({models:t,selectedModel:r,onSelect:i,loading:a,compact:n,maxVisible:s,showTiers:c}){const{t:d}=xe("settings"),[u,p]=o.useState(""),[x,k]=o.useState(!1),[y,j]=o.useState(""),w=o.useMemo(()=>{let m=t;if(u){const v=u.toLowerCase();m=m.filter($=>$.id.toLowerCase().includes(v))}return y&&(m=m.filter(v=>Ks(v)===y)),m},[t,u,y]),b=o.useMemo(()=>{const m={max:0,pro:0,base:0};for(const v of t)m[Ks(v)]++;return m},[t]),S=s??(n?5:10),h=x?w:w.slice(0,S),P=w.length>S;return a?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),d("modelPicker.loading")]}):t.length===0?e.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:d("modelPicker.empty")}):e.jsxs("div",{className:"space-y-2",children:[c&&t.length>3&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>j(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${y?"bg-surface-overlay text-fg-tertiary hover:text-fg-secondary":"bg-brand-500/20 text-brand-500"}`,children:d("modelPicker.allCount",{count:t.length})}),["max","pro","base"].filter(m=>b[m]>0).map(m=>e.jsx("button",{onClick:()=>j(y===m?"":m),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${y===m?mn[m]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:d("modelPicker.tierCount",{tier:d(`modelRouting.tier.${m}`),count:b[m]})},m))]}),t.length>5&&e.jsx("input",{type:"text",value:u,onChange:m=>{p(m.target.value),k(!1)},placeholder:d("modelPicker.filterPlaceholder"),className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),e.jsx("div",{className:`space-y-1 ${n?"max-h-[280px] overflow-y-auto":""}`,children:h.map(m=>{const v=m.id===r,$=Ks(m);return e.jsxs("button",{type:"button",onClick:()=>i(m.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${v?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${v?"border-brand-500":"border-border-default"}`,children:v&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${v?"text-brand-500":"text-fg-primary"}`,children:m.id}),c&&e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase border ${mn[$]}`,children:d(`modelRouting.tier.${$}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:v&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:d("modelPicker.active")})})]}),ki(m)&&m.maxInputTokens>0&&e.jsx("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:e.jsxs("span",{children:[wi(m.maxInputTokens)," ",d("modelPicker.ctx")]})}),!n&&e.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[m.capabilities.functionCalling&&e.jsx(Et,{label:d("modelPicker.capabilities.tools")}),m.capabilities.vision&&e.jsx(Et,{label:d("modelPicker.capabilities.vision")}),m.capabilities.reasoning&&e.jsx(Et,{label:d("modelPicker.capabilities.reasoning")}),m.capabilities.promptCaching&&e.jsx(Et,{label:d("modelPicker.capabilities.caching")}),m.capabilities.webSearch&&e.jsx(Et,{label:d("modelPicker.capabilities.search")})]})]},m.id)})}),P&&!x&&e.jsx("button",{type:"button",onClick:()=>k(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:d("modelPicker.showAll",{count:w.length})}),x&&P&&e.jsx("button",{type:"button",onClick:()=>k(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:d("modelPicker.showLess")})]})}function Et({label:t}){return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:t})}function Vt({value:t,options:r,placeholder:i,onChange:a}){const{t:n}=xe("settings"),[s,c]=o.useState(!1),[d,u]=o.useState(""),p=o.useRef(null),x=o.useRef(null),k=o.useRef(null),[y,j]=o.useState(-1);o.useEffect(()=>{function m(v){p.current&&!p.current.contains(v.target)&&c(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]),o.useEffect(()=>{s&&x.current&&x.current.focus()},[s]);const w=o.useMemo(()=>{if(!d.trim())return r;const m=d.toLowerCase();return r.filter(v=>v.modelId.toLowerCase().includes(m)||v.modelName.toLowerCase().includes(m)||v.provider.toLowerCase().includes(m)||v.providerLabel.toLowerCase().includes(m)||v.tier&&v.tier.toLowerCase().includes(m))},[r,d]),b=o.useMemo(()=>{const m=new Map;for(const $ of w){const I=$.providerLabel;m.has(I)||m.set(I,[]),m.get(I).push($)}const v={max:0,pro:1,base:2};for(const $ of m.values())$.sort((I,R)=>(v[I.tier??"base"]??9)-(v[R.tier??"base"]??9));return m},[w]),S=o.useMemo(()=>{const m=[];for(const v of b.values())m.push(...v);return m},[b]),h=o.useMemo(()=>{if(!t)return i??n("modelRouting.auto");const m=r.find(v=>`${v.provider}/${v.modelId}`===t);return m?`${m.providerLabel}/${m.modelName}`:t},[t,r,i,n]);function P(m){if(!s){(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),c(!0));return}switch(m.key){case"ArrowDown":m.preventDefault(),j(v=>Math.min(v+1,S.length-1));break;case"ArrowUp":m.preventDefault(),j(v=>Math.max(v-1,-1));break;case"Enter":m.preventDefault(),y===-1?a(""):S[y]&&a(`${S[y].provider}/${S[y].modelId}`),c(!1),u("");break;case"Escape":c(!1),u("");break}}return o.useEffect(()=>{k.current&&y>=0&&k.current.querySelector(`[data-focus-index="${y}"]`)?.scrollIntoView({block:"nearest"})},[y]),e.jsxs("div",{ref:p,className:"relative min-w-0",onKeyDown:P,children:[e.jsx("button",{type:"button",onClick:()=>{c(!s),u(""),j(-1)},className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary text-left truncate focus:outline-none focus:border-brand-500",children:h}),s&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full min-w-[240px] max-h-[280px] bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden flex flex-col",children:[e.jsx("div",{className:"p-1.5 border-b border-border-default",children:e.jsx("input",{ref:x,type:"text",value:d,onChange:m=>{u(m.target.value),j(-1)},placeholder:n("modelPicker.searchPlaceholder")||"Search models...",className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary focus:outline-none focus:border-brand-500"})}),e.jsxs("div",{ref:k,className:"overflow-y-auto flex-1",children:[e.jsx("div",{className:`px-3 py-1.5 text-xs cursor-pointer ${y===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{a(""),c(!1),u("")},children:i??n("modelRouting.auto")}),[...b.entries()].map(([m,v])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider bg-surface-overlay/50 sticky top-0",children:m}),v.map($=>{const I=S.indexOf($),R=`${$.provider}/${$.modelId}`===t;return e.jsxs("div",{"data-focus-index":I,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${I===y?"bg-brand-500/20":R?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,onClick:()=>{a(`${$.provider}/${$.modelId}`),c(!1),u("")},children:[e.jsx("span",{className:"flex-1 truncate text-fg-primary",children:$.modelName}),$.tier&&e.jsx(Ci,{tier:$.tier}),$.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:$.costTier})]},`${$.provider}/${$.modelId}`)})]},m)),S.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:n("modelPicker.empty")})]})]})]})}function Ci({tier:t}){const r={max:"bg-purple-500/20 text-purple-400",pro:"bg-blue-500/20 text-blue-400",base:"bg-gray-500/20 text-gray-400"};return e.jsx("span",{className:`px-1 py-0.5 rounded text-[8px] font-bold uppercase ${r[t]??r.base}`,children:t})}const Si=500,xn=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function Ai({onSave:t,configuredProviders:r}){const{t:i}=xe(["settings","common"]),[a,n]=o.useState({}),[s,c]=o.useState(null),[d,u]=o.useState(!1),[p,x]=o.useState(null),[k,y]=o.useState(!0),[j,w]=o.useState("idle"),[b,S]=o.useState(null),[h,P]=o.useState({}),[m,v]=o.useState(!1),[$,I]=o.useState("idle"),[R,V]=o.useState(null),[C,M]=o.useState(!1),B=o.useRef(null),L=o.useRef(null),U=o.useMemo(()=>r.map(g=>g.name).sort().join(","),[r]);o.useEffect(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{n(g.capabilityRouting?.assignments??{}),c(g.routingDefaultModel??null),u(!0)}).catch(g=>{x(String(g)),u(!0)})},[U]),o.useEffect(()=>{let g=!1;return y(!0),fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{if(g)return;const f=[];for(const K of T.providers)for(const z of K.models)f.push({provider:K.provider,providerLabel:K.displayName,modelId:z.id,modelName:z.name,mode:z.mode,tier:z.tier,costTier:z.costTier,capabilities:z.capabilities});S(f)}).catch(()=>{g||S(null)}).finally(()=>{g||y(!1)}),()=>{g=!0}},[U]),o.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{P(g.suggestions),v(!0)}).catch(()=>v(!0))},[U]);const H=o.useCallback(g=>{w("saving"),t(g).then(()=>{w("saved"),setTimeout(()=>w(T=>T==="saved"?"idle":T),2e3)}).catch(()=>{w("error"),setTimeout(()=>w(T=>T==="error"?"idle":T),3e3)})},[t]),W=o.useCallback((g,T)=>{L.current={capabilityRouting:g!==void 0?{assignments:g}:L.current?.capabilityRouting,routingDefaultModel:T!==void 0?T:L.current?.routingDefaultModel},B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{const f=L.current;L.current=null,f&&H(f)},Si)},[H]),O=o.useMemo(()=>r.flatMap(g=>(g.models??[{id:g.model,name:g.model}]).map(T=>({provider:g.name,providerLabel:g.displayName??g.name,modelId:T.id,modelName:T.name}))),[r]),_=b??O,X=o.useMemo(()=>Object.entries(a).map(([g,T])=>`${g}:${T?.provider??""}/${T?.model??""}`).sort().join("|"),[a]);o.useEffect(()=>{!d||!b||b.length===0||b.some(g=>!!g.modelId)&&(n(g=>{let T=!1;const f={...g};for(const K of xn)for(const z of K.capabilities){const se=f[z];if(!se?.model)continue;const ae=ca(b,z);if(ae.length===0)continue;ae.some(te=>te.provider===se.provider&&te.modelId===se.model)||(delete f[z],T=!0)}return T?(W(f),f):g}),c(g=>{if(!g?.model||b.some(z=>z.provider===g.provider&&z.modelId===g.model))return g;const f=b.find(z=>z.provider==="markus"),K=f?{provider:f.provider,model:f.modelId}:{provider:b[0].provider,model:b[0].modelId};return t({routingDefaultModel:K}),K}))},[d,b,U,W,X]);const ce=o.useCallback(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{n(g.capabilityRouting?.assignments??{}),c(g.routingDefaultModel??null)}).catch(()=>{}),y(!0),fetch("/api/models/routing-candidates",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{const T=[];for(const f of g.providers)for(const K of f.models)T.push({provider:f.provider,providerLabel:f.displayName,modelId:K.id,modelName:K.name,mode:K.mode,tier:K.tier,costTier:K.costTier,capabilities:K.capabilities});S(T)}).catch(()=>{}).finally(()=>y(!1))},[]),oe=o.useCallback(async()=>{if($!=="working"){I("working"),V(null);try{const g=await fetch("/api/settings/llm/restore-recommended",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),T=await g.json().catch(()=>({}));if(!g.ok||!T.ok)throw new Error(T.error??`HTTP ${g.status}`);T.capabilityRouting&&n(T.capabilityRouting.assignments??{}),T.routingDefaultModel!==void 0&&c(T.routingDefaultModel),ce(),I("idle"),w("saved"),setTimeout(()=>w(f=>f==="saved"?"idle":f),2e3)}catch(g){I("error"),V(g instanceof Error?g.message:String(g)),setTimeout(()=>I("idle"),4e3)}}},[$,ce]),ee=_.length>0;return d?p?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:i("modelRouting.loadError",{error:p})}):k&&!ee?e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-secondary",children:[e.jsxs("svg",{className:"w-4 h-4 animate-spin text-brand-500",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),e.jsx("span",{children:i("modelRouting.loadingModels")})]})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Ti,{status:j,t:i}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>M(!0),disabled:$==="working",className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500/40 disabled:opacity-50 transition-colors",children:i($==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),R&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:R})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Vt,{value:s?`${s.provider}/${s.model}`:"",options:_,placeholder:i("modelRouting.defaultModelPlaceholder"),onChange:g=>{if(!g)c(null),W(void 0,null);else{const[T,...f]=g.split("/"),K={provider:T,model:f.join("/")};if(c(K),a.text){const z={...a};delete z.text,n(z),W(z,K)}else W(void 0,K)}}})})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.capabilityAssignDesc")})]}),r.length===0&&e.jsx("div",{className:"p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg text-xs text-yellow-400",children:i("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:xn.map(g=>e.jsx(Pi,{groupKey:g.groupKey,capabilities:g.capabilities,assignments:a,suggestions:h,allModels:_,configuredProviderNames:new Set(r.map(T=>T.name)),t:i,onAssign:(T,f)=>{const K={...a};f?K[T]=f:delete K[T],n(K),W(K)}},g.groupKey))})]}),C&&e.jsx(fs,{variant:"primary",title:i("modelRouting.restoreRecommended"),message:i("modelRouting.restoreConfirm"),confirmLabel:i("common:confirm"),onConfirm:()=>{M(!1),oe()},onCancel:()=>M(!1)})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-surface-overlay rounded w-1/3 mb-3"}),e.jsx("div",{className:"h-3 bg-surface-overlay rounded w-2/3 mb-4"}),e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(g=>e.jsx("div",{className:"h-10 bg-surface-overlay rounded-lg"},g))})]})})}function Pi({groupKey:t,capabilities:r,assignments:i,suggestions:a,allModels:n,configuredProviderNames:s,t:c,onAssign:d}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 px-1",children:c(`modelRouting.capabilityGroups.${t}`)}),e.jsx("div",{className:"space-y-1",children:r.map(u=>{const p=i[u],x=a[u],k=p?`${p.provider}/${p.model}`:"",y=ca(n,u),j=x?y.find(P=>P.provider===x.provider&&P.modelId===x.model)?.modelName??x.model:void 0,w=y.length>0,b=p?Mi(n,p.provider,p.model):void 0,S=p&&!s.has(p.provider),h=!!(p&&w&&u!=="text"&&!y.some(P=>P.provider===p.provider&&P.modelId===p.model));return e.jsxs("div",{className:`flex flex-wrap items-center gap-2 px-3 py-2 rounded-lg md:flex-nowrap md:gap-3 ${h?"bg-red-500/10 border border-red-500/30":S?"bg-yellow-500/10 border border-yellow-500/30":!w&&!p?"bg-amber-500/5 border border-amber-500/20":"bg-surface-overlay/40"}`,children:[e.jsx("div",{className:"w-full shrink-0 md:w-28",children:e.jsx("span",{className:"text-xs text-fg-primary",children:c(`modelRouting.capabilities.${u}`)})}),e.jsx("div",{className:"flex-1 min-w-0",children:h?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs text-red-400",children:["⚠ ",p.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:c("modelRouting.mismatchHint")})]}),e.jsx(Vt,{value:"",options:y,placeholder:c("modelRouting.selectModel"),onChange:P=>{if(!P)d(u,null);else{const[m,...v]=P.split("/");d(u,{provider:m,model:v.join("/")})}}})]}):w?e.jsx(Vt,{value:k,options:y,placeholder:j?`${j} (${c("modelRouting.suggested")})`:c("modelRouting.selectModel"),onChange:P=>{if(!P)d(u,null);else{const[m,...v]=P.split("/");d(u,{provider:m,model:v.join("/")})}}}):e.jsxs("span",{className:"text-xs text-amber-400",children:[c("modelRouting.noModelAvailable"),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",c("modelRouting.addProviderHint")]})]})}),e.jsxs("div",{className:"w-14 shrink-0 flex justify-end",children:[h&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:c("modelRouting.mismatchHint"),children:"⚠"}),!h&&S&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:c("modelRouting.staleProvider"),children:"⚠"}),!h&&!S&&b&&e.jsx(gn,{tier:b}),!h&&!S&&!b&&p&&e.jsx(gn,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:p&&e.jsx("button",{onClick:()=>d(u,null),className:"text-fg-tertiary hover:text-red-400 transition-colors",title:c("modelRouting.clear"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]},u)})})]})}function Mi(t,r,i){return t.find(n=>n.provider===r&&n.modelId===i)?.tier}function Ti({status:t,t:r}){if(t==="idle")return null;const i={idle:"",saving:"text-fg-tertiary",saved:"text-green-400",error:"text-red-400"},a={idle:"",saving:r("modelRouting.saving"),saved:r("modelRouting.saved"),error:r("modelRouting.saveError")};return e.jsx("div",{className:`text-xs font-medium transition-opacity ${i[t]}`,children:a[t]})}function gn({tier:t}){const r={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30",unknown:"bg-gray-500/10 text-fg-tertiary border-border-default"};return e.jsx("span",{className:`px-1.5 py-0.5 text-[9px] rounded font-semibold uppercase border ${r[t]??r.unknown}`,children:t==="unknown"?"—":t})}function ca(t,r){if(r==="text")return t.filter(c=>ji(c));const i={image_generation:["image_generation"],audio_tts:["audio_speech"],audio_stt:["audio_transcription"],video_generation:["video_generation"]},a={image_recognition:["vision"],image_generation:["imageGeneration"],audio_tts:["tts"],audio_stt:["stt"],video_generation:["videoGeneration"]},n=i[r],s=a[r];return t.filter(c=>!!(c.capabilities&&c.capabilities.length>0&&s&&s.some(d=>c.capabilities.includes(d))||n&&c.mode&&n.includes(c.mode)))}function Ei({configuredProviders:t}){const{t:r}=xe("settings"),[i,a]=o.useState(null),[n,s]=o.useState([]),[c,d]=o.useState(null),[u,p]=o.useState(null),x=o.useMemo(()=>t.map(b=>`${b.name}:${b.models?.length??0}`).sort().join(","),[t]),k=o.useCallback(async()=>{d(null);try{const[{agents:b},S]=await Promise.all([F.agents.list({lean:!0}),F.teams.list()]),h=S.teams.map(m=>({id:m.id,name:m.name}));s(h);const P=await Promise.all(b.map(async m=>{try{const $=(await F.agents.get(m.id)).config?.llmConfig;return{id:m.id,name:m.name||m.id,teamId:m.teamId,override:$?.modelMode==="custom"&&$.primary&&$.defaultModel?`${$.primary}/${$.defaultModel}`:null,llmConfig:{modelMode:$?.modelMode,primary:$?.primary??"",defaultModel:$?.defaultModel}}}catch{return{id:m.id,name:m.name||m.id,teamId:m.teamId,override:null,llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}}}}));a(b.length?P:null)}catch(b){d(String(b))}},[x]);o.useEffect(()=>{k()},[k,x]);const y=o.useMemo(()=>{const b=[];for(const S of t)for(const h of S.models??[])b.push({provider:S.name,providerLabel:S.displayName??S.name,modelId:h.id,modelName:h.name??h.id});return b},[t]),j=async(b,S)=>{p(b),d(null);try{if(S){const[h,P]=[S.slice(0,S.lastIndexOf("/")),S.slice(S.lastIndexOf("/")+1)];await F.agents.updateConfig(b,{llmConfig:{modelMode:"custom",primary:h,defaultModel:P}})}else await F.agents.updateConfig(b,{llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}});a(h=>h?.map(P=>P.id===b?{...P,override:S}:P)??h)}catch(h){d(String(h))}finally{p(null)}},w=o.useMemo(()=>{if(!i)return[];const b=new Map,S=[];for(const P of i)if(P.teamId){const m=b.get(P.teamId)??[];m.push(P),b.set(P.teamId,m)}else S.push(P);const h=[];S.length&&h.push({key:"ungrouped",label:r("perAgentModel.ungrouped",{defaultValue:"Ungrouped"}),rows:S});for(const P of n){const m=b.get(P.id);m?.length&&h.push({key:`team:${P.id}`,label:P.name,rows:m})}for(const[P,m]of b)n.some(v=>v.id===P)||h.push({key:`team:${P}`,label:P,rows:m});return h},[i,n,r]);return i===null&&!c?e.jsx("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 text-sm text-fg-tertiary",children:r("common:loading",{defaultValue:"Loading…"})}):e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:r("perAgentModel.title",{defaultValue:"Per-agent default model"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r("perAgentModel.desc",{defaultValue:'Bind a specific provider+model to an agent, or leave it following the global default. This is what the composer "Apply to current agent" writes.'})})]})}),c&&e.jsx("div",{className:"text-xs text-red-500",children:c}),(!i||i.length===0)&&!c&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:r("perAgentModel.noAgents",{defaultValue:"No agents available."})}),i&&i.length>0&&e.jsx("div",{className:"space-y-5",children:w.map(b=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary truncate",children:b.label}),e.jsx("span",{className:"text-[10px] text-fg-tertiary/70 tabular-nums shrink-0",children:b.rows.length})]}),e.jsx("div",{className:"space-y-2",children:b.rows.map(S=>e.jsxs("div",{className:"flex flex-col gap-2 text-sm md:flex-row md:items-center md:justify-between md:gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:S.name}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 truncate",children:S.id})]}),e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2 md:w-[320px]",children:[S.override?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{value:S.override,options:y,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:h=>{j(S.id,h||null)}}),e.jsx("button",{type:"button",disabled:u===S.id,onClick:()=>{j(S.id,null)},className:"shrink-0 px-2.5 py-1.5 text-xs border border-border-default rounded-lg hover:bg-surface-base disabled:opacity-40 transition-colors",children:r("perAgentModel.reset",{defaultValue:"Reset"})})]}):e.jsx(Vt,{value:"",options:y,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:h=>{j(S.id,h||null)}}),u===S.id&&e.jsx("span",{className:"shrink-0 text-[10px] text-fg-tertiary",children:r("common:loading",{defaultValue:"…"})})]})]},S.id))})]},b.key))})]})}let xs=[],ls=null;async function Li(){return ls||(ls=(async()=>{try{xs=(await F.modelCatalog.providerCatalog()).providers??[]}catch{xs=[]}return xs})(),ls)}function Ri(){const[t,r]=o.useState(xs);return o.useEffect(()=>{let i=!0;return Li().then(a=>{i&&r(a)}),()=>{i=!1}},[]),t}const Ii="integrations.platforms",kr=(t,r)=>`settings:${Ii}.${t}.${r}`,Bi={feishu:"https://open.feishu.cn/app",telegram:"https://t.me/BotFather",slack:"https://api.slack.com/apps",whatsapp:"https://developers.facebook.com/apps",discord:"https://discord.com/developers/applications"};function Di(t){return Bi[t]}function Oi(t,r){return t(kr(r.id,"label"),{defaultValue:r.label})}function ua(t,r,i){const a=kr(r,`fields.${i.key}`);return{label:t(`${a}.label`,{defaultValue:i.label}),help:i.help?t(`${a}.help`,{defaultValue:i.help}):void 0,placeholder:i.placeholder?t(`${a}.placeholder`,{defaultValue:i.placeholder}):void 0,options:i.options?.map(n=>({value:n.value,label:t(`${a}.options.${n.value}`,{defaultValue:n.label})}))}}function $i(t,r,i){const a=[],n=kr(i,"guide");for(let s=1;s<=20;s+=1){const c=`${n}.step${s}.title`;if(!t.exists(c))break;const d=`${n}.step${s}.desc`,u=t.exists(d)?r(d):void 0;a.push({title:r(c),...u?{desc:u}:{}})}return a}function Vi(t){return t("settings:integrations.guide.heading",{defaultValue:"Setup guide"})}function _i(t){return t.type==="boolean"?t.default===!0:t.multiple?Array.isArray(t.default)?[...t.default]:[]:t.default!==void 0?t.default:""}function ps(t,r){return r==null?!0:t.type==="boolean"?!1:t.multiple?!Array.isArray(r)||r.length===0:typeof r=="string"?r.trim()==="":!1}function fn(t){const r={};for(const i of t.fields){if(i.secret){r[i.key]="";continue}const a=t.values[i.key];r[i.key]=a??_i(i)}return r}function pn(t,r,i={}){const a=[];for(const n of t)if(n.required){if(n.secret){if(!ps(n,r[n.key]))continue;i[n.key]?.hasValue||a.push(n.key);continue}ps(n,r[n.key])&&a.push(n.key)}return a}function Fi(t,r,i){const a={enabled:i};for(const n of t.fields){const s=r[n.key];if(n.secret){if(ps(n,s))continue;a[n.key]=s;continue}s!==void 0&&(a[n.key]=s)}return a}function Ui(t){return t.filter(r=>r.required||r.type==="agent")}function Ki(t){return t.filter(r=>!(r.required||r.type==="agent"))}function yr(t){return Array.isArray(t)?`[${t.map(yr).join(",")}]`:t&&typeof t=="object"?`{${Object.entries(t).filter(([,i])=>i!==void 0).sort(([i],[a])=>i<a?-1:i>a?1:0).map(([i,a])=>`${JSON.stringify(i)}:${yr(a)}`).join(",")}}`:JSON.stringify(t)??"null"}function Hi(t){return yr({id:t.id,enabled:t.enabled,fields:t.fields.map(r=>({key:r.key,type:r.type,required:r.required,secret:r.secret===!0,multiple:r.multiple===!0,default:r.default??null,value:r.secret?!1:t.values[r.key]??null,hasValue:r.secret?t.secrets[r.key]?.hasValue===!0:!1}))})}function zi(t){const r=t.ok===!0||t.success===!0;return{ok:r,text:t.message??t.error??(r?"OK":"Failed"),code:t.code}}function qi(t){return t?.status==="awaiting_reply"||t?.status==="awaiting_inbound"}function Wi(t,r=!1){return t.hasConfig?t.enabled?t.lastVerifiedAt||r?"verified":"unverified":"off":"unconfigured"}function Gi(t){return{id:"",platform:t.id,label:"",enabled:!0,connected:!1,hasConfig:!1,capabilities:t.capabilities,fields:t.fields,values:{},secrets:Ji(t.fields),agentId:null,notifyAgentId:null,channels:[],lastError:null,canListChannels:!1,lastVerifiedAt:null}}function Ji(t){const r={};for(const i of t)i.secret&&(r[i.key]={hasValue:!1});return r}function Yi(t){return t.id===""}function hn(t){return{id:t.platform,label:t.label,capabilities:t.capabilities,fields:t.fields,defaultEnabled:!1,enabled:t.enabled,connected:t.connected,hasConfig:t.hasConfig,values:{...t.values,agentId:t.agentId??""},secrets:t.secrets}}function Hs(t,r){return t.find(i=>i.nativeId===r)}function bn(t,r,i,a){const n=t.filter(s=>s.nativeId!==r);return n.push({nativeId:r,kind:a??null,agentId:i}),n.sort((s,c)=>s.nativeId.localeCompare(c.nativeId))}function yn(t,r){return t.filter(i=>i.nativeId!==r)}function Qi(t,r){const i=new Set(r.map(a=>a.id));return t.filter(a=>!i.has(a.nativeId))}function Zi(t,r){const i=r.trim().toLowerCase();return i?t.filter(a=>a.name.toLowerCase().includes(i)||a.id.toLowerCase().includes(i)):t}function Xi(t){const r=new Map;for(const i of t){const a=r.get(i.platform);a?a.push(i):r.set(i.platform,[i])}return[...r.entries()].map(([i,a])=>({platform:i,instances:a}))}function eo(t,r,i={}){const a=i.devMode??!1,n=new Set(t.filter(d=>d.devOnly&&!a).map(d=>d.id)),s=[],c=new Set;for(const d of t)n.has(d.id)||c.has(d.id)||(c.add(d.id),s.push(d.id));for(const d of r)n.has(d.platform)||c.has(d.platform)||(c.add(d.platform),s.push(d.platform));return s}function to(t,r,i){const[a,n]=o.useState([]),[s,c]=o.useState(null),[d,u]=o.useState(!1),p=o.useRef(t);p.current=t;const x=o.useRef(0),k=o.useCallback(()=>{if(!i||!r)return;const y=++x.current;u(!0),p.current(r).then(j=>{y===x.current&&(n(j.channels??[]),c(j.error??null))}).catch(j=>{y===x.current&&(n([]),c(j instanceof Error?j.message:String(j)))}).finally(()=>{y===x.current&&u(!1)})},[i,r]);return o.useEffect(()=>(k(),()=>{x.current+=1}),[k]),{channels:a,error:s,loading:d,reloadChannels:k}}const ma=/^notify[A-Z]/,xa="notifyEnabled";function so(t){return t.find(r=>r.key===xa)}function ro(t){return t.notifyTarget==="chat"||t.notifyTarget==="user"||ma.test(t.key)}function _t(t){return t.filter(r=>r.notifyTarget==="chat"||r.notifyTarget==="user")}function no(t){return t.filter(r=>!r.notifyTarget&&!r.secret&&r.key!==xa&&ma.test(r.key))}function ao(t){return t.filter(ro)}function ga(t){return _t(t).find(r=>r.notifyTarget==="chat")}function io(t,r){const i=_t(t);return i.length===0?"unsupported":i.some(a=>!ps(a,r[a.key]))?"configured":"not-configured"}function vn(t){return typeof t=="string"?{value:t,label:t}:{value:t.value,label:t.label??t.value,hint:t.hint}}function jn(t,r,i){const a=t.label.toLowerCase(),n=t.value.toLowerCase(),s=`${a} ${n} ${(t.hint??"").toLowerCase()}`;for(const d of r)if(!s.includes(d))return null;if(a.startsWith(i)||n.startsWith(i))return 0;const c=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[\\s./:_-])${c}`).test(a)?1:2}function fa({value:t,options:r,onChange:i,placeholder:a,filterPlaceholder:n,emptyText:s,customHint:c,disabled:d,ariaLabel:u,className:p}){const[x,k]=o.useState(!1),[y,j]=o.useState(""),[w,b]=o.useState(!1),[S,h]=o.useState(-1),P=o.useRef(null),m=o.useRef(null),v=o.useRef(null),$=o.useRef(null),I=o.useId(),[R,V]=o.useState({}),C=o.useMemo(()=>t?r.map(vn).find(O=>O.value===t)?.label??t:a??"",[t,r,a]);o.useEffect(()=>{x||(j(C),b(!1))},[C,x]),o.useEffect(()=>{function O(_){const X=_.target;$.current?.contains(X)||P.current&&!P.current.contains(X)&&k(!1)}return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[]);function M(){const O=m.current;if(!O)return;const _=O.getBoundingClientRect(),X=Math.max(_.width,240),ce=window.innerHeight-_.bottom-8,oe=ce<180&&_.top>ce;V({position:"fixed",left:_.left,width:X,maxHeight:Math.min(260,oe?Math.max(_.top-12,120):ce),...oe?{bottom:window.innerHeight-_.top+4}:{top:_.bottom+4}})}o.useLayoutEffect(()=>{if(!x)return;M();const O=()=>M();return window.addEventListener("scroll",O,!0),window.addEventListener("resize",O),()=>{window.removeEventListener("scroll",O,!0),window.removeEventListener("resize",O)}},[x]);const B=o.useMemo(()=>{const O=r.map(vn),_=y.trim(),X=w?_.toLowerCase().split(/\s+/).filter(Boolean):[],ce=[];O.forEach((g,T)=>{const f=X.length?jn(g,X,_.toLowerCase()):0;f!==null&&ce.push({row:g,score:f,idx:T})}),ce.sort((g,T)=>g.score-T.score||g.idx-T.idx);const oe=[];if(a!==void 0){const g={value:"",label:a};(X.length?jn(g,X,_.toLowerCase()):0)!==null&&oe.push(g)}oe.push(...ce.map(g=>g.row));const ee=_&&!O.some(g=>g.value.toLowerCase()===_.toLowerCase());return c&&w&&ee&&oe.push({value:_,label:_,custom:!0}),oe},[r,y,w,a,c]);o.useEffect(()=>{if(!x||S<0||!v.current)return;v.current.querySelector(`[data-index="${S}"]`)?.scrollIntoView({block:"nearest"})},[S,x,B.length]);function L(){d||(j(C),b(!1),h(B.findIndex(O=>O.value===t)),k(!0),requestAnimationFrame(()=>m.current?.select()))}function U(){k(!1),j(C),b(!1),h(-1)}function H(O){i(O.value),k(!1),j(O.value?O.label:a??""),b(!1),h(-1),m.current?.focus()}function W(O){if(O.key==="ArrowDown"||O.key==="ArrowUp"){if(O.preventDefault(),!x){L();return}h(_=>{const X=O.key==="ArrowDown"?_+1:_-1;return Math.max(-1,Math.min(X,B.length-1))});return}if(O.key==="Enter"){if(!x){O.preventDefault(),L();return}const _=B[S];_?(O.preventDefault(),H(_)):U();return}if(O.key==="Escape"&&x){O.preventDefault(),O.stopPropagation(),U();return}O.key==="Tab"&&x&&U()}return e.jsxs("div",{ref:P,className:`relative ${p??""}`,children:[e.jsx("input",{ref:m,type:"text",role:"combobox","aria-expanded":x,"aria-controls":x?I:void 0,"aria-autocomplete":"list","aria-label":u,"aria-activedescendant":x&&S>=0?`${I}-opt-${S}`:void 0,disabled:d,value:x?y:C,placeholder:n,onMouseDown:()=>{x?k(!1):L()},onChange:O=>{x||k(!0),j(O.target.value),b(!0),h(0)},onKeyDown:W,onBlur:()=>{x&&U()},className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none truncate"}),x&&ti.createPortal(e.jsxs("div",{id:I,role:"listbox",ref:O=>{v.current=O,$.current=O},style:R,onMouseDown:O=>O.preventDefault(),"data-keep-edit-focus":!0,className:"z-50 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1",children:[B.map((O,_)=>e.jsxs("div",{id:`${I}-opt-${_}`,"data-index":_,role:"option","aria-selected":O.value===t,onMouseDown:X=>{X.preventDefault(),H(O)},className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${_===S?"bg-brand-500/20":O.value===t?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,children:[e.jsx("span",{className:`flex-1 truncate ${O.custom?"text-brand-500":"text-fg-primary"}`,children:O.label}),O.hint&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:O.hint}),O.custom&&c&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:typeof c=="function"?c(O.value):c})]},`${O.custom?"custom:":""}${O.value}`)),B.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:s})]}),document.body)]})}async function oo(){const{agents:t}=await F.agents.list({lean:!0});return t.map(r=>({id:r.id,name:r.name,role:r.role}))}let ds=null;function pa(){return ds||(ds=oo().catch(t=>{throw ds=null,t})),ds}function lo(t=pa,r=!0){const[i,a]=o.useState([]);return o.useEffect(()=>{if(!r)return;let n=!0;return t().then(s=>{n&&a(s)}).catch(()=>{n&&a([])}),()=>{n=!1}},[t,r]),i}function hs({value:t,options:r,onChange:i,fieldKey:a,ariaLabel:n,disabled:s}){const{t:c}=xe(["settings"]);return e.jsx(fa,{value:typeof t=="string"?t:"",options:r.map(d=>({value:d.id,label:d.name,hint:d.role})),onChange:d=>i(a,d),disabled:s,placeholder:c("settings:integrations.agentSelect.none",{defaultValue:"Not bound"}),filterPlaceholder:c("settings:integrations.agentSelect.search",{defaultValue:"Search agents…"}),emptyText:c("settings:integrations.agentSelect.empty",{defaultValue:"No matching agent"}),ariaLabel:n??c("settings:integrations.agentSelect.none",{defaultValue:"Not bound"}),className:"w-full"})}function ha({loading:t,error:r,onReload:i,buttonTestId:a,errorTestId:n,empty:s=!1}){const{t:c}=xe(["settings","common"]);return e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-h-[1.25rem]",children:[e.jsxs("button",{type:"button",onClick:i,disabled:t,"aria-busy":t,"data-testid":a,className:"inline-flex items-center gap-1 text-[11px] font-medium text-fg-tertiary hover:text-fg-secondary disabled:opacity-60 transition-colors",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${t?"animate-spin":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t?c("settings:instances.channels.refreshing",{defaultValue:"Refreshing…"}):s?c("settings:integrations.loadGroups",{defaultValue:"Load groups"}):c("settings:instances.channels.refresh",{defaultValue:"Refresh"})]}),r&&e.jsx("span",{"data-testid":n,className:"text-[11px] text-red-600",children:r})]})}const gs="rounded-xl border border-border-default bg-surface-secondary p-4",Dt="text-sm font-semibold text-fg-primary",ba="flex flex-wrap items-center justify-between gap-x-4 gap-y-2",co="flex flex-wrap items-start justify-between gap-x-4 gap-y-2",vr="shrink-0 text-sm text-fg-secondary",ya="flex-1 min-w-[10rem] flex justify-end",bt="text-xs text-fg-tertiary",jr="w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors";function Nr(t){return"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border transition-colors "+(t?"bg-selected-bg border-selected-border text-selected-fg":"bg-surface-primary border-border-default text-fg-secondary hover:border-fg-tertiary")}const uo={verified:"bg-green-500/10 text-green-600 border-green-500/30",unverified:"bg-amber-500/10 text-amber-600 border-amber-500/30",off:"bg-gray-500/10 text-fg-tertiary border-border-default",unconfigured:"bg-gray-500/10 text-fg-tertiary border-border-default"},mo={verified:"bg-green-500",unverified:"bg-amber-400",off:"bg-gray-400",unconfigured:"bg-gray-400"},xo={verified:"settings:integrations.status.verified",unverified:"settings:integrations.status.unverified",off:"settings:integrations.status.off",unconfigured:"settings:integrations.status.unconfigured"},go={verified:"Connected",unverified:"Not verified",off:"Off",unconfigured:"Not configured"};function fo({state:t}){const{t:r}=xe(["settings"]);return e.jsxs("span",{"data-testid":"integration-status","data-state":t,"data-connected":t==="verified"?"true":"false",className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${uo[t]}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${mo[t]}`}),r(xo[t],{defaultValue:go[t]})]})}function $t({type:t,text:r}){return e.jsx("div",{"data-testid":t==="ok"?"integration-msg-ok":"integration-msg-err",className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${t==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-600 border border-red-500/30"}`,children:r})}function Lt({label:t,control:r,help:i,htmlFor:a,start:n=!1}){return e.jsxs("div",{children:[e.jsxs("div",{className:n?co:ba,children:[a?e.jsx("label",{htmlFor:a,className:vr,children:t}):e.jsx("span",{className:vr,children:t}),e.jsx("div",{className:ya,children:r})]}),i?e.jsx("p",{className:`${bt} mt-1.5`,children:i}):null]})}function po({field:t,value:r,hasStored:i,onChange:a,platformId:n="",agentOptions:s=[]}){const{t:c}=xe(["settings"]),d=`integration-field-${t.key}`,[u,p]=o.useState(!1),x=o.useMemo(()=>n?ua(c,n,t):{label:t.label,help:t.help,placeholder:t.placeholder,options:t.options},[c,n,t]),k=x.label,y=x.help,j=x.placeholder,w=x.options??t.options??[],b=e.jsxs(e.Fragment,{children:[k,t.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),S=t.secret&&i?c("settings:integrations.secretStored"):y||void 0;if(t.type==="boolean"){const m=r===!0;return e.jsx(Lt,{label:k,help:y,control:e.jsx(bs,{checked:m,onChange:v=>a(t.key,v),label:k,size:"md",testId:`integration-field-${t.key}`})})}if(t.type==="agent")return e.jsx(Lt,{label:b,help:S,control:e.jsx("div",{className:"w-full","data-testid":`integration-field-${t.key}`,children:e.jsx(hs,{value:r,options:s,onChange:a,fieldKey:t.key,ariaLabel:k})})});if(t.type==="select"&&t.multiple){const m=Array.isArray(r)?r.map(String):[];return e.jsx(Lt,{start:!0,label:b,help:S,control:e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5","data-testid":`integration-field-${t.key}`,children:w.map(v=>{const $=m.includes(v.value);return e.jsx("button",{type:"button","aria-pressed":$,"data-option":v.value,onClick:()=>a(t.key,$?m.filter(I=>I!==v.value):[...m,v.value]),className:Nr($),children:v.label},v.value)})})})}if(t.type==="select")return e.jsx(Lt,{label:b,help:S,htmlFor:d,control:e.jsx("select",{id:d,"data-testid":`integration-field-${t.key}`,value:typeof r=="string"?r:"",onChange:m=>a(t.key,m.target.value),className:jr,children:(t.options??[]).map(m=>{const v=w.find($=>$.value===m.value)?.label??m.label;return e.jsx("option",{value:m.value,children:v},m.value)})})});const h=t.type==="password",P=t.type==="number";return e.jsx(Lt,{label:b,help:S,htmlFor:d,control:e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:d,"data-testid":`integration-field-${t.key}`,type:P?"number":h&&!u?"password":"text",value:r==null?"":String(r),placeholder:h&&i?c("settings:integrations.secretStoredPlaceholder"):j,onChange:m=>a(t.key,m.target.value),className:`${jr}${h?" font-mono pr-10":""}`}),h&&e.jsx("button",{type:"button","aria-label":u?c("settings:integrations.hide",{defaultValue:"Hide"}):c("settings:integrations.show",{defaultValue:"Show"}),onClick:()=>p(m=>!m),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:u?"🙈":"👁"})]})})}function yt({status:t,draft:r,fields:i=t.fields,onChange:a,agentOptions:n=[]}){return e.jsx(e.Fragment,{children:i.map(s=>e.jsx(po,{field:s,platformId:t.id,value:r[s.key],hasStored:t.secrets[s.key]?.hasValue===!0,agentOptions:n,onChange:a},s.key))})}const Nn={pending:"bg-amber-400 animate-pulse",ok:"bg-emerald-500",failed:"bg-red-500"};function wn({label:t,hint:r,leg:i}){const{t:a}=xe("settings");return e.jsxs("div",{className:"flex items-start gap-2.5","data-testid":"connection-test-leg",children:[e.jsx("span",{className:`mt-1.5 w-2 h-2 rounded-full shrink-0 ${Nn[i.state]??Nn.pending}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-fg-primary",children:t}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 break-words",children:i.state==="ok"?i.detail??a("integrations.connectionTest.legOk",{defaultValue:"Verified"}):i.state==="failed"?i.detail??a("integrations.connectionTest.legFailed",{defaultValue:"Failed"}):r})]})]})}function ho(t,r){const i=new Date(t);return Number.isNaN(i.getTime())?t:i.toLocaleString(r,{dateStyle:"medium",timeStyle:"short"})}function bo({test:t,starting:r,onStart:i,lastVerifiedAt:a=null}){const{t:n,i18n:s}=xe("settings"),c=(()=>{if(!t)return null;switch(t.status){case"awaiting_reply":return n("integrations.connectionTest.awaitingReply",{defaultValue:"A test message was sent to {{target}}. Reply to it in {{platform}} to finish — include {{code}} if you can.",target:t.targetChannelName??t.targetChannelId??"",platform:t.platform,code:t.code??""});case"awaiting_inbound":return n("integrations.connectionTest.awaitingInbound",{defaultValue:"Send any message to this bot in {{platform}} — we will answer it to confirm both directions.",platform:t.platform});case"verified":return n("integrations.connectionTest.verified",{defaultValue:"Both directions work — Markus can send to and receive from this bot."});case"expired":return n("integrations.connectionTest.expired",{defaultValue:"No reply arrived in time. Check the bot is in the conversation, then try again."});default:return null}})();return e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:n("integrations.connectionTest.title",{defaultValue:"Connection verification"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:n("integrations.connectionTest.subtitle",{defaultValue:"Sends a real message and waits for your reply — proves both directions."})})]}),t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(wn,{label:n("integrations.connectionTest.outbound",{defaultValue:"Outbound (bot → IM)"}),hint:n("integrations.connectionTest.outboundPending",{defaultValue:"Not sent yet"}),leg:t.outbound}),e.jsx(wn,{label:n("integrations.connectionTest.inbound",{defaultValue:"Inbound (IM → bot)"}),hint:n("integrations.connectionTest.inboundPending",{defaultValue:"Waiting for your reply"}),leg:t.inbound})]}),c&&(t.status==="verified"||t.status==="expired"?e.jsx($t,{type:t.status==="verified"?"ok":"err",text:c}):e.jsx("div",{className:"px-3 py-2 rounded-lg text-xs bg-surface-tertiary text-fg-secondary",children:c}))]}):a?e.jsx($t,{type:"ok",text:n("integrations.connectionTest.lastVerified",{defaultValue:"Verified {{when}}.",when:ho(a,s.language)})}):e.jsx("div",{className:"text-xs text-fg-tertiary",children:n("integrations.connectionTest.idle",{defaultValue:"Not verified yet. Verify to send a real message to the bot and confirm the round trip."})}),e.jsxs("button",{type:"button",onClick:i,disabled:r,"data-testid":"connection-test-start",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-fg-primary border border-border-default rounded-lg hover:bg-surface-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[r?e.jsx("div",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):null,t?n("integrations.connectionTest.retry",{defaultValue:"Verify again"}):n("integrations.connectionTest.start",{defaultValue:"Verify connection"})," "]})]})}function yo({status:t,values:r,setValue:i,channels:a=[],canListChannels:n=!1,channelsLoading:s=!1,channelsError:c=null,onReloadChannels:d=()=>{},channelsGuidance:u=null,testSlot:p}){const{t:x}=xe(["settings","common"]),[k,y]=o.useState(!1),j=_t(t.fields),w=no(t.fields),b=so(t.fields),S=io(t.fields,r),h=ga(t.fields),P=b?r[b.key]!==!1:!0,m=n&&h?h.key:null,v=m!==null?String(r[m]??""):"",$={configured:x("settings:instances.notify.reachConfigured",{defaultValue:"Configured"}),"not-configured":x("settings:instances.notify.reachNotConfigured",{defaultValue:"Not set"}),unsupported:x("settings:instances.notify.reachUnsupported",{defaultValue:"Not supported"})},I={configured:"text-green-600","not-configured":"text-amber-600",unsupported:"text-fg-tertiary"},R={configured:"bg-green-500","not-configured":"bg-amber-400",unsupported:"bg-gray-400"},V=x("settings:instances.notify.guidanceFallback",{defaultValue:"This platform can’t list its conversations — enter the destination ID manually."}),C=u?x(u,{defaultValue:V}):V,M=m!==null&&!s&&v!==""&&!a.some(L=>L.id===v),B="text-xs font-medium text-fg-secondary mb-2";return e.jsxs("section",{"data-testid":"notification-panel","data-reachability":S,className:gs,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsx("h3",{className:Dt,children:x("settings:instances.notify.title",{defaultValue:"Notifications"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs ${I[S]}`,"data-testid":"notification-reachability","data-state":S,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${R[S]}`}),$[S]]}),b&&e.jsx(bs,{checked:P,onChange:L=>i(b.key,L),label:x("settings:instances.notify.masterLabel",{defaultValue:"Enable notifications"}),size:"md",testId:`integration-field-${b.key}`})]})]}),e.jsxs("div",{className:`space-y-4${P?"":" opacity-60"}`,children:[j.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:B,children:x("settings:instances.notify.destination",{defaultValue:"Destination"})}),m!==null&&e.jsxs("div",{"data-testid":"notification-chat-list",className:"space-y-1.5",children:[e.jsx(ha,{loading:s,error:c,onReload:d,empty:a.length===0,buttonTestId:"notification-chat-refresh",errorTestId:"notification-chat-error"}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(L=>e.jsx("button",{type:"button","aria-pressed":v===L.id,"data-testid":`notification-chat-pick-${L.id}`,onClick:()=>i(m,L.id),className:Nr(v===L.id),children:L.name},L.id))}),a.length===0&&!s&&!c&&e.jsx("p",{"data-testid":"notification-chat-empty",className:bt,children:x("settings:instances.notify.pickEmpty",{defaultValue:"Add the bot to a group in your IM → click “Load groups” → pick it from the list."})}),M&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:e.jsx("button",{type:"button","aria-pressed":"true","data-testid":"notification-chat-pick-current",onClick:()=>i(m,v),className:Nr(!0),children:v})})]}),m===null&&e.jsx("p",{"data-testid":"notification-chat-guidance",className:bt,children:C}),m!==null?e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{type:"button","aria-expanded":k,"data-testid":"notification-manual-toggle",onClick:()=>y(L=>!L),className:"inline-flex items-center gap-1 text-xs font-medium text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${k?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),x("settings:instances.notify.manualInput",{defaultValue:"Enter an ID manually"})]}),k&&e.jsx("div",{className:"space-y-4 mt-3","data-testid":"notification-manual-fields",children:e.jsx(yt,{status:t,draft:r,fields:j,onChange:i})})]}):e.jsx("div",{className:"mt-2",children:e.jsx(yt,{status:t,draft:r,fields:j,onChange:i})})]}),w.length>0&&e.jsxs("div",{"data-testid":"notification-preferences",className:"space-y-3",children:[e.jsx("div",{className:B,children:x("settings:instances.notify.content",{defaultValue:"What to send"})}),e.jsx(yt,{status:t,draft:r,fields:w,onChange:i})]}),p]})]})}const ht={fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round"},vo={color:"#64748b",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M21 12a8 8 0 0 1-11.6 7.1L4 21l1.9-5.4A8 8 0 1 1 21 12z"})})},jo={feishu:{color:"#3370ff",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M21 5 3 11l5.5 2.2L19 7l-7.5 8.3L12 21l3-4.5L21 5z"})})},telegram:{color:"#229ed9",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M22 3 2.5 10.5l5.5 2L21 6l-9 10v5l3.5-4.5L20 19 22 3z"})})},slack:{color:"#611f69",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M9.5 3 7.5 20M16.5 4 14.5 21M3.5 9h17M2.5 15h17"})})},whatsapp:{color:"#1faa59",glyph:e.jsxs("g",{...ht,children:[e.jsx("path",{d:"M21 11.5a8.5 8.5 0 0 1-12.6 7.4L3 20.5l1.6-5.3A8.5 8.5 0 1 1 21 11.5z"}),e.jsx("path",{d:"M9 8.8c.3 2.6 2.6 4.9 5.2 5.2l1-1.3 1.9.8"})]})},discord:{color:"#5865f2",glyph:e.jsxs("g",{...ht,children:[e.jsx("rect",{x:"3",y:"7",width:"18",height:"10",rx:"4.5"}),e.jsx("path",{d:"M7.5 11.5h3M9 10v3"}),e.jsx("circle",{cx:"15",cy:"10.7",r:"0.9"}),e.jsx("circle",{cx:"17.3",cy:"13",r:"0.9"})]})}};function No(t){return jo[t]??vo}function va({id:t,size:r=36}){const i=No(t);return e.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded-lg",style:{width:r,height:r,backgroundColor:`${i.color}1a`,color:i.color},"aria-hidden":"true","data-testid":`platform-icon-${t}`,children:e.jsx("svg",{width:Math.round(r*.58),height:Math.round(r*.58),viewBox:"0 0 24 24",children:i.glyph})})}function wo({status:t,configured:r,canListChannels:i=!1,channelsGuidance:a=null}){const{t:n,i18n:s}=xe(["settings","common"]),[c,d]=o.useState(!r),u=o.useMemo(()=>{const k=$i(s,n,t.id);if(_t(t.fields).length===0)return k;const y=n("settings:integrations.guide.destinationStep.desc",{defaultValue:"Pick the chat or user that should receive approvals and notifications — without it they have nowhere to go."}),j=i?{title:n("settings:integrations.guide.selectChatStep.title",{defaultValue:"Pick the notification group"}),desc:n("settings:integrations.guide.selectChatStep.desc",{defaultValue:"Add the bot to a group in your IM → click “Load groups” → pick it from the list."})}:{title:n("settings:integrations.guide.destinationStep.title",{defaultValue:"Set a notification destination"}),desc:a?n(a,{defaultValue:y}):y};return[...k,j]},[s,n,t.id,t.fields,i,a]),p=Di(t.id),x=n(`settings:integrations.platforms.${t.id}.description`,{defaultValue:""});return e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden","data-testid":"integration-guide","data-open":c?"true":"false",children:[e.jsxs("button",{type:"button",onClick:()=>d(k=>!k),"aria-expanded":c,"data-testid":"integration-guide-toggle",className:"w-full flex items-center gap-2.5 px-4 py-3 text-left hover:bg-white/[0.02] transition-colors",children:[e.jsx("span",{className:"text-base leading-none","aria-hidden":"true",children:"🧭"}),e.jsx("span",{className:"flex-1 text-sm font-medium text-fg-primary",children:Vi(n)}),e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${c?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"px-4 pb-4 pt-1 space-y-3 border-t border-border-default",children:[x&&e.jsx("p",{className:"text-xs text-fg-tertiary",children:x}),u.length>0?e.jsx("ol",{className:"space-y-2.5","data-testid":"integration-guide-steps",children:u.map((k,y)=>e.jsxs("li",{className:"flex gap-3",children:[e.jsx("span",{className:"shrink-0 w-5 h-5 mt-0.5 rounded-full bg-brand-500/15 text-brand-600 text-[11px] font-semibold flex items-center justify-center",children:y+1}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-xs font-medium text-fg-primary",children:k.title}),k.desc&&e.jsx("span",{className:"block text-[11px] text-fg-tertiary mt-0.5",children:k.desc})]})]},k.title))}):e.jsx("p",{className:"text-xs text-fg-tertiary",children:n("settings:integrations.guide.fallback",{defaultValue:"Fill in the credentials from the platform’s developer console below."})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[p&&e.jsxs("a",{href:p,target:"_blank",rel:"noreferrer","data-testid":"integration-guide-console",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 transition-colors",children:[n("settings:integrations.guide.openConsole",{defaultValue:"Open developer console"}),e.jsx("span",{"aria-hidden":"true",children:"↗"})]}),t.docsUrl&&e.jsx("a",{href:t.docsUrl,target:"_blank",rel:"noreferrer",className:"text-xs text-brand-600 hover:text-brand-700",children:n("settings:integrations.docs",{defaultValue:"Setup docs"})})]})]})]})}const ja={create:(t,r)=>F.settings.createInstance(t,r).then(i=>i.instance),save:(t,r)=>F.settings.saveInstance(t,r).then(()=>{}),test:(t,r)=>F.settings.testInstance(t,r),remove:t=>F.settings.deleteInstance(t).then(()=>{}),listChannels:t=>F.settings.listInstanceChannels(t),saveChannels:(t,r)=>F.settings.saveInstanceChannels(t,r).then(()=>{}),startConnectionTest:(t,r)=>F.settings.startConnectionTest(t,r).then(i=>i.test),getConnectionTest:t=>F.settings.getConnectionTest(t).then(r=>r.test)},ko=700;function kn({instance:t,client:r=ja,extras:i={},onChanged:a,onCreated:n,loadAgents:s,defaultExpanded:c}){const{t:d}=xe(["settings","common"]),u=Yi(t),[p,x]=o.useState(c??u),[k,y]=o.useState(!1),j=o.useMemo(()=>hn(t),[t]),[w,b]=o.useState(t.label),[S,h]=o.useState(()=>fn(j)),[P,m]=o.useState(t.enabled),[v,$]=o.useState(t.channels),[I,R]=o.useState(typeof t.notifyAgentId=="string"?t.notifyAgentId:""),[V,C]=o.useState({kind:"idle"}),M=!!i[t.platform]?.guidedSetup,[B,L]=o.useState(M&&!t.hasConfig?"guided":"manual"),U=M&&B==="guided",{channels:H,error:W,loading:O,reloadChannels:_}=to(r.listChannels,t.id,p&&t.canListChannels),[X,ce]=o.useState(""),[oe,ee]=o.useState(null),[g,T]=o.useState(!1),[f,K]=o.useState(null),z=qi(oe),[se,ae]=o.useState(!1),ge=t.fields.some(E=>E.type==="agent"),te=lo(o.useMemo(()=>s??pa,[s]),ge),Je=o.useCallback(E=>E?te.find(re=>re.id===E)?.name??E:"",[te]),Ae=Hi(j),Se=o.useRef(t);Se.current=t;const Be=o.useRef(!1),ot=o.useRef(!1);o.useEffect(()=>{if(Be.current)return;const E=Se.current;b(E.label),h(fn(hn(E))),m(E.enabled),$(E.channels),R(typeof E.notifyAgentId=="string"?E.notifyAgentId:"")},[Ae]),o.useEffect(()=>{C({kind:"idle"}),ee(null),K(null),et(!1)},[t.id]),o.useEffect(()=>{L(M&&!t.hasConfig?"guided":"manual")},[t.id,t.hasConfig,M]);const we=o.useCallback(()=>{Be.current=!0,C({kind:"idle"})},[]),fe=o.useCallback((E,re)=>{we(),h(le=>({...le,[E]:re}))},[we]),Ft=o.useCallback(E=>{we(),b(E)},[we]),Ye=o.useCallback(E=>{we(),m(E)},[we]),vt=o.useRef(()=>Promise.resolve()),De=o.useCallback(async()=>{if(!ot.current){ot.current=!0,C({kind:"saving"});try{let E=Se.current.id;E||(E=(await r.create(Se.current.platform,w.trim())).id),await r.save(E,{...Fi(j,S,P),notifyAgentId:I}),Se.current.canListChannels&&await r.saveChannels(E,v);let re=null;try{const{ok:le,text:Ke,code:At}=zi(await r.test(E,{}));!le&&!/not supported/i.test(Ke)&&(re=At==="network_unreachable"?d("settings:integrations.savedNotVerifiedNetwork"):d("settings:integrations.savedNotVerified",{reason:Ke}))}catch(le){re=d("settings:integrations.savedNotVerified",{reason:String(le)})}Be.current=!1,C(re?{kind:"error",text:re}:{kind:"saved"}),await a?.(),Se.current.id===""&&n?.(E)}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}finally{ot.current=!1}}},[r,j,S,P,I,v,w,d,a,n]);vt.current=De;const lt=pn(j.fields,S,t.secrets),Ut=u&&w.trim()==="",Kt=v.every(E=>E.agentId),Qe=!U&&!Ut&<.length===0&&Kt,Ee=o.useMemo(()=>JSON.stringify([w,P,I,v,S]),[w,P,I,v,S]);o.useEffect(()=>{if(!Be.current||!Qe)return;const E=setTimeout(()=>{vt.current()},ko);return()=>clearTimeout(E)},[Ee,Qe]),o.useEffect(()=>{if(!p||u)return;let E=!0;return r.getConnectionTest(t.id).then(re=>{E&&re&&ee(re)}).catch(()=>{}),()=>{E=!1}},[p,u,r,t.id]),o.useEffect(()=>{if(!p||!z)return;let E=!0;const re=setInterval(()=>{r.getConnectionTest(t.id).then(le=>{E&&le&&ee(le)}).catch(()=>{})},2500);return()=>{E=!1,clearInterval(re)}},[p,z,r,t.id]);const jt=o.useRef(null);o.useEffect(()=>{oe?.status==="verified"&&jt.current!==t.id&&(jt.current=t.id,a?.())},[oe?.status,t.id,a]);const Ht=o.useCallback(async()=>{T(!0),K(null);try{ee(await r.startConnectionTest(t.id))}catch(E){K(E instanceof Error?E.message:String(E))}finally{T(!1)}},[r,t.id]),ye=i[t.platform],_e=o.useMemo(()=>({platformId:t.platform,instanceId:t.id||void 0,status:j,values:S,setValue:fe,reload:()=>{a?.()},agents:te,onCreated:n,setupMethod:M?B:void 0,setSetupMethod:M?L:void 0}),[t.platform,t.id,j,S,fe,a,te,n,M,B]),Ne=o.useMemo(()=>new Set(ye?.ownedFields??[]),[ye]),Nt=_t(j.fields).length>0,wt=o.useMemo(()=>new Set(Nt?ao(j.fields).map(E=>E.key):[]),[j.fields,Nt]),Ze=o.useMemo(()=>j.fields.filter(E=>!Ne.has(E.key)&&!wt.has(E.key)),[j.fields,Ne,wt]),Fe=o.useMemo(()=>Ui(Ze),[Ze]),Xe=o.useMemo(()=>Ki(Ze),[Ze]),kt=o.useMemo(()=>Fe.filter(E=>E.type==="agent"),[Fe]),Ct=o.useMemo(()=>Fe.filter(E=>E.type!=="agent"),[Fe]),[zt,et]=o.useState(!1),tt=o.useMemo(()=>pn(t.fields,t.values,t.secrets),[t.fields,t.values,t.secrets]),Oe=t.hasConfig&&!tt.some(E=>Ct.some(re=>re.key===E)),St=o.useMemo(()=>Zi(H,X),[H,X]),je=o.useMemo(()=>Qi(v,H),[v,H]),st=v.filter(E=>!E.agentId).length,qt=o.useCallback((E,re)=>{we(),$(le=>re?bn(le,E.id,Hs(le,E.id)?.agentId??t.agentId??"",E.kind??null):yn(le,E.id))},[we,t.agentId]),Wt=o.useCallback((E,re)=>{we(),$(le=>bn(le,E,re,Hs(le,E)?.kind??null))},[we]),rt=o.useCallback(async()=>{ae(!1);try{await r.remove(t.id),await a?.()}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}},[r,t.id,a]),Ue=Wi(t,oe?.status==="verified"),ne=t.id||`new-${t.platform}`,pe=`instance-name-${ne}`,Gt=lt.map(E=>{const re=j.fields.find(le=>le.key===E);return re?ua(d,t.platform,re).label:E}).join(", ");return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden border border-border-default","data-testid":`instance-card-${ne}`,"data-instance":t.id,"data-platform":t.platform,"data-draft":u?"true":"false","data-expanded":p?"true":"false","data-connection":Ue,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":p,"data-testid":`instance-toggle-${ne}`,className:"flex-1 min-w-0 flex items-center gap-3 text-left",children:[e.jsx(va,{id:t.platform}),e.jsxs("span",{className:"flex-1 min-w-0 flex items-center gap-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary truncate","data-testid":`instance-label-${ne}`,children:w.trim()===""?d("settings:instances.newBot",{defaultValue:"New bot"}):w}),!u&&e.jsx("span",{className:"hidden sm:inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-surface-secondary border border-border-default text-fg-tertiary","data-testid":`instance-platform-${ne}`,children:t.platform}),!u&&t.agentId&&e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1.5 text-xs text-fg-tertiary truncate","data-testid":`instance-agent-${ne}`,title:d("settings:instances.boundAgent",{defaultValue:"Bound agent"}),children:[e.jsx("span",{className:"text-fg-quaternary",children:"→"}),Je(t.agentId)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(fo,{state:Ue}),!u&&e.jsx(bs,{checked:P,onChange:Ye,size:"md",testId:`instance-enabled-${ne}`,label:d("settings:instances.toggleLabel",{defaultValue:"Turn this bot on or off"})}),e.jsx("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":p,"data-testid":`instance-chevron-${ne}`,className:"p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:e.jsx("svg",{className:`w-4 h-4 transition-transform ${p?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})})]})]}),p&&e.jsxs("div",{className:"px-6 pb-6 pt-5 border-t border-border-default space-y-6",children:[!t.hasConfig&&!U&&e.jsx(wo,{status:j,configured:t.hasConfig,canListChannels:t.canListChannels,channelsGuidance:t.channelsGuidance??null}),!M&&ye?.placement==="before"&&ye.render(_e),e.jsxs("section",{"data-testid":`instance-credentials-${ne}`,className:gs,children:[e.jsx("h3",{className:`${Dt} mb-3`,children:t.hasConfig?d("settings:instances.setup.configuredTitle",{defaultValue:"Bot setup"}):M?d("settings:instances.setup.title",{defaultValue:"Connection"}):d("settings:instances.credentials",{defaultValue:"Credentials"})}),M&&!t.hasConfig&&e.jsx("div",{role:"tablist",className:"inline-flex rounded-lg border border-border-default bg-surface-secondary p-0.5 mb-4",children:["guided","manual"].map(E=>e.jsx("button",{type:"button",role:"tab","aria-selected":B===E,onClick:()=>L(E),"data-testid":`setup-method-${E}-${ne}`,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${B===E?"bg-surface-elevated text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:E==="guided"?d("settings:instances.setup.guided",{defaultValue:"Scan to create (recommended)"}):d("settings:instances.setup.manual",{defaultValue:"Enter credentials manually"})},E))}),U?e.jsx("div",{className:"space-y-4",children:ye.render(_e)}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:ba,children:[e.jsxs("label",{htmlFor:pe,className:vr,children:[d("settings:instances.addBot.name",{defaultValue:"Bot name"}),e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:ya,children:e.jsx("input",{id:pe,"data-testid":`new-bot-name-${t.platform}`,value:w,onChange:E=>Ft(E.target.value),placeholder:d("settings:instances.addBot.namePlaceholder",{defaultValue:"e.g. Sales"}),className:jr})})]}),kt.length>0&&e.jsx(yt,{status:j,draft:S,fields:kt,onChange:fe,agentOptions:te}),Ct.length>0&&(Oe&&!zt?e.jsx("div",{"data-testid":`instance-credentials-configured-${ne}`,className:"space-y-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx("span",{"aria-hidden":"true",children:"✓"}),d("settings:instances.credentialsSet",{defaultValue:"Credentials set"})]}),e.jsx("button",{type:"button",onClick:()=>et(!0),"data-testid":`instance-credentials-edit-${ne}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsEdit",{defaultValue:"Change"})})]})}):e.jsxs("div",{className:"space-y-3",children:[Oe&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx("span",{"aria-hidden":"true",children:"✓"}),d("settings:instances.credentialsSet",{defaultValue:"Credentials set"})]}),e.jsx("button",{type:"button",onClick:()=>et(!1),"data-testid":`instance-credentials-hide-${ne}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsHide",{defaultValue:"Hide"})})]}),e.jsx(yt,{status:j,draft:S,fields:Ct,onChange:fe,agentOptions:te})]}))]}),e.jsx("div",{className:"mt-3 min-h-[1.25rem]","data-testid":`instance-save-state-${ne}`,children:e.jsxs("span",{"data-state":V.kind,className:"inline-flex items-center gap-2 text-xs text-fg-tertiary",children:[V.kind==="saving"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),d("settings:instances.autosave.saving",{defaultValue:"Saving…"})]}),V.kind==="saved"&&e.jsxs("span",{className:"text-green-600",children:["✓ ",d("settings:instances.autosave.saved",{defaultValue:"Saved"})]}),!Qe&&!U&&e.jsx("span",{"data-testid":`instance-missing-${ne}`,children:lt.length>0?d("settings:integrations.missingRequired",{defaultValue:"Required: {{fields}}",fields:Gt}):d("settings:instances.addBot.labelRequired",{defaultValue:"Give the bot a name."})})]})}),V.kind==="error"&&e.jsx("div",{className:"mt-2",children:e.jsx($t,{type:"err",text:V.text})})]}),!u&&e.jsxs("section",{children:[e.jsx(bo,{test:oe,starting:g,lastVerifiedAt:t.lastVerifiedAt,onStart:()=>{Ht()}}),f&&e.jsx("div",{className:"mt-3",children:e.jsx($t,{type:"err",text:f})})]}),!u&&Nt&&e.jsx(yo,{status:j,values:S,setValue:fe,channels:H,canListChannels:t.canListChannels,channelsLoading:O,channelsError:W,onReloadChannels:_,channelsGuidance:t.channelsGuidance??null,testSlot:ye?.sendTest?.(_e)}),e.jsxs("section",{"data-testid":`instance-more-${ne}`,children:[e.jsxs("button",{type:"button",onClick:()=>y(E=>!E),"aria-expanded":k,"data-testid":`instance-more-toggle-${ne}`,className:"w-full flex items-center gap-2 text-left group px-1",children:[e.jsx("span",{className:Dt,children:d("settings:instances.moreSettings",{defaultValue:"Advanced"})}),e.jsx("span",{className:`${bt} truncate hidden sm:inline`,children:d("settings:instances.moreSettingsHint",{defaultValue:"Chat routing and platform options"})}),e.jsx("svg",{className:`ml-auto w-3.5 h-3.5 text-fg-tertiary transition-transform ${k?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})]}),k&&e.jsxs("div",{className:"mt-3 space-y-4",children:[Xe.length>0&&e.jsxs("div",{className:gs,children:[e.jsx("h4",{className:`${Dt} mb-1`,children:d("settings:instances.advancedTitle",{defaultValue:"Platform options"})}),!u&&e.jsx("p",{className:`${bt} mb-3`,children:d("settings:instances.advancedHint",{defaultValue:"These default to the right value for almost every setup — leave them alone unless you know you need them."})}),e.jsx(yt,{status:j,draft:S,fields:Xe,onChange:fe,agentOptions:te})]}),!u&&e.jsxs("div",{className:gs,children:[e.jsx("h4",{className:`${Dt} mb-1`,children:d("settings:instances.routing.chats",{defaultValue:"Chat routing"})}),e.jsx("p",{className:`${bt} mb-3`,children:d("settings:instances.routing.chatsHint",{defaultValue:"The agent bound above answers every chat by default. Route a specific chat to a different agent here."})}),!t.canListChannels&&e.jsx("p",{className:"text-[11px] text-fg-tertiary","data-testid":`instance-chats-unsupported-${ne}`,children:t.channelsGuidance?d(t.channelsGuidance,{defaultValue:d("settings:instances.routing.unsupported",{defaultValue:"This platform does not let us list its chats."})}):d("settings:instances.routing.unsupported",{defaultValue:"This platform does not let us list its chats."})}),t.canListChannels&&e.jsx("div",{className:"mb-2",children:e.jsx(ha,{loading:O,error:W,onReload:_,empty:H.length===0,buttonTestId:`instance-chats-refresh-${ne}`,errorTestId:`instance-chats-error-${ne}`})}),t.canListChannels&&H.length>0&&e.jsx("input",{type:"text",value:X,onChange:E=>ce(E.target.value),placeholder:d("settings:instances.routing.searchChats",{defaultValue:"Search chats…"}),"data-testid":`instance-chat-search-${ne}`,className:"w-full mb-2 px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500"}),e.jsxs("div",{className:"space-y-2","data-testid":`instance-chats-${ne}`,children:[St.map(E=>{const re=Hs(v,E.id);return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-fg-primary min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:!!re,"data-testid":`instance-chat-toggle-${ne}-${E.id}`,onChange:le=>qt(E,le.target.checked),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate",title:E.id,children:E.name})]}),re&&e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${ne}-${E.id}`,children:e.jsx(hs,{value:re.agentId,options:te,onChange:(le,Ke)=>Wt(E.id,typeof Ke=="string"?Ke:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.id)}),je.map(E=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-fg-primary min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:!0,"data-testid":`instance-chat-toggle-${ne}-${E.nativeId}`,onChange:()=>$(re=>yn(re,E.nativeId)),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate font-mono text-xs",title:E.nativeId,children:E.nativeId})]}),e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${ne}-${E.nativeId}`,children:e.jsx(hs,{value:E.agentId,options:te,onChange:(re,le)=>Wt(E.nativeId,typeof le=="string"?le:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.nativeId))]}),e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-2",children:d("settings:instances.routing.autoSaved",{defaultValue:"Changes are saved automatically."})}),st>0&&e.jsx("div",{className:"mt-3",children:e.jsx($t,{type:"err",text:d("settings:instances.routing.agentRequired",{defaultValue:"Pick an agent for every selected chat ({{count}} still unassigned).",count:st})})})]})]})]}),!M&&ye&&ye.placement!=="before"&&ye.render(_e),!u&&e.jsx("div",{className:"pt-1",children:e.jsx("button",{type:"button",onClick:()=>ae(!0),"data-testid":`instance-disconnect-${ne}`,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-600 border border-red-500/30 rounded-lg hover:bg-red-500/10 transition-colors",children:d("settings:integrations.disconnect",{defaultValue:"Disconnect"})})})]}),se&&e.jsx(fs,{title:d("settings:integrations.disconnectConfirmTitle",{defaultValue:"Disconnect this bot?"}),message:d("settings:integrations.disconnectConfirmMessage",{defaultValue:"Its stored credentials are removed and it stops sending and receiving messages. This cannot be undone."}),confirmLabel:d("settings:integrations.disconnect",{defaultValue:"Disconnect"}),variant:"danger",onConfirm:()=>{rt()},onCancel:()=>ae(!1)})]})}var ft={},zs,Cn;function Co(){return Cn||(Cn=1,zs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),zs}var qs={},Ge={},Sn;function at(){if(Sn)return Ge;Sn=1;let t;const r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return Ge.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},Ge.getSymbolTotalCodewords=function(a){return r[a]},Ge.getBCHDigit=function(i){let a=0;for(;i!==0;)a++,i>>>=1;return a},Ge.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},Ge.isKanjiModeEnabled=function(){return typeof t<"u"},Ge.toSJIS=function(a){return t(a)},Ge}var Ws={},An;function Cr(){return An||(An=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+i)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,n){if(t.isValid(a))return a;try{return r(a)}catch{return n}}})(Ws)),Ws}var Gs,Pn;function So(){if(Pn)return Gs;Pn=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(r){const i=Math.floor(r/8);return(this.buffer[i]>>>7-r%8&1)===1},put:function(r,i){for(let a=0;a<i;a++)this.putBit((r>>>i-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const i=Math.floor(this.length/8);this.buffer.length<=i&&this.buffer.push(0),r&&(this.buffer[i]|=128>>>this.length%8),this.length++}},Gs=t,Gs}var Js,Mn;function Ao(){if(Mn)return Js;Mn=1;function t(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return t.prototype.set=function(r,i,a,n){const s=r*this.size+i;this.data[s]=a,n&&(this.reservedBit[s]=!0)},t.prototype.get=function(r,i){return this.data[r*this.size+i]},t.prototype.xor=function(r,i,a){this.data[r*this.size+i]^=a},t.prototype.isReserved=function(r,i){return this.reservedBit[r*this.size+i]},Js=t,Js}var Ys={},Tn;function Po(){return Tn||(Tn=1,(function(t){const r=at().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const n=Math.floor(a/7)+2,s=r(a),c=s===145?26:Math.ceil((s-13)/(2*n-2))*2,d=[s-7];for(let u=1;u<n-1;u++)d[u]=d[u-1]-c;return d.push(6),d.reverse()},t.getPositions=function(a){const n=[],s=t.getRowColCoords(a),c=s.length;for(let d=0;d<c;d++)for(let u=0;u<c;u++)d===0&&u===0||d===0&&u===c-1||d===c-1&&u===0||n.push([s[d],s[u]]);return n}})(Ys)),Ys}var Qs={},En;function Mo(){if(En)return Qs;En=1;const t=at().getSymbolSize,r=7;return Qs.getPositions=function(a){const n=t(a);return[[0,0],[n-r,0],[0,n-r]]},Qs}var Zs={},Ln;function To(){return Ln||(Ln=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={N1:3,N2:3,N3:40,N4:10};t.isValid=function(n){return n!=null&&n!==""&&!isNaN(n)&&n>=0&&n<=7},t.from=function(n){return t.isValid(n)?parseInt(n,10):void 0},t.getPenaltyN1=function(n){const s=n.size;let c=0,d=0,u=0,p=null,x=null;for(let k=0;k<s;k++){d=u=0,p=x=null;for(let y=0;y<s;y++){let j=n.get(k,y);j===p?d++:(d>=5&&(c+=r.N1+(d-5)),p=j,d=1),j=n.get(y,k),j===x?u++:(u>=5&&(c+=r.N1+(u-5)),x=j,u=1)}d>=5&&(c+=r.N1+(d-5)),u>=5&&(c+=r.N1+(u-5))}return c},t.getPenaltyN2=function(n){const s=n.size;let c=0;for(let d=0;d<s-1;d++)for(let u=0;u<s-1;u++){const p=n.get(d,u)+n.get(d,u+1)+n.get(d+1,u)+n.get(d+1,u+1);(p===4||p===0)&&c++}return c*r.N2},t.getPenaltyN3=function(n){const s=n.size;let c=0,d=0,u=0;for(let p=0;p<s;p++){d=u=0;for(let x=0;x<s;x++)d=d<<1&2047|n.get(p,x),x>=10&&(d===1488||d===93)&&c++,u=u<<1&2047|n.get(x,p),x>=10&&(u===1488||u===93)&&c++}return c*r.N3},t.getPenaltyN4=function(n){let s=0;const c=n.data.length;for(let u=0;u<c;u++)s+=n.data[u];return Math.abs(Math.ceil(s*100/c/5)-10)*r.N4};function i(a,n,s){switch(a){case t.Patterns.PATTERN000:return(n+s)%2===0;case t.Patterns.PATTERN001:return n%2===0;case t.Patterns.PATTERN010:return s%3===0;case t.Patterns.PATTERN011:return(n+s)%3===0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(s/3))%2===0;case t.Patterns.PATTERN101:return n*s%2+n*s%3===0;case t.Patterns.PATTERN110:return(n*s%2+n*s%3)%2===0;case t.Patterns.PATTERN111:return(n*s%3+(n+s)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(n,s){const c=s.size;for(let d=0;d<c;d++)for(let u=0;u<c;u++)s.isReserved(u,d)||s.xor(u,d,i(n,u,d))},t.getBestMask=function(n,s){const c=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let p=0;p<c;p++){s(p),t.applyMask(p,n);const x=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(p,n),x<u&&(u=x,d=p)}return d}})(Zs)),Zs}var cs={},Rn;function Na(){if(Rn)return cs;Rn=1;const t=Cr(),r=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return cs.getBlocksCount=function(n,s){switch(s){case t.L:return r[(n-1)*4+0];case t.M:return r[(n-1)*4+1];case t.Q:return r[(n-1)*4+2];case t.H:return r[(n-1)*4+3];default:return}},cs.getTotalCodewordsCount=function(n,s){switch(s){case t.L:return i[(n-1)*4+0];case t.M:return i[(n-1)*4+1];case t.Q:return i[(n-1)*4+2];case t.H:return i[(n-1)*4+3];default:return}},cs}var Xs={},Rt={},In;function Eo(){if(In)return Rt;In=1;const t=new Uint8Array(512),r=new Uint8Array(256);return(function(){let a=1;for(let n=0;n<255;n++)t[n]=a,r[a]=n,a<<=1,a&256&&(a^=285);for(let n=255;n<512;n++)t[n]=t[n-255]})(),Rt.log=function(a){if(a<1)throw new Error("log("+a+")");return r[a]},Rt.exp=function(a){return t[a]},Rt.mul=function(a,n){return a===0||n===0?0:t[r[a]+r[n]]},Rt}var Bn;function Lo(){return Bn||(Bn=1,(function(t){const r=Eo();t.mul=function(a,n){const s=new Uint8Array(a.length+n.length-1);for(let c=0;c<a.length;c++)for(let d=0;d<n.length;d++)s[c+d]^=r.mul(a[c],n[d]);return s},t.mod=function(a,n){let s=new Uint8Array(a);for(;s.length-n.length>=0;){const c=s[0];for(let u=0;u<n.length;u++)s[u]^=r.mul(n[u],c);let d=0;for(;d<s.length&&s[d]===0;)d++;s=s.slice(d)}return s},t.generateECPolynomial=function(a){let n=new Uint8Array([1]);for(let s=0;s<a;s++)n=t.mul(n,new Uint8Array([1,r.exp(s)]));return n}})(Xs)),Xs}var er,Dn;function Ro(){if(Dn)return er;Dn=1;const t=Lo();function r(i){this.genPoly=void 0,this.degree=i,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},r.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const n=new Uint8Array(a.length+this.degree);n.set(a);const s=t.mod(n,this.genPoly),c=this.degree-s.length;if(c>0){const d=new Uint8Array(this.degree);return d.set(s,c),d}return s},er=r,er}var tr={},sr={},rr={},On;function wa(){return On||(On=1,rr.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),rr}var Re={},$n;function ka(){if($n)return Re;$n=1;const t="[0-9]+",r="[A-Z $%*+\\-./:]+";let i="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";i=i.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+i+`)(?:.|[\r
|
|
1
|
+
import{u as xe,r as o,j as e,J as fs,l as F,k as ti,y as si,a0 as ri,a1 as ni,h as Ot,a2 as oa,a3 as ai,a4 as ii,w as oi,a5 as li,v as la,a6 as di,a7 as ci,a8 as ui,a9 as dn,aa as mi,n as ms,P as br,_ as xi,ab as gi,a as fi,b as pi,c as hi,ac as cn,ad as bi,ae as un,i as yi,o as Us}from"./index-Ci5bUF3m.js";import{L as vi}from"./AsyncState-Czik5FUM.js";import{i as ji,S as bs}from"./Switch-CJm0Y6Ab.js";function Ni(t,r){for(var i=0;i<r.length;i++){const a=r[i];if(typeof a!="string"&&!Array.isArray(a)){for(const n in a)if(n!=="default"&&!(n in t)){const s=Object.getOwnPropertyDescriptor(a,n);s&&Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>a[n]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}function wi(t){return t>=1e6?`${(t/1e6).toFixed(t%1e6===0?0:1)}M`:t>=1e3?`${(t/1e3).toFixed((t%1e3===0,0))}K`:String(t)}function ki(t){return t.maxInputTokens>0||t.inputCostPer1MTokens>0||t.outputCostPer1MTokens>0}function Ks(t){if(t.tier)return t.tier;const r=t.id.toLowerCase(),i=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,a=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;return/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(r)?"pro":i.test(r)?"max":a.test(r)?"base":"pro"}const mn={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30"};function da({models:t,selectedModel:r,onSelect:i,loading:a,compact:n,maxVisible:s,showTiers:c}){const{t:d}=xe("settings"),[u,p]=o.useState(""),[x,k]=o.useState(!1),[y,j]=o.useState(""),w=o.useMemo(()=>{let m=t;if(u){const v=u.toLowerCase();m=m.filter($=>$.id.toLowerCase().includes(v))}return y&&(m=m.filter(v=>Ks(v)===y)),m},[t,u,y]),b=o.useMemo(()=>{const m={max:0,pro:0,base:0};for(const v of t)m[Ks(v)]++;return m},[t]),S=s??(n?5:10),h=x?w:w.slice(0,S),P=w.length>S;return a?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),d("modelPicker.loading")]}):t.length===0?e.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:d("modelPicker.empty")}):e.jsxs("div",{className:"space-y-2",children:[c&&t.length>3&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>j(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${y?"bg-surface-overlay text-fg-tertiary hover:text-fg-secondary":"bg-brand-500/20 text-brand-500"}`,children:d("modelPicker.allCount",{count:t.length})}),["max","pro","base"].filter(m=>b[m]>0).map(m=>e.jsx("button",{onClick:()=>j(y===m?"":m),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${y===m?mn[m]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:d("modelPicker.tierCount",{tier:d(`modelRouting.tier.${m}`),count:b[m]})},m))]}),t.length>5&&e.jsx("input",{type:"text",value:u,onChange:m=>{p(m.target.value),k(!1)},placeholder:d("modelPicker.filterPlaceholder"),className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),e.jsx("div",{className:`space-y-1 ${n?"max-h-[280px] overflow-y-auto":""}`,children:h.map(m=>{const v=m.id===r,$=Ks(m);return e.jsxs("button",{type:"button",onClick:()=>i(m.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${v?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${v?"border-brand-500":"border-border-default"}`,children:v&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${v?"text-brand-500":"text-fg-primary"}`,children:m.id}),c&&e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase border ${mn[$]}`,children:d(`modelRouting.tier.${$}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:v&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:d("modelPicker.active")})})]}),ki(m)&&m.maxInputTokens>0&&e.jsx("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:e.jsxs("span",{children:[wi(m.maxInputTokens)," ",d("modelPicker.ctx")]})}),!n&&e.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[m.capabilities.functionCalling&&e.jsx(Et,{label:d("modelPicker.capabilities.tools")}),m.capabilities.vision&&e.jsx(Et,{label:d("modelPicker.capabilities.vision")}),m.capabilities.reasoning&&e.jsx(Et,{label:d("modelPicker.capabilities.reasoning")}),m.capabilities.promptCaching&&e.jsx(Et,{label:d("modelPicker.capabilities.caching")}),m.capabilities.webSearch&&e.jsx(Et,{label:d("modelPicker.capabilities.search")})]})]},m.id)})}),P&&!x&&e.jsx("button",{type:"button",onClick:()=>k(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:d("modelPicker.showAll",{count:w.length})}),x&&P&&e.jsx("button",{type:"button",onClick:()=>k(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:d("modelPicker.showLess")})]})}function Et({label:t}){return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:t})}function Vt({value:t,options:r,placeholder:i,onChange:a}){const{t:n}=xe("settings"),[s,c]=o.useState(!1),[d,u]=o.useState(""),p=o.useRef(null),x=o.useRef(null),k=o.useRef(null),[y,j]=o.useState(-1);o.useEffect(()=>{function m(v){p.current&&!p.current.contains(v.target)&&c(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]),o.useEffect(()=>{s&&x.current&&x.current.focus()},[s]);const w=o.useMemo(()=>{if(!d.trim())return r;const m=d.toLowerCase();return r.filter(v=>v.modelId.toLowerCase().includes(m)||v.modelName.toLowerCase().includes(m)||v.provider.toLowerCase().includes(m)||v.providerLabel.toLowerCase().includes(m)||v.tier&&v.tier.toLowerCase().includes(m))},[r,d]),b=o.useMemo(()=>{const m=new Map;for(const $ of w){const I=$.providerLabel;m.has(I)||m.set(I,[]),m.get(I).push($)}const v={max:0,pro:1,base:2};for(const $ of m.values())$.sort((I,R)=>(v[I.tier??"base"]??9)-(v[R.tier??"base"]??9));return m},[w]),S=o.useMemo(()=>{const m=[];for(const v of b.values())m.push(...v);return m},[b]),h=o.useMemo(()=>{if(!t)return i??n("modelRouting.auto");const m=r.find(v=>`${v.provider}/${v.modelId}`===t);return m?`${m.providerLabel}/${m.modelName}`:t},[t,r,i,n]);function P(m){if(!s){(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),c(!0));return}switch(m.key){case"ArrowDown":m.preventDefault(),j(v=>Math.min(v+1,S.length-1));break;case"ArrowUp":m.preventDefault(),j(v=>Math.max(v-1,-1));break;case"Enter":m.preventDefault(),y===-1?a(""):S[y]&&a(`${S[y].provider}/${S[y].modelId}`),c(!1),u("");break;case"Escape":c(!1),u("");break}}return o.useEffect(()=>{k.current&&y>=0&&k.current.querySelector(`[data-focus-index="${y}"]`)?.scrollIntoView({block:"nearest"})},[y]),e.jsxs("div",{ref:p,className:"relative min-w-0",onKeyDown:P,children:[e.jsx("button",{type:"button",onClick:()=>{c(!s),u(""),j(-1)},className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary text-left truncate focus:outline-none focus:border-brand-500",children:h}),s&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full min-w-[240px] max-h-[280px] bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden flex flex-col",children:[e.jsx("div",{className:"p-1.5 border-b border-border-default",children:e.jsx("input",{ref:x,type:"text",value:d,onChange:m=>{u(m.target.value),j(-1)},placeholder:n("modelPicker.searchPlaceholder")||"Search models...",className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary focus:outline-none focus:border-brand-500"})}),e.jsxs("div",{ref:k,className:"overflow-y-auto flex-1",children:[e.jsx("div",{className:`px-3 py-1.5 text-xs cursor-pointer ${y===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{a(""),c(!1),u("")},children:i??n("modelRouting.auto")}),[...b.entries()].map(([m,v])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider bg-surface-overlay/50 sticky top-0",children:m}),v.map($=>{const I=S.indexOf($),R=`${$.provider}/${$.modelId}`===t;return e.jsxs("div",{"data-focus-index":I,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${I===y?"bg-brand-500/20":R?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,onClick:()=>{a(`${$.provider}/${$.modelId}`),c(!1),u("")},children:[e.jsx("span",{className:"flex-1 truncate text-fg-primary",children:$.modelName}),$.tier&&e.jsx(Ci,{tier:$.tier}),$.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:$.costTier})]},`${$.provider}/${$.modelId}`)})]},m)),S.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:n("modelPicker.empty")})]})]})]})}function Ci({tier:t}){const r={max:"bg-purple-500/20 text-purple-400",pro:"bg-blue-500/20 text-blue-400",base:"bg-gray-500/20 text-gray-400"};return e.jsx("span",{className:`px-1 py-0.5 rounded text-[8px] font-bold uppercase ${r[t]??r.base}`,children:t})}const Si=500,xn=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function Ai({onSave:t,configuredProviders:r}){const{t:i}=xe(["settings","common"]),[a,n]=o.useState({}),[s,c]=o.useState(null),[d,u]=o.useState(!1),[p,x]=o.useState(null),[k,y]=o.useState(!0),[j,w]=o.useState("idle"),[b,S]=o.useState(null),[h,P]=o.useState({}),[m,v]=o.useState(!1),[$,I]=o.useState("idle"),[R,V]=o.useState(null),[C,M]=o.useState(!1),B=o.useRef(null),L=o.useRef(null),U=o.useMemo(()=>r.map(g=>g.name).sort().join(","),[r]);o.useEffect(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{n(g.capabilityRouting?.assignments??{}),c(g.routingDefaultModel??null),u(!0)}).catch(g=>{x(String(g)),u(!0)})},[U]),o.useEffect(()=>{let g=!1;return y(!0),fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{if(g)return;const f=[];for(const K of T.providers)for(const z of K.models)f.push({provider:K.provider,providerLabel:K.displayName,modelId:z.id,modelName:z.name,mode:z.mode,tier:z.tier,costTier:z.costTier,capabilities:z.capabilities});S(f)}).catch(()=>{g||S(null)}).finally(()=>{g||y(!1)}),()=>{g=!0}},[U]),o.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{P(g.suggestions),v(!0)}).catch(()=>v(!0))},[U]);const H=o.useCallback(g=>{w("saving"),t(g).then(()=>{w("saved"),setTimeout(()=>w(T=>T==="saved"?"idle":T),2e3)}).catch(()=>{w("error"),setTimeout(()=>w(T=>T==="error"?"idle":T),3e3)})},[t]),W=o.useCallback((g,T)=>{L.current={capabilityRouting:g!==void 0?{assignments:g}:L.current?.capabilityRouting,routingDefaultModel:T!==void 0?T:L.current?.routingDefaultModel},B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{const f=L.current;L.current=null,f&&H(f)},Si)},[H]),O=o.useMemo(()=>r.flatMap(g=>(g.models??[{id:g.model,name:g.model}]).map(T=>({provider:g.name,providerLabel:g.displayName??g.name,modelId:T.id,modelName:T.name}))),[r]),_=b??O,X=o.useMemo(()=>Object.entries(a).map(([g,T])=>`${g}:${T?.provider??""}/${T?.model??""}`).sort().join("|"),[a]);o.useEffect(()=>{!d||!b||b.length===0||b.some(g=>!!g.modelId)&&(n(g=>{let T=!1;const f={...g};for(const K of xn)for(const z of K.capabilities){const se=f[z];if(!se?.model)continue;const ae=ca(b,z);if(ae.length===0)continue;ae.some(te=>te.provider===se.provider&&te.modelId===se.model)||(delete f[z],T=!0)}return T?(W(f),f):g}),c(g=>{if(!g?.model||b.some(z=>z.provider===g.provider&&z.modelId===g.model))return g;const f=b.find(z=>z.provider==="markus"),K=f?{provider:f.provider,model:f.modelId}:{provider:b[0].provider,model:b[0].modelId};return t({routingDefaultModel:K}),K}))},[d,b,U,W,X]);const ce=o.useCallback(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{n(g.capabilityRouting?.assignments??{}),c(g.routingDefaultModel??null)}).catch(()=>{}),y(!0),fetch("/api/models/routing-candidates",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{const T=[];for(const f of g.providers)for(const K of f.models)T.push({provider:f.provider,providerLabel:f.displayName,modelId:K.id,modelName:K.name,mode:K.mode,tier:K.tier,costTier:K.costTier,capabilities:K.capabilities});S(T)}).catch(()=>{}).finally(()=>y(!1))},[]),oe=o.useCallback(async()=>{if($!=="working"){I("working"),V(null);try{const g=await fetch("/api/settings/llm/restore-recommended",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),T=await g.json().catch(()=>({}));if(!g.ok||!T.ok)throw new Error(T.error??`HTTP ${g.status}`);T.capabilityRouting&&n(T.capabilityRouting.assignments??{}),T.routingDefaultModel!==void 0&&c(T.routingDefaultModel),ce(),I("idle"),w("saved"),setTimeout(()=>w(f=>f==="saved"?"idle":f),2e3)}catch(g){I("error"),V(g instanceof Error?g.message:String(g)),setTimeout(()=>I("idle"),4e3)}}},[$,ce]),ee=_.length>0;return d?p?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:i("modelRouting.loadError",{error:p})}):k&&!ee?e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-secondary",children:[e.jsxs("svg",{className:"w-4 h-4 animate-spin text-brand-500",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),e.jsx("span",{children:i("modelRouting.loadingModels")})]})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Ti,{status:j,t:i}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>M(!0),disabled:$==="working",className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500/40 disabled:opacity-50 transition-colors",children:i($==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),R&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:R})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Vt,{value:s?`${s.provider}/${s.model}`:"",options:_,placeholder:i("modelRouting.defaultModelPlaceholder"),onChange:g=>{if(!g)c(null),W(void 0,null);else{const[T,...f]=g.split("/"),K={provider:T,model:f.join("/")};if(c(K),a.text){const z={...a};delete z.text,n(z),W(z,K)}else W(void 0,K)}}})})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.capabilityAssignDesc")})]}),r.length===0&&e.jsx("div",{className:"p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg text-xs text-yellow-400",children:i("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:xn.map(g=>e.jsx(Pi,{groupKey:g.groupKey,capabilities:g.capabilities,assignments:a,suggestions:h,allModels:_,configuredProviderNames:new Set(r.map(T=>T.name)),t:i,onAssign:(T,f)=>{const K={...a};f?K[T]=f:delete K[T],n(K),W(K)}},g.groupKey))})]}),C&&e.jsx(fs,{variant:"primary",title:i("modelRouting.restoreRecommended"),message:i("modelRouting.restoreConfirm"),confirmLabel:i("common:confirm"),onConfirm:()=>{M(!1),oe()},onCancel:()=>M(!1)})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-surface-overlay rounded w-1/3 mb-3"}),e.jsx("div",{className:"h-3 bg-surface-overlay rounded w-2/3 mb-4"}),e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(g=>e.jsx("div",{className:"h-10 bg-surface-overlay rounded-lg"},g))})]})})}function Pi({groupKey:t,capabilities:r,assignments:i,suggestions:a,allModels:n,configuredProviderNames:s,t:c,onAssign:d}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 px-1",children:c(`modelRouting.capabilityGroups.${t}`)}),e.jsx("div",{className:"space-y-1",children:r.map(u=>{const p=i[u],x=a[u],k=p?`${p.provider}/${p.model}`:"",y=ca(n,u),j=x?y.find(P=>P.provider===x.provider&&P.modelId===x.model)?.modelName??x.model:void 0,w=y.length>0,b=p?Mi(n,p.provider,p.model):void 0,S=p&&!s.has(p.provider),h=!!(p&&w&&u!=="text"&&!y.some(P=>P.provider===p.provider&&P.modelId===p.model));return e.jsxs("div",{className:`flex flex-wrap items-center gap-2 px-3 py-2 rounded-lg md:flex-nowrap md:gap-3 ${h?"bg-red-500/10 border border-red-500/30":S?"bg-yellow-500/10 border border-yellow-500/30":!w&&!p?"bg-amber-500/5 border border-amber-500/20":"bg-surface-overlay/40"}`,children:[e.jsx("div",{className:"w-full shrink-0 md:w-28",children:e.jsx("span",{className:"text-xs text-fg-primary",children:c(`modelRouting.capabilities.${u}`)})}),e.jsx("div",{className:"flex-1 min-w-0",children:h?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs text-red-400",children:["⚠ ",p.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:c("modelRouting.mismatchHint")})]}),e.jsx(Vt,{value:"",options:y,placeholder:c("modelRouting.selectModel"),onChange:P=>{if(!P)d(u,null);else{const[m,...v]=P.split("/");d(u,{provider:m,model:v.join("/")})}}})]}):w?e.jsx(Vt,{value:k,options:y,placeholder:j?`${j} (${c("modelRouting.suggested")})`:c("modelRouting.selectModel"),onChange:P=>{if(!P)d(u,null);else{const[m,...v]=P.split("/");d(u,{provider:m,model:v.join("/")})}}}):e.jsxs("span",{className:"text-xs text-amber-400",children:[c("modelRouting.noModelAvailable"),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",c("modelRouting.addProviderHint")]})]})}),e.jsxs("div",{className:"w-14 shrink-0 flex justify-end",children:[h&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:c("modelRouting.mismatchHint"),children:"⚠"}),!h&&S&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:c("modelRouting.staleProvider"),children:"⚠"}),!h&&!S&&b&&e.jsx(gn,{tier:b}),!h&&!S&&!b&&p&&e.jsx(gn,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:p&&e.jsx("button",{onClick:()=>d(u,null),className:"text-fg-tertiary hover:text-red-400 transition-colors",title:c("modelRouting.clear"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]},u)})})]})}function Mi(t,r,i){return t.find(n=>n.provider===r&&n.modelId===i)?.tier}function Ti({status:t,t:r}){if(t==="idle")return null;const i={idle:"",saving:"text-fg-tertiary",saved:"text-green-400",error:"text-red-400"},a={idle:"",saving:r("modelRouting.saving"),saved:r("modelRouting.saved"),error:r("modelRouting.saveError")};return e.jsx("div",{className:`text-xs font-medium transition-opacity ${i[t]}`,children:a[t]})}function gn({tier:t}){const r={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30",unknown:"bg-gray-500/10 text-fg-tertiary border-border-default"};return e.jsx("span",{className:`px-1.5 py-0.5 text-[9px] rounded font-semibold uppercase border ${r[t]??r.unknown}`,children:t==="unknown"?"—":t})}function ca(t,r){if(r==="text")return t.filter(c=>ji(c));const i={image_generation:["image_generation"],audio_tts:["audio_speech"],audio_stt:["audio_transcription"],video_generation:["video_generation"]},a={image_recognition:["vision"],image_generation:["imageGeneration"],audio_tts:["tts"],audio_stt:["stt"],video_generation:["videoGeneration"]},n=i[r],s=a[r];return t.filter(c=>!!(c.capabilities&&c.capabilities.length>0&&s&&s.some(d=>c.capabilities.includes(d))||n&&c.mode&&n.includes(c.mode)))}function Ei({configuredProviders:t}){const{t:r}=xe("settings"),[i,a]=o.useState(null),[n,s]=o.useState([]),[c,d]=o.useState(null),[u,p]=o.useState(null),x=o.useMemo(()=>t.map(b=>`${b.name}:${b.models?.length??0}`).sort().join(","),[t]),k=o.useCallback(async()=>{d(null);try{const[{agents:b},S]=await Promise.all([F.agents.list({lean:!0}),F.teams.list()]),h=S.teams.map(m=>({id:m.id,name:m.name}));s(h);const P=await Promise.all(b.map(async m=>{try{const $=(await F.agents.get(m.id)).config?.llmConfig;return{id:m.id,name:m.name||m.id,teamId:m.teamId,override:$?.modelMode==="custom"&&$.primary&&$.defaultModel?`${$.primary}/${$.defaultModel}`:null,llmConfig:{modelMode:$?.modelMode,primary:$?.primary??"",defaultModel:$?.defaultModel}}}catch{return{id:m.id,name:m.name||m.id,teamId:m.teamId,override:null,llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}}}}));a(b.length?P:null)}catch(b){d(String(b))}},[x]);o.useEffect(()=>{k()},[k,x]);const y=o.useMemo(()=>{const b=[];for(const S of t)for(const h of S.models??[])b.push({provider:S.name,providerLabel:S.displayName??S.name,modelId:h.id,modelName:h.name??h.id});return b},[t]),j=async(b,S)=>{p(b),d(null);try{if(S){const[h,P]=[S.slice(0,S.lastIndexOf("/")),S.slice(S.lastIndexOf("/")+1)];await F.agents.updateConfig(b,{llmConfig:{modelMode:"custom",primary:h,defaultModel:P}})}else await F.agents.updateConfig(b,{llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}});a(h=>h?.map(P=>P.id===b?{...P,override:S}:P)??h)}catch(h){d(String(h))}finally{p(null)}},w=o.useMemo(()=>{if(!i)return[];const b=new Map,S=[];for(const P of i)if(P.teamId){const m=b.get(P.teamId)??[];m.push(P),b.set(P.teamId,m)}else S.push(P);const h=[];S.length&&h.push({key:"ungrouped",label:r("perAgentModel.ungrouped",{defaultValue:"Ungrouped"}),rows:S});for(const P of n){const m=b.get(P.id);m?.length&&h.push({key:`team:${P.id}`,label:P.name,rows:m})}for(const[P,m]of b)n.some(v=>v.id===P)||h.push({key:`team:${P}`,label:P,rows:m});return h},[i,n,r]);return i===null&&!c?e.jsx("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 text-sm text-fg-tertiary",children:r("common:loading",{defaultValue:"Loading…"})}):e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4 md:p-5 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:r("perAgentModel.title",{defaultValue:"Per-agent default model"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r("perAgentModel.desc",{defaultValue:'Bind a specific provider+model to an agent, or leave it following the global default. This is what the composer "Apply to current agent" writes.'})})]})}),c&&e.jsx("div",{className:"text-xs text-red-500",children:c}),(!i||i.length===0)&&!c&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:r("perAgentModel.noAgents",{defaultValue:"No agents available."})}),i&&i.length>0&&e.jsx("div",{className:"space-y-5",children:w.map(b=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary truncate",children:b.label}),e.jsx("span",{className:"text-[10px] text-fg-tertiary/70 tabular-nums shrink-0",children:b.rows.length})]}),e.jsx("div",{className:"space-y-2",children:b.rows.map(S=>e.jsxs("div",{className:"flex flex-col gap-2 text-sm md:flex-row md:items-center md:justify-between md:gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:S.name}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 truncate",children:S.id})]}),e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2 md:w-[320px]",children:[S.override?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{value:S.override,options:y,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:h=>{j(S.id,h||null)}}),e.jsx("button",{type:"button",disabled:u===S.id,onClick:()=>{j(S.id,null)},className:"shrink-0 px-2.5 py-1.5 text-xs border border-border-default rounded-lg hover:bg-surface-base disabled:opacity-40 transition-colors",children:r("perAgentModel.reset",{defaultValue:"Reset"})})]}):e.jsx(Vt,{value:"",options:y,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:h=>{j(S.id,h||null)}}),u===S.id&&e.jsx("span",{className:"shrink-0 text-[10px] text-fg-tertiary",children:r("common:loading",{defaultValue:"…"})})]})]},S.id))})]},b.key))})]})}let xs=[],ls=null;async function Li(){return ls||(ls=(async()=>{try{xs=(await F.modelCatalog.providerCatalog()).providers??[]}catch{xs=[]}return xs})(),ls)}function Ri(){const[t,r]=o.useState(xs);return o.useEffect(()=>{let i=!0;return Li().then(a=>{i&&r(a)}),()=>{i=!1}},[]),t}const Ii="integrations.platforms",kr=(t,r)=>`settings:${Ii}.${t}.${r}`,Bi={feishu:"https://open.feishu.cn/app",telegram:"https://t.me/BotFather",slack:"https://api.slack.com/apps",whatsapp:"https://developers.facebook.com/apps",discord:"https://discord.com/developers/applications"};function Di(t){return Bi[t]}function Oi(t,r){return t(kr(r.id,"label"),{defaultValue:r.label})}function ua(t,r,i){const a=kr(r,`fields.${i.key}`);return{label:t(`${a}.label`,{defaultValue:i.label}),help:i.help?t(`${a}.help`,{defaultValue:i.help}):void 0,placeholder:i.placeholder?t(`${a}.placeholder`,{defaultValue:i.placeholder}):void 0,options:i.options?.map(n=>({value:n.value,label:t(`${a}.options.${n.value}`,{defaultValue:n.label})}))}}function $i(t,r,i){const a=[],n=kr(i,"guide");for(let s=1;s<=20;s+=1){const c=`${n}.step${s}.title`;if(!t.exists(c))break;const d=`${n}.step${s}.desc`,u=t.exists(d)?r(d):void 0;a.push({title:r(c),...u?{desc:u}:{}})}return a}function Vi(t){return t("settings:integrations.guide.heading",{defaultValue:"Setup guide"})}function _i(t){return t.type==="boolean"?t.default===!0:t.multiple?Array.isArray(t.default)?[...t.default]:[]:t.default!==void 0?t.default:""}function ps(t,r){return r==null?!0:t.type==="boolean"?!1:t.multiple?!Array.isArray(r)||r.length===0:typeof r=="string"?r.trim()==="":!1}function fn(t){const r={};for(const i of t.fields){if(i.secret){r[i.key]="";continue}const a=t.values[i.key];r[i.key]=a??_i(i)}return r}function pn(t,r,i={}){const a=[];for(const n of t)if(n.required){if(n.secret){if(!ps(n,r[n.key]))continue;i[n.key]?.hasValue||a.push(n.key);continue}ps(n,r[n.key])&&a.push(n.key)}return a}function Fi(t,r,i){const a={enabled:i};for(const n of t.fields){const s=r[n.key];if(n.secret){if(ps(n,s))continue;a[n.key]=s;continue}s!==void 0&&(a[n.key]=s)}return a}function Ui(t){return t.filter(r=>r.required||r.type==="agent")}function Ki(t){return t.filter(r=>!(r.required||r.type==="agent"))}function yr(t){return Array.isArray(t)?`[${t.map(yr).join(",")}]`:t&&typeof t=="object"?`{${Object.entries(t).filter(([,i])=>i!==void 0).sort(([i],[a])=>i<a?-1:i>a?1:0).map(([i,a])=>`${JSON.stringify(i)}:${yr(a)}`).join(",")}}`:JSON.stringify(t)??"null"}function Hi(t){return yr({id:t.id,enabled:t.enabled,fields:t.fields.map(r=>({key:r.key,type:r.type,required:r.required,secret:r.secret===!0,multiple:r.multiple===!0,default:r.default??null,value:r.secret?!1:t.values[r.key]??null,hasValue:r.secret?t.secrets[r.key]?.hasValue===!0:!1}))})}function zi(t){const r=t.ok===!0||t.success===!0;return{ok:r,text:t.message??t.error??(r?"OK":"Failed"),code:t.code}}function qi(t){return t?.status==="awaiting_reply"||t?.status==="awaiting_inbound"}function Wi(t,r=!1){return t.hasConfig?t.enabled?t.lastVerifiedAt||r?"verified":"unverified":"off":"unconfigured"}function Gi(t){return{id:"",platform:t.id,label:"",enabled:!0,connected:!1,hasConfig:!1,capabilities:t.capabilities,fields:t.fields,values:{},secrets:Ji(t.fields),agentId:null,notifyAgentId:null,channels:[],lastError:null,canListChannels:!1,lastVerifiedAt:null}}function Ji(t){const r={};for(const i of t)i.secret&&(r[i.key]={hasValue:!1});return r}function Yi(t){return t.id===""}function hn(t){return{id:t.platform,label:t.label,capabilities:t.capabilities,fields:t.fields,defaultEnabled:!1,enabled:t.enabled,connected:t.connected,hasConfig:t.hasConfig,values:{...t.values,agentId:t.agentId??""},secrets:t.secrets}}function Hs(t,r){return t.find(i=>i.nativeId===r)}function bn(t,r,i,a){const n=t.filter(s=>s.nativeId!==r);return n.push({nativeId:r,kind:a??null,agentId:i}),n.sort((s,c)=>s.nativeId.localeCompare(c.nativeId))}function yn(t,r){return t.filter(i=>i.nativeId!==r)}function Qi(t,r){const i=new Set(r.map(a=>a.id));return t.filter(a=>!i.has(a.nativeId))}function Zi(t,r){const i=r.trim().toLowerCase();return i?t.filter(a=>a.name.toLowerCase().includes(i)||a.id.toLowerCase().includes(i)):t}function Xi(t){const r=new Map;for(const i of t){const a=r.get(i.platform);a?a.push(i):r.set(i.platform,[i])}return[...r.entries()].map(([i,a])=>({platform:i,instances:a}))}function eo(t,r,i={}){const a=i.devMode??!1,n=new Set(t.filter(d=>d.devOnly&&!a).map(d=>d.id)),s=[],c=new Set;for(const d of t)n.has(d.id)||c.has(d.id)||(c.add(d.id),s.push(d.id));for(const d of r)n.has(d.platform)||c.has(d.platform)||(c.add(d.platform),s.push(d.platform));return s}function to(t,r,i){const[a,n]=o.useState([]),[s,c]=o.useState(null),[d,u]=o.useState(!1),p=o.useRef(t);p.current=t;const x=o.useRef(0),k=o.useCallback(()=>{if(!i||!r)return;const y=++x.current;u(!0),p.current(r).then(j=>{y===x.current&&(n(j.channels??[]),c(j.error??null))}).catch(j=>{y===x.current&&(n([]),c(j instanceof Error?j.message:String(j)))}).finally(()=>{y===x.current&&u(!1)})},[i,r]);return o.useEffect(()=>(k(),()=>{x.current+=1}),[k]),{channels:a,error:s,loading:d,reloadChannels:k}}const ma=/^notify[A-Z]/,xa="notifyEnabled";function so(t){return t.find(r=>r.key===xa)}function ro(t){return t.notifyTarget==="chat"||t.notifyTarget==="user"||ma.test(t.key)}function _t(t){return t.filter(r=>r.notifyTarget==="chat"||r.notifyTarget==="user")}function no(t){return t.filter(r=>!r.notifyTarget&&!r.secret&&r.key!==xa&&ma.test(r.key))}function ao(t){return t.filter(ro)}function ga(t){return _t(t).find(r=>r.notifyTarget==="chat")}function io(t,r){const i=_t(t);return i.length===0?"unsupported":i.some(a=>!ps(a,r[a.key]))?"configured":"not-configured"}function vn(t){return typeof t=="string"?{value:t,label:t}:{value:t.value,label:t.label??t.value,hint:t.hint}}function jn(t,r,i){const a=t.label.toLowerCase(),n=t.value.toLowerCase(),s=`${a} ${n} ${(t.hint??"").toLowerCase()}`;for(const d of r)if(!s.includes(d))return null;if(a.startsWith(i)||n.startsWith(i))return 0;const c=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[\\s./:_-])${c}`).test(a)?1:2}function fa({value:t,options:r,onChange:i,placeholder:a,filterPlaceholder:n,emptyText:s,customHint:c,disabled:d,ariaLabel:u,className:p}){const[x,k]=o.useState(!1),[y,j]=o.useState(""),[w,b]=o.useState(!1),[S,h]=o.useState(-1),P=o.useRef(null),m=o.useRef(null),v=o.useRef(null),$=o.useRef(null),I=o.useId(),[R,V]=o.useState({}),C=o.useMemo(()=>t?r.map(vn).find(O=>O.value===t)?.label??t:a??"",[t,r,a]);o.useEffect(()=>{x||(j(C),b(!1))},[C,x]),o.useEffect(()=>{function O(_){const X=_.target;$.current?.contains(X)||P.current&&!P.current.contains(X)&&k(!1)}return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[]);function M(){const O=m.current;if(!O)return;const _=O.getBoundingClientRect(),X=Math.max(_.width,240),ce=window.innerHeight-_.bottom-8,oe=ce<180&&_.top>ce;V({position:"fixed",left:_.left,width:X,maxHeight:Math.min(260,oe?Math.max(_.top-12,120):ce),...oe?{bottom:window.innerHeight-_.top+4}:{top:_.bottom+4}})}o.useLayoutEffect(()=>{if(!x)return;M();const O=()=>M();return window.addEventListener("scroll",O,!0),window.addEventListener("resize",O),()=>{window.removeEventListener("scroll",O,!0),window.removeEventListener("resize",O)}},[x]);const B=o.useMemo(()=>{const O=r.map(vn),_=y.trim(),X=w?_.toLowerCase().split(/\s+/).filter(Boolean):[],ce=[];O.forEach((g,T)=>{const f=X.length?jn(g,X,_.toLowerCase()):0;f!==null&&ce.push({row:g,score:f,idx:T})}),ce.sort((g,T)=>g.score-T.score||g.idx-T.idx);const oe=[];if(a!==void 0){const g={value:"",label:a};(X.length?jn(g,X,_.toLowerCase()):0)!==null&&oe.push(g)}oe.push(...ce.map(g=>g.row));const ee=_&&!O.some(g=>g.value.toLowerCase()===_.toLowerCase());return c&&w&&ee&&oe.push({value:_,label:_,custom:!0}),oe},[r,y,w,a,c]);o.useEffect(()=>{if(!x||S<0||!v.current)return;v.current.querySelector(`[data-index="${S}"]`)?.scrollIntoView({block:"nearest"})},[S,x,B.length]);function L(){d||(j(C),b(!1),h(B.findIndex(O=>O.value===t)),k(!0),requestAnimationFrame(()=>m.current?.select()))}function U(){k(!1),j(C),b(!1),h(-1)}function H(O){i(O.value),k(!1),j(O.value?O.label:a??""),b(!1),h(-1),m.current?.focus()}function W(O){if(O.key==="ArrowDown"||O.key==="ArrowUp"){if(O.preventDefault(),!x){L();return}h(_=>{const X=O.key==="ArrowDown"?_+1:_-1;return Math.max(-1,Math.min(X,B.length-1))});return}if(O.key==="Enter"){if(!x){O.preventDefault(),L();return}const _=B[S];_?(O.preventDefault(),H(_)):U();return}if(O.key==="Escape"&&x){O.preventDefault(),O.stopPropagation(),U();return}O.key==="Tab"&&x&&U()}return e.jsxs("div",{ref:P,className:`relative ${p??""}`,children:[e.jsx("input",{ref:m,type:"text",role:"combobox","aria-expanded":x,"aria-controls":x?I:void 0,"aria-autocomplete":"list","aria-label":u,"aria-activedescendant":x&&S>=0?`${I}-opt-${S}`:void 0,disabled:d,value:x?y:C,placeholder:n,onMouseDown:()=>{x?k(!1):L()},onChange:O=>{x||k(!0),j(O.target.value),b(!0),h(0)},onKeyDown:W,onBlur:()=>{x&&U()},className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none truncate"}),x&&ti.createPortal(e.jsxs("div",{id:I,role:"listbox",ref:O=>{v.current=O,$.current=O},style:R,onMouseDown:O=>O.preventDefault(),"data-keep-edit-focus":!0,className:"z-50 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1",children:[B.map((O,_)=>e.jsxs("div",{id:`${I}-opt-${_}`,"data-index":_,role:"option","aria-selected":O.value===t,onMouseDown:X=>{X.preventDefault(),H(O)},className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${_===S?"bg-brand-500/20":O.value===t?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,children:[e.jsx("span",{className:`flex-1 truncate ${O.custom?"text-brand-500":"text-fg-primary"}`,children:O.label}),O.hint&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:O.hint}),O.custom&&c&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:typeof c=="function"?c(O.value):c})]},`${O.custom?"custom:":""}${O.value}`)),B.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:s})]}),document.body)]})}async function oo(){const{agents:t}=await F.agents.list({lean:!0});return t.map(r=>({id:r.id,name:r.name,role:r.role}))}let ds=null;function pa(){return ds||(ds=oo().catch(t=>{throw ds=null,t})),ds}function lo(t=pa,r=!0){const[i,a]=o.useState([]);return o.useEffect(()=>{if(!r)return;let n=!0;return t().then(s=>{n&&a(s)}).catch(()=>{n&&a([])}),()=>{n=!1}},[t,r]),i}function hs({value:t,options:r,onChange:i,fieldKey:a,ariaLabel:n,disabled:s}){const{t:c}=xe(["settings"]);return e.jsx(fa,{value:typeof t=="string"?t:"",options:r.map(d=>({value:d.id,label:d.name,hint:d.role})),onChange:d=>i(a,d),disabled:s,placeholder:c("settings:integrations.agentSelect.none",{defaultValue:"Not bound"}),filterPlaceholder:c("settings:integrations.agentSelect.search",{defaultValue:"Search agents…"}),emptyText:c("settings:integrations.agentSelect.empty",{defaultValue:"No matching agent"}),ariaLabel:n??c("settings:integrations.agentSelect.none",{defaultValue:"Not bound"}),className:"w-full"})}function ha({loading:t,error:r,onReload:i,buttonTestId:a,errorTestId:n,empty:s=!1}){const{t:c}=xe(["settings","common"]);return e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-h-[1.25rem]",children:[e.jsxs("button",{type:"button",onClick:i,disabled:t,"aria-busy":t,"data-testid":a,className:"inline-flex items-center gap-1 text-[11px] font-medium text-fg-tertiary hover:text-fg-secondary disabled:opacity-60 transition-colors",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${t?"animate-spin":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t?c("settings:instances.channels.refreshing",{defaultValue:"Refreshing…"}):s?c("settings:integrations.loadGroups",{defaultValue:"Load groups"}):c("settings:instances.channels.refresh",{defaultValue:"Refresh"})]}),r&&e.jsx("span",{"data-testid":n,className:"text-[11px] text-red-600",children:r})]})}const gs="rounded-xl border border-border-default bg-surface-secondary p-4",Dt="text-sm font-semibold text-fg-primary",ba="flex flex-wrap items-center justify-between gap-x-4 gap-y-2",co="flex flex-wrap items-start justify-between gap-x-4 gap-y-2",vr="shrink-0 text-sm text-fg-secondary",ya="flex-1 min-w-[10rem] flex justify-end",bt="text-xs text-fg-tertiary",jr="w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors";function Nr(t){return"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border transition-colors "+(t?"bg-selected-bg border-selected-border text-selected-fg":"bg-surface-primary border-border-default text-fg-secondary hover:border-fg-tertiary")}const uo={verified:"bg-green-500/10 text-green-600 border-green-500/30",unverified:"bg-amber-500/10 text-amber-600 border-amber-500/30",off:"bg-gray-500/10 text-fg-tertiary border-border-default",unconfigured:"bg-gray-500/10 text-fg-tertiary border-border-default"},mo={verified:"bg-green-500",unverified:"bg-amber-400",off:"bg-gray-400",unconfigured:"bg-gray-400"},xo={verified:"settings:integrations.status.verified",unverified:"settings:integrations.status.unverified",off:"settings:integrations.status.off",unconfigured:"settings:integrations.status.unconfigured"},go={verified:"Connected",unverified:"Not verified",off:"Off",unconfigured:"Not configured"};function fo({state:t}){const{t:r}=xe(["settings"]);return e.jsxs("span",{"data-testid":"integration-status","data-state":t,"data-connected":t==="verified"?"true":"false",className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${uo[t]}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${mo[t]}`}),r(xo[t],{defaultValue:go[t]})]})}function $t({type:t,text:r}){return e.jsx("div",{"data-testid":t==="ok"?"integration-msg-ok":"integration-msg-err",className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${t==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-600 border border-red-500/30"}`,children:r})}function Lt({label:t,control:r,help:i,htmlFor:a,start:n=!1}){return e.jsxs("div",{children:[e.jsxs("div",{className:n?co:ba,children:[a?e.jsx("label",{htmlFor:a,className:vr,children:t}):e.jsx("span",{className:vr,children:t}),e.jsx("div",{className:ya,children:r})]}),i?e.jsx("p",{className:`${bt} mt-1.5`,children:i}):null]})}function po({field:t,value:r,hasStored:i,onChange:a,platformId:n="",agentOptions:s=[]}){const{t:c}=xe(["settings"]),d=`integration-field-${t.key}`,[u,p]=o.useState(!1),x=o.useMemo(()=>n?ua(c,n,t):{label:t.label,help:t.help,placeholder:t.placeholder,options:t.options},[c,n,t]),k=x.label,y=x.help,j=x.placeholder,w=x.options??t.options??[],b=e.jsxs(e.Fragment,{children:[k,t.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),S=t.secret&&i?c("settings:integrations.secretStored"):y||void 0;if(t.type==="boolean"){const m=r===!0;return e.jsx(Lt,{label:k,help:y,control:e.jsx(bs,{checked:m,onChange:v=>a(t.key,v),label:k,size:"md",testId:`integration-field-${t.key}`})})}if(t.type==="agent")return e.jsx(Lt,{label:b,help:S,control:e.jsx("div",{className:"w-full","data-testid":`integration-field-${t.key}`,children:e.jsx(hs,{value:r,options:s,onChange:a,fieldKey:t.key,ariaLabel:k})})});if(t.type==="select"&&t.multiple){const m=Array.isArray(r)?r.map(String):[];return e.jsx(Lt,{start:!0,label:b,help:S,control:e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5","data-testid":`integration-field-${t.key}`,children:w.map(v=>{const $=m.includes(v.value);return e.jsx("button",{type:"button","aria-pressed":$,"data-option":v.value,onClick:()=>a(t.key,$?m.filter(I=>I!==v.value):[...m,v.value]),className:Nr($),children:v.label},v.value)})})})}if(t.type==="select")return e.jsx(Lt,{label:b,help:S,htmlFor:d,control:e.jsx("select",{id:d,"data-testid":`integration-field-${t.key}`,value:typeof r=="string"?r:"",onChange:m=>a(t.key,m.target.value),className:jr,children:(t.options??[]).map(m=>{const v=w.find($=>$.value===m.value)?.label??m.label;return e.jsx("option",{value:m.value,children:v},m.value)})})});const h=t.type==="password",P=t.type==="number";return e.jsx(Lt,{label:b,help:S,htmlFor:d,control:e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:d,"data-testid":`integration-field-${t.key}`,type:P?"number":h&&!u?"password":"text",value:r==null?"":String(r),placeholder:h&&i?c("settings:integrations.secretStoredPlaceholder"):j,onChange:m=>a(t.key,m.target.value),className:`${jr}${h?" font-mono pr-10":""}`}),h&&e.jsx("button",{type:"button","aria-label":u?c("settings:integrations.hide",{defaultValue:"Hide"}):c("settings:integrations.show",{defaultValue:"Show"}),onClick:()=>p(m=>!m),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:u?"🙈":"👁"})]})})}function yt({status:t,draft:r,fields:i=t.fields,onChange:a,agentOptions:n=[]}){return e.jsx(e.Fragment,{children:i.map(s=>e.jsx(po,{field:s,platformId:t.id,value:r[s.key],hasStored:t.secrets[s.key]?.hasValue===!0,agentOptions:n,onChange:a},s.key))})}const Nn={pending:"bg-amber-400 animate-pulse",ok:"bg-emerald-500",failed:"bg-red-500"};function wn({label:t,hint:r,leg:i}){const{t:a}=xe("settings");return e.jsxs("div",{className:"flex items-start gap-2.5","data-testid":"connection-test-leg",children:[e.jsx("span",{className:`mt-1.5 w-2 h-2 rounded-full shrink-0 ${Nn[i.state]??Nn.pending}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-fg-primary",children:t}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 break-words",children:i.state==="ok"?i.detail??a("integrations.connectionTest.legOk",{defaultValue:"Verified"}):i.state==="failed"?i.detail??a("integrations.connectionTest.legFailed",{defaultValue:"Failed"}):r})]})]})}function ho(t,r){const i=new Date(t);return Number.isNaN(i.getTime())?t:i.toLocaleString(r,{dateStyle:"medium",timeStyle:"short"})}function bo({test:t,starting:r,onStart:i,lastVerifiedAt:a=null}){const{t:n,i18n:s}=xe("settings"),c=(()=>{if(!t)return null;switch(t.status){case"awaiting_reply":return n("integrations.connectionTest.awaitingReply",{defaultValue:"A test message was sent to {{target}}. Reply to it in {{platform}} to finish — include {{code}} if you can.",target:t.targetChannelName??t.targetChannelId??"",platform:t.platform,code:t.code??""});case"awaiting_inbound":return n("integrations.connectionTest.awaitingInbound",{defaultValue:"Send any message to this bot in {{platform}} — we will answer it to confirm both directions.",platform:t.platform});case"verified":return n("integrations.connectionTest.verified",{defaultValue:"Both directions work — Markus can send to and receive from this bot."});case"expired":return n("integrations.connectionTest.expired",{defaultValue:"No reply arrived in time. Check the bot is in the conversation, then try again."});default:return null}})();return e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:n("integrations.connectionTest.title",{defaultValue:"Connection verification"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:n("integrations.connectionTest.subtitle",{defaultValue:"Sends a real message and waits for your reply — proves both directions."})})]}),t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(wn,{label:n("integrations.connectionTest.outbound",{defaultValue:"Outbound (bot → IM)"}),hint:n("integrations.connectionTest.outboundPending",{defaultValue:"Not sent yet"}),leg:t.outbound}),e.jsx(wn,{label:n("integrations.connectionTest.inbound",{defaultValue:"Inbound (IM → bot)"}),hint:n("integrations.connectionTest.inboundPending",{defaultValue:"Waiting for your reply"}),leg:t.inbound})]}),c&&(t.status==="verified"||t.status==="expired"?e.jsx($t,{type:t.status==="verified"?"ok":"err",text:c}):e.jsx("div",{className:"px-3 py-2 rounded-lg text-xs bg-surface-tertiary text-fg-secondary",children:c}))]}):a?e.jsx($t,{type:"ok",text:n("integrations.connectionTest.lastVerified",{defaultValue:"Verified {{when}}.",when:ho(a,s.language)})}):e.jsx("div",{className:"text-xs text-fg-tertiary",children:n("integrations.connectionTest.idle",{defaultValue:"Not verified yet. Verify to send a real message to the bot and confirm the round trip."})}),e.jsxs("button",{type:"button",onClick:i,disabled:r,"data-testid":"connection-test-start",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-fg-primary border border-border-default rounded-lg hover:bg-surface-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[r?e.jsx("div",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):null,t?n("integrations.connectionTest.retry",{defaultValue:"Verify again"}):n("integrations.connectionTest.start",{defaultValue:"Verify connection"})," "]})]})}function yo({status:t,values:r,setValue:i,channels:a=[],canListChannels:n=!1,channelsLoading:s=!1,channelsError:c=null,onReloadChannels:d=()=>{},channelsGuidance:u=null,testSlot:p}){const{t:x}=xe(["settings","common"]),[k,y]=o.useState(!1),j=_t(t.fields),w=no(t.fields),b=so(t.fields),S=io(t.fields,r),h=ga(t.fields),P=b?r[b.key]!==!1:!0,m=n&&h?h.key:null,v=m!==null?String(r[m]??""):"",$={configured:x("settings:instances.notify.reachConfigured",{defaultValue:"Configured"}),"not-configured":x("settings:instances.notify.reachNotConfigured",{defaultValue:"Not set"}),unsupported:x("settings:instances.notify.reachUnsupported",{defaultValue:"Not supported"})},I={configured:"text-green-600","not-configured":"text-amber-600",unsupported:"text-fg-tertiary"},R={configured:"bg-green-500","not-configured":"bg-amber-400",unsupported:"bg-gray-400"},V=x("settings:instances.notify.guidanceFallback",{defaultValue:"This platform can’t list its conversations — enter the destination ID manually."}),C=u?x(u,{defaultValue:V}):V,M=m!==null&&!s&&v!==""&&!a.some(L=>L.id===v),B="text-xs font-medium text-fg-secondary mb-2";return e.jsxs("section",{"data-testid":"notification-panel","data-reachability":S,className:gs,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsx("h3",{className:Dt,children:x("settings:instances.notify.title",{defaultValue:"Notifications"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs ${I[S]}`,"data-testid":"notification-reachability","data-state":S,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${R[S]}`}),$[S]]}),b&&e.jsx(bs,{checked:P,onChange:L=>i(b.key,L),label:x("settings:instances.notify.masterLabel",{defaultValue:"Enable notifications"}),size:"md",testId:`integration-field-${b.key}`})]})]}),e.jsxs("div",{className:`space-y-4${P?"":" opacity-60"}`,children:[j.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:B,children:x("settings:instances.notify.destination",{defaultValue:"Destination"})}),m!==null&&e.jsxs("div",{"data-testid":"notification-chat-list",className:"space-y-1.5",children:[e.jsx(ha,{loading:s,error:c,onReload:d,empty:a.length===0,buttonTestId:"notification-chat-refresh",errorTestId:"notification-chat-error"}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(L=>e.jsx("button",{type:"button","aria-pressed":v===L.id,"data-testid":`notification-chat-pick-${L.id}`,onClick:()=>i(m,L.id),className:Nr(v===L.id),children:L.name},L.id))}),a.length===0&&!s&&!c&&e.jsx("p",{"data-testid":"notification-chat-empty",className:bt,children:x("settings:instances.notify.pickEmpty",{defaultValue:"Add the bot to a group in your IM → click “Load groups” → pick it from the list."})}),M&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:e.jsx("button",{type:"button","aria-pressed":"true","data-testid":"notification-chat-pick-current",onClick:()=>i(m,v),className:Nr(!0),children:v})})]}),m===null&&e.jsx("p",{"data-testid":"notification-chat-guidance",className:bt,children:C}),m!==null?e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{type:"button","aria-expanded":k,"data-testid":"notification-manual-toggle",onClick:()=>y(L=>!L),className:"inline-flex items-center gap-1 text-xs font-medium text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${k?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),x("settings:instances.notify.manualInput",{defaultValue:"Enter an ID manually"})]}),k&&e.jsx("div",{className:"space-y-4 mt-3","data-testid":"notification-manual-fields",children:e.jsx(yt,{status:t,draft:r,fields:j,onChange:i})})]}):e.jsx("div",{className:"mt-2",children:e.jsx(yt,{status:t,draft:r,fields:j,onChange:i})})]}),w.length>0&&e.jsxs("div",{"data-testid":"notification-preferences",className:"space-y-3",children:[e.jsx("div",{className:B,children:x("settings:instances.notify.content",{defaultValue:"What to send"})}),e.jsx(yt,{status:t,draft:r,fields:w,onChange:i})]}),p]})]})}const ht={fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round"},vo={color:"#64748b",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M21 12a8 8 0 0 1-11.6 7.1L4 21l1.9-5.4A8 8 0 1 1 21 12z"})})},jo={feishu:{color:"#3370ff",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M21 5 3 11l5.5 2.2L19 7l-7.5 8.3L12 21l3-4.5L21 5z"})})},telegram:{color:"#229ed9",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M22 3 2.5 10.5l5.5 2L21 6l-9 10v5l3.5-4.5L20 19 22 3z"})})},slack:{color:"#611f69",glyph:e.jsx("g",{...ht,children:e.jsx("path",{d:"M9.5 3 7.5 20M16.5 4 14.5 21M3.5 9h17M2.5 15h17"})})},whatsapp:{color:"#1faa59",glyph:e.jsxs("g",{...ht,children:[e.jsx("path",{d:"M21 11.5a8.5 8.5 0 0 1-12.6 7.4L3 20.5l1.6-5.3A8.5 8.5 0 1 1 21 11.5z"}),e.jsx("path",{d:"M9 8.8c.3 2.6 2.6 4.9 5.2 5.2l1-1.3 1.9.8"})]})},discord:{color:"#5865f2",glyph:e.jsxs("g",{...ht,children:[e.jsx("rect",{x:"3",y:"7",width:"18",height:"10",rx:"4.5"}),e.jsx("path",{d:"M7.5 11.5h3M9 10v3"}),e.jsx("circle",{cx:"15",cy:"10.7",r:"0.9"}),e.jsx("circle",{cx:"17.3",cy:"13",r:"0.9"})]})}};function No(t){return jo[t]??vo}function va({id:t,size:r=36}){const i=No(t);return e.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded-lg",style:{width:r,height:r,backgroundColor:`${i.color}1a`,color:i.color},"aria-hidden":"true","data-testid":`platform-icon-${t}`,children:e.jsx("svg",{width:Math.round(r*.58),height:Math.round(r*.58),viewBox:"0 0 24 24",children:i.glyph})})}function wo({status:t,configured:r,canListChannels:i=!1,channelsGuidance:a=null}){const{t:n,i18n:s}=xe(["settings","common"]),[c,d]=o.useState(!r),u=o.useMemo(()=>{const k=$i(s,n,t.id);if(_t(t.fields).length===0)return k;const y=n("settings:integrations.guide.destinationStep.desc",{defaultValue:"Pick the chat or user that should receive approvals and notifications — without it they have nowhere to go."}),j=i?{title:n("settings:integrations.guide.selectChatStep.title",{defaultValue:"Pick the notification group"}),desc:n("settings:integrations.guide.selectChatStep.desc",{defaultValue:"Add the bot to a group in your IM → click “Load groups” → pick it from the list."})}:{title:n("settings:integrations.guide.destinationStep.title",{defaultValue:"Set a notification destination"}),desc:a?n(a,{defaultValue:y}):y};return[...k,j]},[s,n,t.id,t.fields,i,a]),p=Di(t.id),x=n(`settings:integrations.platforms.${t.id}.description`,{defaultValue:""});return e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl overflow-hidden","data-testid":"integration-guide","data-open":c?"true":"false",children:[e.jsxs("button",{type:"button",onClick:()=>d(k=>!k),"aria-expanded":c,"data-testid":"integration-guide-toggle",className:"w-full flex items-center gap-2.5 px-4 py-3 text-left hover:bg-white/[0.02] transition-colors",children:[e.jsx("span",{className:"text-base leading-none","aria-hidden":"true",children:"🧭"}),e.jsx("span",{className:"flex-1 text-sm font-medium text-fg-primary",children:Vi(n)}),e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${c?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"px-4 pb-4 pt-1 space-y-3 border-t border-border-default",children:[x&&e.jsx("p",{className:"text-xs text-fg-tertiary",children:x}),u.length>0?e.jsx("ol",{className:"space-y-2.5","data-testid":"integration-guide-steps",children:u.map((k,y)=>e.jsxs("li",{className:"flex gap-3",children:[e.jsx("span",{className:"shrink-0 w-5 h-5 mt-0.5 rounded-full bg-brand-500/15 text-brand-600 text-[11px] font-semibold flex items-center justify-center",children:y+1}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-xs font-medium text-fg-primary",children:k.title}),k.desc&&e.jsx("span",{className:"block text-[11px] text-fg-tertiary mt-0.5",children:k.desc})]})]},k.title))}):e.jsx("p",{className:"text-xs text-fg-tertiary",children:n("settings:integrations.guide.fallback",{defaultValue:"Fill in the credentials from the platform’s developer console below."})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[p&&e.jsxs("a",{href:p,target:"_blank",rel:"noreferrer","data-testid":"integration-guide-console",className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 transition-colors",children:[n("settings:integrations.guide.openConsole",{defaultValue:"Open developer console"}),e.jsx("span",{"aria-hidden":"true",children:"↗"})]}),t.docsUrl&&e.jsx("a",{href:t.docsUrl,target:"_blank",rel:"noreferrer",className:"text-xs text-brand-600 hover:text-brand-700",children:n("settings:integrations.docs",{defaultValue:"Setup docs"})})]})]})]})}const ja={create:(t,r)=>F.settings.createInstance(t,r).then(i=>i.instance),save:(t,r)=>F.settings.saveInstance(t,r).then(()=>{}),test:(t,r)=>F.settings.testInstance(t,r),remove:t=>F.settings.deleteInstance(t).then(()=>{}),listChannels:t=>F.settings.listInstanceChannels(t),saveChannels:(t,r)=>F.settings.saveInstanceChannels(t,r).then(()=>{}),startConnectionTest:(t,r)=>F.settings.startConnectionTest(t,r).then(i=>i.test),getConnectionTest:t=>F.settings.getConnectionTest(t).then(r=>r.test)},ko=700;function kn({instance:t,client:r=ja,extras:i={},onChanged:a,onCreated:n,loadAgents:s,defaultExpanded:c}){const{t:d}=xe(["settings","common"]),u=Yi(t),[p,x]=o.useState(c??u),[k,y]=o.useState(!1),j=o.useMemo(()=>hn(t),[t]),[w,b]=o.useState(t.label),[S,h]=o.useState(()=>fn(j)),[P,m]=o.useState(t.enabled),[v,$]=o.useState(t.channels),[I,R]=o.useState(typeof t.notifyAgentId=="string"?t.notifyAgentId:""),[V,C]=o.useState({kind:"idle"}),M=!!i[t.platform]?.guidedSetup,[B,L]=o.useState(M&&!t.hasConfig?"guided":"manual"),U=M&&B==="guided",{channels:H,error:W,loading:O,reloadChannels:_}=to(r.listChannels,t.id,p&&t.canListChannels),[X,ce]=o.useState(""),[oe,ee]=o.useState(null),[g,T]=o.useState(!1),[f,K]=o.useState(null),z=qi(oe),[se,ae]=o.useState(!1),ge=t.fields.some(E=>E.type==="agent"),te=lo(o.useMemo(()=>s??pa,[s]),ge),Je=o.useCallback(E=>E?te.find(re=>re.id===E)?.name??E:"",[te]),Ae=Hi(j),Se=o.useRef(t);Se.current=t;const Be=o.useRef(!1),ot=o.useRef(!1);o.useEffect(()=>{if(Be.current)return;const E=Se.current;b(E.label),h(fn(hn(E))),m(E.enabled),$(E.channels),R(typeof E.notifyAgentId=="string"?E.notifyAgentId:"")},[Ae]),o.useEffect(()=>{C({kind:"idle"}),ee(null),K(null),et(!1)},[t.id]),o.useEffect(()=>{L(M&&!t.hasConfig?"guided":"manual")},[t.id,t.hasConfig,M]);const we=o.useCallback(()=>{Be.current=!0,C({kind:"idle"})},[]),fe=o.useCallback((E,re)=>{we(),h(le=>({...le,[E]:re}))},[we]),Ft=o.useCallback(E=>{we(),b(E)},[we]),Ye=o.useCallback(E=>{we(),m(E)},[we]),vt=o.useRef(()=>Promise.resolve()),De=o.useCallback(async()=>{if(!ot.current){ot.current=!0,C({kind:"saving"});try{let E=Se.current.id;E||(E=(await r.create(Se.current.platform,w.trim())).id),await r.save(E,{...Fi(j,S,P),notifyAgentId:I}),Se.current.canListChannels&&await r.saveChannels(E,v);let re=null;try{const{ok:le,text:Ke,code:At}=zi(await r.test(E,{}));!le&&!/not supported/i.test(Ke)&&(re=At==="network_unreachable"?d("settings:integrations.savedNotVerifiedNetwork"):d("settings:integrations.savedNotVerified",{reason:Ke}))}catch(le){re=d("settings:integrations.savedNotVerified",{reason:String(le)})}Be.current=!1,C(re?{kind:"error",text:re}:{kind:"saved"}),await a?.(),Se.current.id===""&&n?.(E)}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}finally{ot.current=!1}}},[r,j,S,P,I,v,w,d,a,n]);vt.current=De;const lt=pn(j.fields,S,t.secrets),Ut=u&&w.trim()==="",Kt=v.every(E=>E.agentId),Qe=!U&&!Ut&<.length===0&&Kt,Ee=o.useMemo(()=>JSON.stringify([w,P,I,v,S]),[w,P,I,v,S]);o.useEffect(()=>{if(!Be.current||!Qe)return;const E=setTimeout(()=>{vt.current()},ko);return()=>clearTimeout(E)},[Ee,Qe]),o.useEffect(()=>{if(!p||u)return;let E=!0;return r.getConnectionTest(t.id).then(re=>{E&&re&&ee(re)}).catch(()=>{}),()=>{E=!1}},[p,u,r,t.id]),o.useEffect(()=>{if(!p||!z)return;let E=!0;const re=setInterval(()=>{r.getConnectionTest(t.id).then(le=>{E&&le&&ee(le)}).catch(()=>{})},2500);return()=>{E=!1,clearInterval(re)}},[p,z,r,t.id]);const jt=o.useRef(null);o.useEffect(()=>{oe?.status==="verified"&&jt.current!==t.id&&(jt.current=t.id,a?.())},[oe?.status,t.id,a]);const Ht=o.useCallback(async()=>{T(!0),K(null);try{ee(await r.startConnectionTest(t.id))}catch(E){K(E instanceof Error?E.message:String(E))}finally{T(!1)}},[r,t.id]),ye=i[t.platform],_e=o.useMemo(()=>({platformId:t.platform,instanceId:t.id||void 0,status:j,values:S,setValue:fe,reload:()=>{a?.()},agents:te,onCreated:n,setupMethod:M?B:void 0,setSetupMethod:M?L:void 0}),[t.platform,t.id,j,S,fe,a,te,n,M,B]),Ne=o.useMemo(()=>new Set(ye?.ownedFields??[]),[ye]),Nt=_t(j.fields).length>0,wt=o.useMemo(()=>new Set(Nt?ao(j.fields).map(E=>E.key):[]),[j.fields,Nt]),Ze=o.useMemo(()=>j.fields.filter(E=>!Ne.has(E.key)&&!wt.has(E.key)),[j.fields,Ne,wt]),Fe=o.useMemo(()=>Ui(Ze),[Ze]),Xe=o.useMemo(()=>Ki(Ze),[Ze]),kt=o.useMemo(()=>Fe.filter(E=>E.type==="agent"),[Fe]),Ct=o.useMemo(()=>Fe.filter(E=>E.type!=="agent"),[Fe]),[zt,et]=o.useState(!1),tt=o.useMemo(()=>pn(t.fields,t.values,t.secrets),[t.fields,t.values,t.secrets]),Oe=t.hasConfig&&!tt.some(E=>Ct.some(re=>re.key===E)),St=o.useMemo(()=>Zi(H,X),[H,X]),je=o.useMemo(()=>Qi(v,H),[v,H]),st=v.filter(E=>!E.agentId).length,qt=o.useCallback((E,re)=>{we(),$(le=>re?bn(le,E.id,Hs(le,E.id)?.agentId??t.agentId??"",E.kind??null):yn(le,E.id))},[we,t.agentId]),Wt=o.useCallback((E,re)=>{we(),$(le=>bn(le,E,re,Hs(le,E)?.kind??null))},[we]),rt=o.useCallback(async()=>{ae(!1);try{await r.remove(t.id),await a?.()}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}},[r,t.id,a]),Ue=Wi(t,oe?.status==="verified"),ne=t.id||`new-${t.platform}`,pe=`instance-name-${ne}`,Gt=lt.map(E=>{const re=j.fields.find(le=>le.key===E);return re?ua(d,t.platform,re).label:E}).join(", ");return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden border border-border-default","data-testid":`instance-card-${ne}`,"data-instance":t.id,"data-platform":t.platform,"data-draft":u?"true":"false","data-expanded":p?"true":"false","data-connection":Ue,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsxs("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":p,"data-testid":`instance-toggle-${ne}`,className:"flex-1 min-w-0 flex items-center gap-3 text-left",children:[e.jsx(va,{id:t.platform}),e.jsxs("span",{className:"flex-1 min-w-0 flex items-center gap-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary truncate","data-testid":`instance-label-${ne}`,children:w.trim()===""?d("settings:instances.newBot",{defaultValue:"New bot"}):w}),!u&&e.jsx("span",{className:"hidden sm:inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium bg-surface-secondary border border-border-default text-fg-tertiary","data-testid":`instance-platform-${ne}`,children:t.platform}),!u&&t.agentId&&e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1.5 text-xs text-fg-tertiary truncate","data-testid":`instance-agent-${ne}`,title:d("settings:instances.boundAgent",{defaultValue:"Bound agent"}),children:[e.jsx("span",{className:"text-fg-quaternary",children:"→"}),Je(t.agentId)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(fo,{state:Ue}),!u&&e.jsx(bs,{checked:P,onChange:Ye,size:"md",testId:`instance-enabled-${ne}`,label:d("settings:instances.toggleLabel",{defaultValue:"Turn this bot on or off"})}),e.jsx("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":p,"data-testid":`instance-chevron-${ne}`,className:"p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:e.jsx("svg",{className:`w-4 h-4 transition-transform ${p?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})})]})]}),p&&e.jsxs("div",{className:"px-6 pb-6 pt-5 border-t border-border-default space-y-6",children:[!t.hasConfig&&!U&&e.jsx(wo,{status:j,configured:t.hasConfig,canListChannels:t.canListChannels,channelsGuidance:t.channelsGuidance??null}),!M&&ye?.placement==="before"&&ye.render(_e),e.jsxs("section",{"data-testid":`instance-credentials-${ne}`,className:gs,children:[e.jsx("h3",{className:`${Dt} mb-3`,children:t.hasConfig?d("settings:instances.setup.configuredTitle",{defaultValue:"Bot setup"}):M?d("settings:instances.setup.title",{defaultValue:"Connection"}):d("settings:instances.credentials",{defaultValue:"Credentials"})}),M&&!t.hasConfig&&e.jsx("div",{role:"tablist",className:"inline-flex rounded-lg border border-border-default bg-surface-secondary p-0.5 mb-4",children:["guided","manual"].map(E=>e.jsx("button",{type:"button",role:"tab","aria-selected":B===E,onClick:()=>L(E),"data-testid":`setup-method-${E}-${ne}`,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${B===E?"bg-surface-elevated text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:E==="guided"?d("settings:instances.setup.guided",{defaultValue:"Scan to create (recommended)"}):d("settings:instances.setup.manual",{defaultValue:"Enter credentials manually"})},E))}),U?e.jsx("div",{className:"space-y-4",children:ye.render(_e)}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:ba,children:[e.jsxs("label",{htmlFor:pe,className:vr,children:[d("settings:instances.addBot.name",{defaultValue:"Bot name"}),e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:ya,children:e.jsx("input",{id:pe,"data-testid":`new-bot-name-${t.platform}`,value:w,onChange:E=>Ft(E.target.value),placeholder:d("settings:instances.addBot.namePlaceholder",{defaultValue:"e.g. Sales"}),className:jr})})]}),kt.length>0&&e.jsx(yt,{status:j,draft:S,fields:kt,onChange:fe,agentOptions:te}),Ct.length>0&&(Oe&&!zt?e.jsx("div",{"data-testid":`instance-credentials-configured-${ne}`,className:"space-y-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx("span",{"aria-hidden":"true",children:"✓"}),d("settings:instances.credentialsSet",{defaultValue:"Credentials set"})]}),e.jsx("button",{type:"button",onClick:()=>et(!0),"data-testid":`instance-credentials-edit-${ne}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsEdit",{defaultValue:"Change"})})]})}):e.jsxs("div",{className:"space-y-3",children:[Oe&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx("span",{"aria-hidden":"true",children:"✓"}),d("settings:instances.credentialsSet",{defaultValue:"Credentials set"})]}),e.jsx("button",{type:"button",onClick:()=>et(!1),"data-testid":`instance-credentials-hide-${ne}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsHide",{defaultValue:"Hide"})})]}),e.jsx(yt,{status:j,draft:S,fields:Ct,onChange:fe,agentOptions:te})]}))]}),e.jsx("div",{className:"mt-3 min-h-[1.25rem]","data-testid":`instance-save-state-${ne}`,children:e.jsxs("span",{"data-state":V.kind,className:"inline-flex items-center gap-2 text-xs text-fg-tertiary",children:[V.kind==="saving"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),d("settings:instances.autosave.saving",{defaultValue:"Saving…"})]}),V.kind==="saved"&&e.jsxs("span",{className:"text-green-600",children:["✓ ",d("settings:instances.autosave.saved",{defaultValue:"Saved"})]}),!Qe&&!U&&e.jsx("span",{"data-testid":`instance-missing-${ne}`,children:lt.length>0?d("settings:integrations.missingRequired",{defaultValue:"Required: {{fields}}",fields:Gt}):d("settings:instances.addBot.labelRequired",{defaultValue:"Give the bot a name."})})]})}),V.kind==="error"&&e.jsx("div",{className:"mt-2",children:e.jsx($t,{type:"err",text:V.text})})]}),!u&&e.jsxs("section",{children:[e.jsx(bo,{test:oe,starting:g,lastVerifiedAt:t.lastVerifiedAt,onStart:()=>{Ht()}}),f&&e.jsx("div",{className:"mt-3",children:e.jsx($t,{type:"err",text:f})})]}),!u&&Nt&&e.jsx(yo,{status:j,values:S,setValue:fe,channels:H,canListChannels:t.canListChannels,channelsLoading:O,channelsError:W,onReloadChannels:_,channelsGuidance:t.channelsGuidance??null,testSlot:ye?.sendTest?.(_e)}),e.jsxs("section",{"data-testid":`instance-more-${ne}`,children:[e.jsxs("button",{type:"button",onClick:()=>y(E=>!E),"aria-expanded":k,"data-testid":`instance-more-toggle-${ne}`,className:"w-full flex items-center gap-2 text-left group px-1",children:[e.jsx("span",{className:Dt,children:d("settings:instances.moreSettings",{defaultValue:"Advanced"})}),e.jsx("span",{className:`${bt} truncate hidden sm:inline`,children:d("settings:instances.moreSettingsHint",{defaultValue:"Chat routing and platform options"})}),e.jsx("svg",{className:`ml-auto w-3.5 h-3.5 text-fg-tertiary transition-transform ${k?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})]}),k&&e.jsxs("div",{className:"mt-3 space-y-4",children:[Xe.length>0&&e.jsxs("div",{className:gs,children:[e.jsx("h4",{className:`${Dt} mb-1`,children:d("settings:instances.advancedTitle",{defaultValue:"Platform options"})}),!u&&e.jsx("p",{className:`${bt} mb-3`,children:d("settings:instances.advancedHint",{defaultValue:"These default to the right value for almost every setup — leave them alone unless you know you need them."})}),e.jsx(yt,{status:j,draft:S,fields:Xe,onChange:fe,agentOptions:te})]}),!u&&e.jsxs("div",{className:gs,children:[e.jsx("h4",{className:`${Dt} mb-1`,children:d("settings:instances.routing.chats",{defaultValue:"Chat routing"})}),e.jsx("p",{className:`${bt} mb-3`,children:d("settings:instances.routing.chatsHint",{defaultValue:"The agent bound above answers every chat by default. Route a specific chat to a different agent here."})}),!t.canListChannels&&e.jsx("p",{className:"text-[11px] text-fg-tertiary","data-testid":`instance-chats-unsupported-${ne}`,children:t.channelsGuidance?d(t.channelsGuidance,{defaultValue:d("settings:instances.routing.unsupported",{defaultValue:"This platform does not let us list its chats."})}):d("settings:instances.routing.unsupported",{defaultValue:"This platform does not let us list its chats."})}),t.canListChannels&&e.jsx("div",{className:"mb-2",children:e.jsx(ha,{loading:O,error:W,onReload:_,empty:H.length===0,buttonTestId:`instance-chats-refresh-${ne}`,errorTestId:`instance-chats-error-${ne}`})}),t.canListChannels&&H.length>0&&e.jsx("input",{type:"text",value:X,onChange:E=>ce(E.target.value),placeholder:d("settings:instances.routing.searchChats",{defaultValue:"Search chats…"}),"data-testid":`instance-chat-search-${ne}`,className:"w-full mb-2 px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500"}),e.jsxs("div",{className:"space-y-2","data-testid":`instance-chats-${ne}`,children:[St.map(E=>{const re=Hs(v,E.id);return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-fg-primary min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:!!re,"data-testid":`instance-chat-toggle-${ne}-${E.id}`,onChange:le=>qt(E,le.target.checked),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate",title:E.id,children:E.name})]}),re&&e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${ne}-${E.id}`,children:e.jsx(hs,{value:re.agentId,options:te,onChange:(le,Ke)=>Wt(E.id,typeof Ke=="string"?Ke:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.id)}),je.map(E=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-fg-primary min-w-0 flex-1",children:[e.jsx("input",{type:"checkbox",checked:!0,"data-testid":`instance-chat-toggle-${ne}-${E.nativeId}`,onChange:()=>$(re=>yn(re,E.nativeId)),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate font-mono text-xs",title:E.nativeId,children:E.nativeId})]}),e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${ne}-${E.nativeId}`,children:e.jsx(hs,{value:E.agentId,options:te,onChange:(re,le)=>Wt(E.nativeId,typeof le=="string"?le:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.nativeId))]}),e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-2",children:d("settings:instances.routing.autoSaved",{defaultValue:"Changes are saved automatically."})}),st>0&&e.jsx("div",{className:"mt-3",children:e.jsx($t,{type:"err",text:d("settings:instances.routing.agentRequired",{defaultValue:"Pick an agent for every selected chat ({{count}} still unassigned).",count:st})})})]})]})]}),!M&&ye&&ye.placement!=="before"&&ye.render(_e),!u&&e.jsx("div",{className:"pt-1",children:e.jsx("button",{type:"button",onClick:()=>ae(!0),"data-testid":`instance-disconnect-${ne}`,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-600 border border-red-500/30 rounded-lg hover:bg-red-500/10 transition-colors",children:d("settings:integrations.disconnect",{defaultValue:"Disconnect"})})})]}),se&&e.jsx(fs,{title:d("settings:integrations.disconnectConfirmTitle",{defaultValue:"Disconnect this bot?"}),message:d("settings:integrations.disconnectConfirmMessage",{defaultValue:"Its stored credentials are removed and it stops sending and receiving messages. This cannot be undone."}),confirmLabel:d("settings:integrations.disconnect",{defaultValue:"Disconnect"}),variant:"danger",onConfirm:()=>{rt()},onCancel:()=>ae(!1)})]})}var ft={},zs,Cn;function Co(){return Cn||(Cn=1,zs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),zs}var qs={},Ge={},Sn;function at(){if(Sn)return Ge;Sn=1;let t;const r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return Ge.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},Ge.getSymbolTotalCodewords=function(a){return r[a]},Ge.getBCHDigit=function(i){let a=0;for(;i!==0;)a++,i>>>=1;return a},Ge.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},Ge.isKanjiModeEnabled=function(){return typeof t<"u"},Ge.toSJIS=function(a){return t(a)},Ge}var Ws={},An;function Cr(){return An||(An=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+i)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,n){if(t.isValid(a))return a;try{return r(a)}catch{return n}}})(Ws)),Ws}var Gs,Pn;function So(){if(Pn)return Gs;Pn=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(r){const i=Math.floor(r/8);return(this.buffer[i]>>>7-r%8&1)===1},put:function(r,i){for(let a=0;a<i;a++)this.putBit((r>>>i-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const i=Math.floor(this.length/8);this.buffer.length<=i&&this.buffer.push(0),r&&(this.buffer[i]|=128>>>this.length%8),this.length++}},Gs=t,Gs}var Js,Mn;function Ao(){if(Mn)return Js;Mn=1;function t(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return t.prototype.set=function(r,i,a,n){const s=r*this.size+i;this.data[s]=a,n&&(this.reservedBit[s]=!0)},t.prototype.get=function(r,i){return this.data[r*this.size+i]},t.prototype.xor=function(r,i,a){this.data[r*this.size+i]^=a},t.prototype.isReserved=function(r,i){return this.reservedBit[r*this.size+i]},Js=t,Js}var Ys={},Tn;function Po(){return Tn||(Tn=1,(function(t){const r=at().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const n=Math.floor(a/7)+2,s=r(a),c=s===145?26:Math.ceil((s-13)/(2*n-2))*2,d=[s-7];for(let u=1;u<n-1;u++)d[u]=d[u-1]-c;return d.push(6),d.reverse()},t.getPositions=function(a){const n=[],s=t.getRowColCoords(a),c=s.length;for(let d=0;d<c;d++)for(let u=0;u<c;u++)d===0&&u===0||d===0&&u===c-1||d===c-1&&u===0||n.push([s[d],s[u]]);return n}})(Ys)),Ys}var Qs={},En;function Mo(){if(En)return Qs;En=1;const t=at().getSymbolSize,r=7;return Qs.getPositions=function(a){const n=t(a);return[[0,0],[n-r,0],[0,n-r]]},Qs}var Zs={},Ln;function To(){return Ln||(Ln=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={N1:3,N2:3,N3:40,N4:10};t.isValid=function(n){return n!=null&&n!==""&&!isNaN(n)&&n>=0&&n<=7},t.from=function(n){return t.isValid(n)?parseInt(n,10):void 0},t.getPenaltyN1=function(n){const s=n.size;let c=0,d=0,u=0,p=null,x=null;for(let k=0;k<s;k++){d=u=0,p=x=null;for(let y=0;y<s;y++){let j=n.get(k,y);j===p?d++:(d>=5&&(c+=r.N1+(d-5)),p=j,d=1),j=n.get(y,k),j===x?u++:(u>=5&&(c+=r.N1+(u-5)),x=j,u=1)}d>=5&&(c+=r.N1+(d-5)),u>=5&&(c+=r.N1+(u-5))}return c},t.getPenaltyN2=function(n){const s=n.size;let c=0;for(let d=0;d<s-1;d++)for(let u=0;u<s-1;u++){const p=n.get(d,u)+n.get(d,u+1)+n.get(d+1,u)+n.get(d+1,u+1);(p===4||p===0)&&c++}return c*r.N2},t.getPenaltyN3=function(n){const s=n.size;let c=0,d=0,u=0;for(let p=0;p<s;p++){d=u=0;for(let x=0;x<s;x++)d=d<<1&2047|n.get(p,x),x>=10&&(d===1488||d===93)&&c++,u=u<<1&2047|n.get(x,p),x>=10&&(u===1488||u===93)&&c++}return c*r.N3},t.getPenaltyN4=function(n){let s=0;const c=n.data.length;for(let u=0;u<c;u++)s+=n.data[u];return Math.abs(Math.ceil(s*100/c/5)-10)*r.N4};function i(a,n,s){switch(a){case t.Patterns.PATTERN000:return(n+s)%2===0;case t.Patterns.PATTERN001:return n%2===0;case t.Patterns.PATTERN010:return s%3===0;case t.Patterns.PATTERN011:return(n+s)%3===0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(s/3))%2===0;case t.Patterns.PATTERN101:return n*s%2+n*s%3===0;case t.Patterns.PATTERN110:return(n*s%2+n*s%3)%2===0;case t.Patterns.PATTERN111:return(n*s%3+(n+s)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(n,s){const c=s.size;for(let d=0;d<c;d++)for(let u=0;u<c;u++)s.isReserved(u,d)||s.xor(u,d,i(n,u,d))},t.getBestMask=function(n,s){const c=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let p=0;p<c;p++){s(p),t.applyMask(p,n);const x=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(p,n),x<u&&(u=x,d=p)}return d}})(Zs)),Zs}var cs={},Rn;function Na(){if(Rn)return cs;Rn=1;const t=Cr(),r=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return cs.getBlocksCount=function(n,s){switch(s){case t.L:return r[(n-1)*4+0];case t.M:return r[(n-1)*4+1];case t.Q:return r[(n-1)*4+2];case t.H:return r[(n-1)*4+3];default:return}},cs.getTotalCodewordsCount=function(n,s){switch(s){case t.L:return i[(n-1)*4+0];case t.M:return i[(n-1)*4+1];case t.Q:return i[(n-1)*4+2];case t.H:return i[(n-1)*4+3];default:return}},cs}var Xs={},Rt={},In;function Eo(){if(In)return Rt;In=1;const t=new Uint8Array(512),r=new Uint8Array(256);return(function(){let a=1;for(let n=0;n<255;n++)t[n]=a,r[a]=n,a<<=1,a&256&&(a^=285);for(let n=255;n<512;n++)t[n]=t[n-255]})(),Rt.log=function(a){if(a<1)throw new Error("log("+a+")");return r[a]},Rt.exp=function(a){return t[a]},Rt.mul=function(a,n){return a===0||n===0?0:t[r[a]+r[n]]},Rt}var Bn;function Lo(){return Bn||(Bn=1,(function(t){const r=Eo();t.mul=function(a,n){const s=new Uint8Array(a.length+n.length-1);for(let c=0;c<a.length;c++)for(let d=0;d<n.length;d++)s[c+d]^=r.mul(a[c],n[d]);return s},t.mod=function(a,n){let s=new Uint8Array(a);for(;s.length-n.length>=0;){const c=s[0];for(let u=0;u<n.length;u++)s[u]^=r.mul(n[u],c);let d=0;for(;d<s.length&&s[d]===0;)d++;s=s.slice(d)}return s},t.generateECPolynomial=function(a){let n=new Uint8Array([1]);for(let s=0;s<a;s++)n=t.mul(n,new Uint8Array([1,r.exp(s)]));return n}})(Xs)),Xs}var er,Dn;function Ro(){if(Dn)return er;Dn=1;const t=Lo();function r(i){this.genPoly=void 0,this.degree=i,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},r.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const n=new Uint8Array(a.length+this.degree);n.set(a);const s=t.mod(n,this.genPoly),c=this.degree-s.length;if(c>0){const d=new Uint8Array(this.degree);return d.set(s,c),d}return s},er=r,er}var tr={},sr={},rr={},On;function wa(){return On||(On=1,rr.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),rr}var Re={},$n;function ka(){if($n)return Re;$n=1;const t="[0-9]+",r="[A-Z $%*+\\-./:]+";let i="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";i=i.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+i+`)(?:.|[\r
|
|
2
2
|
]))+`;Re.KANJI=new RegExp(i,"g"),Re.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Re.BYTE=new RegExp(a,"g"),Re.NUMERIC=new RegExp(t,"g"),Re.ALPHANUMERIC=new RegExp(r,"g");const n=new RegExp("^"+i+"$"),s=new RegExp("^"+t+"$"),c=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Re.testKanji=function(u){return n.test(u)},Re.testNumeric=function(u){return s.test(u)},Re.testAlphanumeric=function(u){return c.test(u)},Re}var Vn;function it(){return Vn||(Vn=1,(function(t){const r=wa(),i=ka();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(s,c){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!r.isValid(c))throw new Error("Invalid version: "+c);return c>=1&&c<10?s.ccBits[0]:c<27?s.ccBits[1]:s.ccBits[2]},t.getBestModeForData=function(s){return i.testNumeric(s)?t.NUMERIC:i.testAlphanumeric(s)?t.ALPHANUMERIC:i.testKanji(s)?t.KANJI:t.BYTE},t.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},t.isValid=function(s){return s&&s.bit&&s.ccBits};function a(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+n)}}t.from=function(s,c){if(t.isValid(s))return s;try{return a(s)}catch{return c}}})(sr)),sr}var _n;function Io(){return _n||(_n=1,(function(t){const r=at(),i=Na(),a=Cr(),n=it(),s=wa(),c=7973,d=r.getBCHDigit(c);function u(y,j,w){for(let b=1;b<=40;b++)if(j<=t.getCapacity(b,w,y))return b}function p(y,j){return n.getCharCountIndicator(y,j)+4}function x(y,j){let w=0;return y.forEach(function(b){const S=p(b.mode,j);w+=S+b.getBitsLength()}),w}function k(y,j){for(let w=1;w<=40;w++)if(x(y,w)<=t.getCapacity(w,j,n.MIXED))return w}t.from=function(j,w){return s.isValid(j)?parseInt(j,10):w},t.getCapacity=function(j,w,b){if(!s.isValid(j))throw new Error("Invalid QR Code version");typeof b>"u"&&(b=n.BYTE);const S=r.getSymbolTotalCodewords(j),h=i.getTotalCodewordsCount(j,w),P=(S-h)*8;if(b===n.MIXED)return P;const m=P-p(b,j);switch(b){case n.NUMERIC:return Math.floor(m/10*3);case n.ALPHANUMERIC:return Math.floor(m/11*2);case n.KANJI:return Math.floor(m/13);case n.BYTE:default:return Math.floor(m/8)}},t.getBestVersionForData=function(j,w){let b;const S=a.from(w,a.M);if(Array.isArray(j)){if(j.length>1)return k(j,S);if(j.length===0)return 1;b=j[0]}else b=j;return u(b.mode,b.getLength(),S)},t.getEncodedBits=function(j){if(!s.isValid(j)||j<7)throw new Error("Invalid QR Code version");let w=j<<12;for(;r.getBCHDigit(w)-d>=0;)w^=c<<r.getBCHDigit(w)-d;return j<<12|w}})(tr)),tr}var nr={},Fn;function Bo(){if(Fn)return nr;Fn=1;const t=at(),r=1335,i=21522,a=t.getBCHDigit(r);return nr.getEncodedBits=function(s,c){const d=s.bit<<3|c;let u=d<<10;for(;t.getBCHDigit(u)-a>=0;)u^=r<<t.getBCHDigit(u)-a;return(d<<10|u)^i},nr}var ar={},ir,Un;function Do(){if(Un)return ir;Un=1;const t=it();function r(i){this.mode=t.NUMERIC,this.data=i.toString()}return r.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(a){let n,s,c;for(n=0;n+3<=this.data.length;n+=3)s=this.data.substr(n,3),c=parseInt(s,10),a.put(c,10);const d=this.data.length-n;d>0&&(s=this.data.substr(n),c=parseInt(s,10),a.put(c,d*3+1))},ir=r,ir}var or,Kn;function Oo(){if(Kn)return or;Kn=1;const t=it(),r=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function i(a){this.mode=t.ALPHANUMERIC,this.data=a}return i.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let c=r.indexOf(this.data[s])*45;c+=r.indexOf(this.data[s+1]),n.put(c,11)}this.data.length%2&&n.put(r.indexOf(this.data[s]),6)},or=i,or}var lr,Hn;function $o(){if(Hn)return lr;Hn=1;const t=it();function r(i){this.mode=t.BYTE,typeof i=="string"?this.data=new TextEncoder().encode(i):this.data=new Uint8Array(i)}return r.getBitsLength=function(a){return a*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(i){for(let a=0,n=this.data.length;a<n;a++)i.put(this.data[a],8)},lr=r,lr}var dr,zn;function Vo(){if(zn)return dr;zn=1;const t=it(),r=at();function i(a){this.mode=t.KANJI,this.data=a}return i.getBitsLength=function(n){return n*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(a){let n;for(n=0;n<this.data.length;n++){let s=r.toSJIS(this.data[n]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
|
|
3
3
|
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),a.put(s,13)}},dr=i,dr}var cr={exports:{}},qn;function _o(){return qn||(qn=1,(function(t){var r={single_source_shortest_paths:function(i,a,n){var s={},c={};c[a]=0;var d=r.PriorityQueue.make();d.push(a,0);for(var u,p,x,k,y,j,w,b,S;!d.empty();){u=d.pop(),p=u.value,k=u.cost,y=i[p]||{};for(x in y)y.hasOwnProperty(x)&&(j=y[x],w=k+j,b=c[x],S=typeof c[x]>"u",(S||b>w)&&(c[x]=w,d.push(x,w),s[x]=p))}if(typeof n<"u"&&typeof c[n]>"u"){var h=["Could not find a path from ",a," to ",n,"."].join("");throw new Error(h)}return s},extract_shortest_path_from_predecessor_list:function(i,a){for(var n=[],s=a;s;)n.push(s),i[s],s=i[s];return n.reverse(),n},find_path:function(i,a,n){var s=r.single_source_shortest_paths(i,a,n);return r.extract_shortest_path_from_predecessor_list(s,n)},PriorityQueue:{make:function(i){var a=r.PriorityQueue,n={},s;i=i||{};for(s in a)a.hasOwnProperty(s)&&(n[s]=a[s]);return n.queue=[],n.sorter=i.sorter||a.default_sorter,n},default_sorter:function(i,a){return i.cost-a.cost},push:function(i,a){var n={value:i,cost:a};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=r})(cr)),cr.exports}var Wn;function Fo(){return Wn||(Wn=1,(function(t){const r=it(),i=Do(),a=Oo(),n=$o(),s=Vo(),c=ka(),d=at(),u=_o();function p(h){return unescape(encodeURIComponent(h)).length}function x(h,P,m){const v=[];let $;for(;($=h.exec(m))!==null;)v.push({data:$[0],index:$.index,mode:P,length:$[0].length});return v}function k(h){const P=x(c.NUMERIC,r.NUMERIC,h),m=x(c.ALPHANUMERIC,r.ALPHANUMERIC,h);let v,$;return d.isKanjiModeEnabled()?(v=x(c.BYTE,r.BYTE,h),$=x(c.KANJI,r.KANJI,h)):(v=x(c.BYTE_KANJI,r.BYTE,h),$=[]),P.concat(m,v,$).sort(function(R,V){return R.index-V.index}).map(function(R){return{data:R.data,mode:R.mode,length:R.length}})}function y(h,P){switch(P){case r.NUMERIC:return i.getBitsLength(h);case r.ALPHANUMERIC:return a.getBitsLength(h);case r.KANJI:return s.getBitsLength(h);case r.BYTE:return n.getBitsLength(h)}}function j(h){return h.reduce(function(P,m){const v=P.length-1>=0?P[P.length-1]:null;return v&&v.mode===m.mode?(P[P.length-1].data+=m.data,P):(P.push(m),P)},[])}function w(h){const P=[];for(let m=0;m<h.length;m++){const v=h[m];switch(v.mode){case r.NUMERIC:P.push([v,{data:v.data,mode:r.ALPHANUMERIC,length:v.length},{data:v.data,mode:r.BYTE,length:v.length}]);break;case r.ALPHANUMERIC:P.push([v,{data:v.data,mode:r.BYTE,length:v.length}]);break;case r.KANJI:P.push([v,{data:v.data,mode:r.BYTE,length:p(v.data)}]);break;case r.BYTE:P.push([{data:v.data,mode:r.BYTE,length:p(v.data)}])}}return P}function b(h,P){const m={},v={start:{}};let $=["start"];for(let I=0;I<h.length;I++){const R=h[I],V=[];for(let C=0;C<R.length;C++){const M=R[C],B=""+I+C;V.push(B),m[B]={node:M,lastCount:0},v[B]={};for(let L=0;L<$.length;L++){const U=$[L];m[U]&&m[U].node.mode===M.mode?(v[U][B]=y(m[U].lastCount+M.length,M.mode)-y(m[U].lastCount,M.mode),m[U].lastCount+=M.length):(m[U]&&(m[U].lastCount=M.length),v[U][B]=y(M.length,M.mode)+4+r.getCharCountIndicator(M.mode,P))}}$=V}for(let I=0;I<$.length;I++)v[$[I]].end=0;return{map:v,table:m}}function S(h,P){let m;const v=r.getBestModeForData(h);if(m=r.from(P,v),m!==r.BYTE&&m.bit<v.bit)throw new Error('"'+h+'" cannot be encoded with mode '+r.toString(m)+`.
|
|
4
4
|
Suggested mode is: `+r.toString(v));switch(m===r.KANJI&&!d.isKanjiModeEnabled()&&(m=r.BYTE),m){case r.NUMERIC:return new i(h);case r.ALPHANUMERIC:return new a(h);case r.KANJI:return new s(h);case r.BYTE:return new n(h)}}t.fromArray=function(P){return P.reduce(function(m,v){return typeof v=="string"?m.push(S(v,null)):v.data&&m.push(S(v.data,v.mode)),m},[])},t.fromString=function(P,m){const v=k(P,d.isKanjiModeEnabled()),$=w(v),I=b($,m),R=u.find_path(I.map,"start","end"),V=[];for(let C=1;C<R.length-1;C++)V.push(I.table[R[C]].node);return t.fromArray(j(V))},t.rawSplit=function(P){return t.fromArray(k(P,d.isKanjiModeEnabled()))}})(ar)),ar}var Gn;function Uo(){if(Gn)return qs;Gn=1;const t=at(),r=Cr(),i=So(),a=Ao(),n=Po(),s=Mo(),c=To(),d=Na(),u=Ro(),p=Io(),x=Bo(),k=it(),y=Fo();function j(I,R){const V=I.size,C=s.getPositions(R);for(let M=0;M<C.length;M++){const B=C[M][0],L=C[M][1];for(let U=-1;U<=7;U++)if(!(B+U<=-1||V<=B+U))for(let H=-1;H<=7;H++)L+H<=-1||V<=L+H||(U>=0&&U<=6&&(H===0||H===6)||H>=0&&H<=6&&(U===0||U===6)||U>=2&&U<=4&&H>=2&&H<=4?I.set(B+U,L+H,!0,!0):I.set(B+U,L+H,!1,!0))}}function w(I){const R=I.size;for(let V=8;V<R-8;V++){const C=V%2===0;I.set(V,6,C,!0),I.set(6,V,C,!0)}}function b(I,R){const V=n.getPositions(R);for(let C=0;C<V.length;C++){const M=V[C][0],B=V[C][1];for(let L=-2;L<=2;L++)for(let U=-2;U<=2;U++)L===-2||L===2||U===-2||U===2||L===0&&U===0?I.set(M+L,B+U,!0,!0):I.set(M+L,B+U,!1,!0)}}function S(I,R){const V=I.size,C=p.getEncodedBits(R);let M,B,L;for(let U=0;U<18;U++)M=Math.floor(U/3),B=U%3+V-8-3,L=(C>>U&1)===1,I.set(M,B,L,!0),I.set(B,M,L,!0)}function h(I,R,V){const C=I.size,M=x.getEncodedBits(R,V);let B,L;for(B=0;B<15;B++)L=(M>>B&1)===1,B<6?I.set(B,8,L,!0):B<8?I.set(B+1,8,L,!0):I.set(C-15+B,8,L,!0),B<8?I.set(8,C-B-1,L,!0):B<9?I.set(8,15-B-1+1,L,!0):I.set(8,15-B-1,L,!0);I.set(C-8,8,1,!0)}function P(I,R){const V=I.size;let C=-1,M=V-1,B=7,L=0;for(let U=V-1;U>0;U-=2)for(U===6&&U--;;){for(let H=0;H<2;H++)if(!I.isReserved(M,U-H)){let W=!1;L<R.length&&(W=(R[L]>>>B&1)===1),I.set(M,U-H,W),B--,B===-1&&(L++,B=7)}if(M+=C,M<0||V<=M){M-=C,C=-C;break}}}function m(I,R,V){const C=new i;V.forEach(function(H){C.put(H.mode.bit,4),C.put(H.getLength(),k.getCharCountIndicator(H.mode,I)),H.write(C)});const M=t.getSymbolTotalCodewords(I),B=d.getTotalCodewordsCount(I,R),L=(M-B)*8;for(C.getLengthInBits()+4<=L&&C.put(0,4);C.getLengthInBits()%8!==0;)C.putBit(0);const U=(L-C.getLengthInBits())/8;for(let H=0;H<U;H++)C.put(H%2?17:236,8);return v(C,I,R)}function v(I,R,V){const C=t.getSymbolTotalCodewords(R),M=d.getTotalCodewordsCount(R,V),B=C-M,L=d.getBlocksCount(R,V),U=C%L,H=L-U,W=Math.floor(C/L),O=Math.floor(B/L),_=O+1,X=W-O,ce=new u(X);let oe=0;const ee=new Array(L),g=new Array(L);let T=0;const f=new Uint8Array(I.buffer);for(let ge=0;ge<L;ge++){const te=ge<H?O:_;ee[ge]=f.slice(oe,oe+te),g[ge]=ce.encode(ee[ge]),oe+=te,T=Math.max(T,te)}const K=new Uint8Array(C);let z=0,se,ae;for(se=0;se<T;se++)for(ae=0;ae<L;ae++)se<ee[ae].length&&(K[z++]=ee[ae][se]);for(se=0;se<X;se++)for(ae=0;ae<L;ae++)K[z++]=g[ae][se];return K}function $(I,R,V,C){let M;if(Array.isArray(I))M=y.fromArray(I);else if(typeof I=="string"){let W=R;if(!W){const O=y.rawSplit(I);W=p.getBestVersionForData(O,V)}M=y.fromString(I,W||40)}else throw new Error("Invalid data");const B=p.getBestVersionForData(M,V);if(!B)throw new Error("The amount of data is too big to be stored in a QR Code");if(!R)R=B;else if(R<B)throw new Error(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as E,r as d,a as M,b as A,c as D,d as C,j as e,P as L,i as R,S as z,T as H,e as K,f as $,I as O,h as q,g as B}from"./index-
|
|
1
|
+
import{u as E,r as d,a as M,b as A,c as D,d as C,j as e,P as L,i as R,S as z,T as H,e as K,f as $,I as O,h as q,g as B}from"./index-Ci5bUF3m.js";const v=[{id:"discover"},{id:"agents"},{id:"teams"},{id:"skills"},{id:"installed"}],P={agent:"agents",team:"teams",skill:"skills",connector:"skills"},F={discover:"M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z",agents:"M12 2a5 5 0 015 5v1a5 5 0 01-10 0V7a5 5 0 015-5zM4 21a8 8 0 0116 0z",teams:"M16 11a4 4 0 10-4-4 4 4 0 004 4zM8 13a3 3 0 10-3-3 3 3 0 003 3zm0 2c-2.7 0-5 1.3-5 3v2h7v-2c0-.7.2-1.3.6-1.9A7.6 7.6 0 008 15zm8 0c-3 0-6 1.5-6 3.5V21h12v-2.5c0-2-3-3.5-6-3.5z",skills:"M13 2L3 14h7l-1 8 10-12h-7z",installed:"M12 3v12m0 0l-4-4m4 4l4-4M5 21h14"};function I(n){return n==="discover"||n==="agents"||n==="teams"||n==="skills"||n==="installed"}function T(){const n=localStorage.getItem("markus_nav_installItem"),o=localStorage.getItem("markus_nav_storeTab");if(n)return{tab:I(o)?o:"agents",installId:n};const f=new URLSearchParams(window.location.search),s=f.get("install");if(s){const a=f.get("type");return{tab:a&&P[a]||"agents",installId:s}}return{tab:I(o)?o:"discover",installId:null}}function N(){localStorage.removeItem("markus_nav_installItem"),localStorage.removeItem("markus_nav_storeTab");const n=new URLSearchParams(window.location.search);if(n.has("install")||n.has("type")){n.delete("install"),n.delete("type");const o=n.toString();window.history.replaceState(null,"",window.location.pathname+(o?`?${o}`:"")+window.location.hash)}}function V({itemId:n,onDismiss:o,onInstalled:f}){const{t:s}=E(["store","common"]),[a,p]=d.useState(null),[g,l]=d.useState("loading"),[b,k]=d.useState(!1),[u,m]=d.useState("");d.useEffect(()=>{let x=!1;return l("loading"),p(null),m(""),q.getItem(n).then(({item:c})=>{x||(c?(p(c),l("ready")):l("missing"))}).catch(()=>{x||l("missing")}),()=>{x=!0}},[n]);const w=async()=>{if(!(!a||b)){k(!0),m("");try{await B(a),m(s("deepLink.installed")),f()}catch(x){const c=x instanceof Error?x.message:"";m(c.includes("402")||c.includes("Purchase")?s("deepLink.purchaseRequired"):s("deepLink.failed"))}finally{k(!1)}}};return e.jsxs("div",{className:"shrink-0 mx-3 mt-3 mb-1 rounded-xl border border-brand-500/30 bg-brand-600/10 px-4 py-3 flex flex-col sm:flex-row sm:items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-brand-400/90 mb-0.5",children:s("deepLink.fromHub")}),g==="loading"&&e.jsx("p",{className:"text-sm text-fg-secondary",children:s("deepLink.loading")}),g==="missing"&&e.jsx("p",{className:"text-sm text-rose-300",children:s("deepLink.missing")}),g==="ready"&&a&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-semibold text-fg-primary truncate",children:a.name}),a.description&&e.jsx("p",{className:"text-xs text-fg-tertiary line-clamp-2 mt-0.5",children:a.description}),u&&e.jsx("p",{className:"text-xs mt-1 text-brand-300",children:u})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[g==="ready"&&a&&e.jsx("button",{type:"button",disabled:b,onClick:()=>{w()},className:"px-3.5 py-2 rounded-lg text-xs font-semibold bg-brand-600 hover:bg-brand-500 text-white disabled:opacity-60",children:s(b?"deepLink.installing":"deepLink.install")}),e.jsx("button",{type:"button",onClick:o,className:"px-2.5 py-2 rounded-lg text-xs text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/60",children:s("deepLink.dismiss")})]})]})}function G({authUser:n}){const{t:o}=E(["store","common"]),[f]=d.useState(T),[s,a]=d.useState(f.tab),p=M(),g=A(L.STORE),l=D(),b=l?.keyboardPane??"content",k=C(v,s,a),[u,m]=d.useState(f.installId),w=d.useRef(s);w.current=s,d.useEffect(()=>{if(p||!g)return;const t=r=>{if(l?.keyboardPane==="l0"||r.metaKey||r.ctrlKey||r.altKey||R(r.target))return;const i=r.key.length===1?r.key.toLowerCase():r.key;if(i==="h"||i==="ArrowLeft"){r.preventDefault(),l?.setL0FocusPageId(L.STORE),l?.setLeftCollapsed(!1),l?.setKeyboardPane("l0");return}if(i==="l"||i==="ArrowRight"){r.preventDefault(),l?.keyboardPane!=="l1"&&l?.setKeyboardPane("l1");return}const h=i==="j"||i==="ArrowDown"?1:i==="k"||i==="ArrowUp"?-1:0;if(!h)return;r.preventDefault(),l?.setKeyboardPane("l1");const y=v.findIndex(_=>_.id===w.current),S=v[Math.max(0,Math.min(v.length-1,y+h))];a(S.id),requestAnimationFrame(()=>{document.querySelector(`[data-store-tab-id="${S.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",t,!0),()=>document.removeEventListener("keydown",t,!0)},[p,g,l]),d.useEffect(()=>{const t=T();t.installId&&(m(t.installId),I(t.tab)&&a(t.tab),N())},[]),d.useEffect(()=>{const t=r=>{const i=r.detail;if(i.page==="store"||i.page==="explore"){const h=i.params?.storeTab??localStorage.getItem("markus_nav_storeTab"),y=i.params?.installItem??localStorage.getItem("markus_nav_installItem");h&&I(h)&&a(h),y&&m(y),(h||y)&&N()}};return window.addEventListener("markus:navigate",t),()=>window.removeEventListener("markus:navigate",t)},[]);const x=(t,r)=>{const i=P[t]??"agents";r&&m(r),a(i)},c=()=>m(null),j=()=>e.jsxs(e.Fragment,{children:[u&&e.jsx(V,{itemId:u,onDismiss:c,onInstalled:c}),s==="discover"&&e.jsx(z,{onOpenType:x}),s==="agents"&&e.jsx(H,{authUser:n,highlightItemId:u,onHighlightDone:c}),s==="teams"&&e.jsx(K,{highlightItemId:u,onHighlightDone:c}),s==="skills"&&e.jsx($,{highlightItemId:u,onHighlightDone:c}),s==="installed"&&e.jsx(O,{})]});return p?e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:k.onTouchStart,onTouchEnd:k.onTouchEnd,children:[e.jsx("div",{className:"flex shrink-0 overflow-x-auto scrollbar-hide",children:v.map(t=>e.jsx("button",{onClick:()=>a(t.id),className:`flex-1 min-w-fit px-4 py-3 text-sm font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===t.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary hover:text-fg-secondary"}`,children:o(`tabs.${t.id}`)},t.id))}),e.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:j()})]}):e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-row",children:[e.jsxs("nav",{"data-keyboard-pane":"l1",className:`w-36 shrink-0 bg-surface-secondary rounded-xl m-1 mr-0 flex flex-col py-4 px-2 gap-1 ${b==="l1"?"ring-1 ring-inset ring-brand-500/30":""}`,children:[e.jsx("div",{className:"px-3 pb-3 mb-1",children:e.jsx("h2",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:o("title")})}),v.map(t=>e.jsxs("button",{"data-store-tab-id":t.id,onClick:()=>a(t.id),className:`flex items-center gap-2.5 px-3 py-2.5 rounded-lg text-sm font-medium transition-all ${s===t.id?b==="l1"?"bg-brand-500/25 text-brand-400 ring-1 ring-inset ring-brand-500/40":"bg-brand-600/15 text-brand-400 shadow-sm shadow-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[e.jsx("svg",{className:"w-4 h-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:e.jsx("path",{d:F[t.id]})}),o(`tabs.${t.id}`)]},t.id))]}),e.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:j()})]})}export{G as StorePage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as a}from"./index-
|
|
1
|
+
import{j as a}from"./index-Ci5bUF3m.js";const h="chat",d=new Set(["imageGeneration","tts","stt","videoGeneration","audioOutput","audioInput"]);function p(t){const e=t.capabilities??[];return e.includes(h)?!0:!(e.some(s=>d.has(s))||t.mode&&t.mode!=="chat")}const x={sm:{track:"w-9 h-5",knob:"w-4 h-4",on:"translate-x-4",off:"translate-x-0.5"},md:{track:"w-10 h-5",knob:"w-4 h-4",on:"translate-x-5",off:"translate-x-0.5"},lg:{track:"w-12 h-6",knob:"w-5 h-5",on:"translate-x-6",off:"translate-x-0.5"}};function w({checked:t,onChange:e,label:s,disabled:r=!1,size:l="md",testId:u,className:f="",children:i}){const n=t===!0,o=x[l],c=a.jsx("button",{type:"button",role:"switch","aria-checked":n,"aria-label":s,disabled:r,"data-testid":u,onClick:()=>e(!n),className:`relative ${o.track} shrink-0 rounded-full transition-colors duration-200 ${n?"bg-switch-on":"bg-switch-off"} ${r?"opacity-50 cursor-not-allowed":"cursor-pointer"} ${f}`,children:a.jsx("span",{className:`absolute top-0.5 left-0.5 block ${o.knob} rounded-full bg-switch-knob shadow transition-transform duration-200 ${n?o.on:o.off}`})});return i?a.jsxs("label",{className:"flex items-center justify-between gap-2 cursor-pointer select-none",children:[a.jsx("span",{className:"text-xs text-fg-secondary",children:i}),c]}):c}export{w as S,p as i};
|