@markus-global/cli 0.12.3-rc.2 → 0.12.3-rc.3

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.
Files changed (70) hide show
  1. package/dist/markus.mjs +85 -5
  2. package/dist/web-ui/assets/{AsyncState-DlUYNJNs.js → AsyncState-D2omBzdj.js} +1 -1
  3. package/dist/web-ui/assets/{ChatComponents-Buxli2VA.js → ChatComponents-lSVBiM5B.js} +1 -1
  4. package/dist/web-ui/assets/{ContentRenderer-Dry2nbFd.js → ContentRenderer-DxgRNOd1.js} +2 -2
  5. package/dist/web-ui/assets/{DeliverableShareModal-C5hu0BwE.js → DeliverableShareModal-DU0PupsS.js} +1 -1
  6. package/dist/web-ui/assets/Deliverables-BYacAH8w.js +6 -0
  7. package/dist/web-ui/assets/{MarkdownMessage-BU1Z2MSr.js → MarkdownMessage-DwxvYN4X.js} +1 -1
  8. package/dist/web-ui/assets/{Search-Dk7IVqDd.js → Search-jBc36ZOH.js} +1 -1
  9. package/dist/web-ui/assets/{SendToChat-CLVw1mNM.js → SendToChat-13m2h7gu.js} +1 -1
  10. package/dist/web-ui/assets/{Settings-BDFR0Z_o.js → Settings-BkKMrBt2.js} +1 -1
  11. package/dist/web-ui/assets/{Store-DSubNdbJ.js → Store-dLubNc0P.js} +1 -1
  12. package/dist/web-ui/assets/{Switch-CE_QndUQ.js → Switch-CXRQn2gn.js} +1 -1
  13. package/dist/web-ui/assets/{Team-lUUZwXVm.js → Team-zVv87kaX.js} +36 -36
  14. package/dist/web-ui/assets/Work-DbPgRas-.js +142 -0
  15. package/dist/web-ui/assets/{arc-CzLCxbPi.js → arc-C6rhmRdi.js} +1 -1
  16. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Bjt1eu5I.js → architectureDiagram-3BPJPVTR-BvaRSMDl.js} +1 -1
  17. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-5t_XsWP-.js → blockDiagram-GPEHLZMM-DP7IwNLE.js} +1 -1
  18. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-DC4yhIA-.js → c4Diagram-AAUBKEIU-CEQJBqku.js} +1 -1
  19. package/dist/web-ui/assets/channel-pUJ_pqAp.js +1 -0
  20. package/dist/web-ui/assets/{chunk-2J33WTMH-DpBVR8wv.js → chunk-2J33WTMH-BtGwhrHv.js} +1 -1
  21. package/dist/web-ui/assets/{chunk-4BX2VUAB-CRHzHTTM.js → chunk-4BX2VUAB-DNKfs4jy.js} +1 -1
  22. package/dist/web-ui/assets/{chunk-55IACEB6-BiE1vYDP.js → chunk-55IACEB6-Bd4eMlUg.js} +1 -1
  23. package/dist/web-ui/assets/{chunk-727SXJPM-C62sZl96.js → chunk-727SXJPM-CHmRT5rY.js} +1 -1
  24. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BWltDJW9.js → chunk-AQP2D5EJ-CmoWgw5d.js} +1 -1
  25. package/dist/web-ui/assets/{chunk-FMBD7UC4-Djfb2_hP.js → chunk-FMBD7UC4-Csafnaj6.js} +1 -1
  26. package/dist/web-ui/assets/{chunk-ND2GUHAM-B5S005b9.js → chunk-ND2GUHAM-Cip_3Llj.js} +1 -1
  27. package/dist/web-ui/assets/{chunk-QZHKN3VN-CHbAcqJY.js → chunk-QZHKN3VN-C0WlO578.js} +1 -1
  28. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-Cs9dF-hf.js +1 -0
  29. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-Cs9dF-hf.js +1 -0
  30. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BkLxosxB.js → cose-bilkent-S5V4N54A-ByhHiryW.js} +1 -1
  31. package/dist/web-ui/assets/{dagre-BM42HDAG-D3u0UzhI.js → dagre-BM42HDAG-B5-K3iqP.js} +1 -1
  32. package/dist/web-ui/assets/{diagram-2AECGRRQ-CI9nnxn2.js → diagram-2AECGRRQ-Ci16wMOI.js} +1 -1
  33. package/dist/web-ui/assets/{diagram-5GNKFQAL-CcHQ4hSh.js → diagram-5GNKFQAL-Dfnzu_xA.js} +1 -1
  34. package/dist/web-ui/assets/{diagram-KO2AKTUF-DdULvZjD.js → diagram-KO2AKTUF-K9NvC1S4.js} +1 -1
  35. package/dist/web-ui/assets/{diagram-LMA3HP47-CInbHt1K.js → diagram-LMA3HP47-CaKq8BY-.js} +1 -1
  36. package/dist/web-ui/assets/{diagram-OG6HWLK6-B29d5ucM.js → diagram-OG6HWLK6-DqY8Y9OR.js} +1 -1
  37. package/dist/web-ui/assets/{docx-preview-ChWyJtz_.js → docx-preview-DS9aOywt.js} +1 -1
  38. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CJnS1EyG.js → erDiagram-TEJ5UH35-iW17lrM1.js} +1 -1
  39. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-B2WoYwwl.js → flowDiagram-I6XJVG4X-BBkXZBPV.js} +1 -1
  40. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-DPV693xk.js → ganttDiagram-6RSMTGT7-J2QuVqg4.js} +1 -1
  41. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-3D2euYF9.js → gitGraphDiagram-PVQCEYII-EhZa3sGY.js} +1 -1
  42. package/dist/web-ui/assets/{index-BdiEUYQB.js → index-BHu6brRf.js} +56 -56
  43. package/dist/web-ui/assets/index-CzHSs0Vd.css +1 -0
  44. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-BWUbt7Jc.js → infoDiagram-5YYISTIA-BaiNGDG7.js} +1 -1
  45. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BE3afH_7.js → ishikawaDiagram-YF4QCWOH-BYN0gLmP.js} +1 -1
  46. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-CDm95QAx.js → journeyDiagram-JHISSGLW-CKUGXjL8.js} +1 -1
  47. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-c0jOBZCa.js → kanban-definition-UN3LZRKU-iKb5H8rf.js} +1 -1
  48. package/dist/web-ui/assets/{mermaid.core-c5cZjaP1.js → mermaid.core-BSghRCEC.js} +5 -5
  49. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BbsAVFCx.js → mindmap-definition-RKZ34NQL-JjtDu_0Z.js} +1 -1
  50. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-DyXBINfp.js → pieDiagram-4H26LBE5-BDXCI_g9.js} +1 -1
  51. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-gMRWTBzV.js → quadrantDiagram-W4KKPZXB-bATU3F6v.js} +1 -1
  52. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-OWjUHVO4.js → requirementDiagram-4Y6WPE33-BNJWpDxg.js} +1 -1
  53. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CsIAucjq.js → sankeyDiagram-5OEKKPKP-C3B8NPUe.js} +1 -1
  54. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BbxZog_d.js → sequenceDiagram-3UESZ5HK-DhGwy4UV.js} +1 -1
  55. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-CfNPAfJc.js → stateDiagram-AJRCARHV-BtfcmNhI.js} +1 -1
  56. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BOaSwLIS.js +1 -0
  57. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-BSO--1Kk.js → timeline-definition-PNZ67QCA-BpY3qMyG.js} +1 -1
  58. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-FBig_P4B.js → vennDiagram-CIIHVFJN-S0f15t2D.js} +1 -1
  59. package/dist/web-ui/assets/{wardley-L42UT6IY-BSFxmcZr.js → wardley-L42UT6IY-BdcJNPNt.js} +1 -1
  60. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-KgYOT0P6.js → wardleyDiagram-YWT4CUSO-mR-gwtcd.js} +1 -1
  61. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-TiGfFomq.js → xychartDiagram-2RQKCTM6-Dq0PtvdL.js} +1 -1
  62. package/dist/web-ui/index.html +2 -2
  63. package/package.json +1 -1
  64. package/dist/web-ui/assets/Deliverables-KM6_2Vwj.js +0 -3
  65. package/dist/web-ui/assets/Work-skYgAZu2.js +0 -142
  66. package/dist/web-ui/assets/channel-Dr_j_eV7.js +0 -1
  67. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DnBTgapK.js +0 -1
  68. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DnBTgapK.js +0 -1
  69. package/dist/web-ui/assets/index-CjwBVJDR.css +0 -1
  70. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BhOU2GYL.js +0 -1
@@ -1,4 +1,4 @@
1
- import{u as xe,r as i,j as e,a4 as Cs,k as F,a3 as $o,a1 as Vo,a6 as _o,a7 as Fo,h as _t,a8 as $a,a9 as Uo,aa as Ko,U as Ho,ab as zo,$ as Va,ac as qo,ad as Wo,ae as Go,af as Vn,ag as Jo,n as Ns,P as $r,_ as Yo,ah as Qo,ai as _n,aj as Zo,a as Xo,b as ei,c as ti,ak as Fn,al as si,am as ri,an as Un,ao as _a,i as ni,ap as ai,V as dr}from"./index-BdiEUYQB.js";import{L as oi}from"./AsyncState-DlUYNJNs.js";import{i as ii,S as Ut}from"./Switch-CE_QndUQ.js";function li(t,r){for(var o=0;o<r.length;o++){const a=r[o];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 di(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 ci(t){return t.maxInputTokens>0||t.inputCostPer1MTokens>0||t.outputCostPer1MTokens>0}function cr(t){if(t.tier)return t.tier;const r=t.id.toLowerCase(),o=/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":o.test(r)?"max":a.test(r)?"base":"pro"}const Kn={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 Fa({models:t,selectedModel:r,onSelect:o,loading:a,compact:n,maxVisible:s,showTiers:c}){const{t:d}=xe("settings"),[u,h]=i.useState(""),[x,k]=i.useState(!1),[v,y]=i.useState(""),S=i.useMemo(()=>{let m=t;if(u){const w=u.toLowerCase();m=m.filter($=>$.id.toLowerCase().includes(w))}return v&&(m=m.filter(w=>cr(w)===v)),m},[t,u,v]),N=i.useMemo(()=>{const m={max:0,pro:0,base:0};for(const w of t)m[cr(w)]++;return m},[t]),j=s??(n?5:10),p=x?S:S.slice(0,j),A=S.length>j;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:()=>y(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${v?"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=>N[m]>0).map(m=>e.jsx("button",{onClick:()=>y(v===m?"":m),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${v===m?Kn[m]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:d("modelPicker.tierCount",{tier:d(`modelRouting.tier.${m}`),count:N[m]})},m))]}),t.length>5&&e.jsx("input",{type:"text",value:u,onChange:m=>{h(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:p.map(m=>{const w=m.id===r,$=cr(m);return e.jsxs("button",{type:"button",onClick:()=>o(m.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${w?"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 ${w?"border-brand-500":"border-border-default"}`,children:w&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${w?"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 ${Kn[$]}`,children:d(`modelRouting.tier.${$}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:w&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:d("modelPicker.active")})})]}),ci(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:[di(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(Lt,{label:d("modelPicker.capabilities.tools")}),m.capabilities.vision&&e.jsx(Lt,{label:d("modelPicker.capabilities.vision")}),m.capabilities.reasoning&&e.jsx(Lt,{label:d("modelPicker.capabilities.reasoning")}),m.capabilities.promptCaching&&e.jsx(Lt,{label:d("modelPicker.capabilities.caching")}),m.capabilities.webSearch&&e.jsx(Lt,{label:d("modelPicker.capabilities.search")})]})]},m.id)})}),A&&!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:S.length})}),x&&A&&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 Lt({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 Kt({value:t,options:r,placeholder:o,onChange:a}){const{t:n}=xe("settings"),[s,c]=i.useState(!1),[d,u]=i.useState(""),h=i.useRef(null),x=i.useRef(null),k=i.useRef(null),[v,y]=i.useState(-1);i.useEffect(()=>{function m(w){h.current&&!h.current.contains(w.target)&&c(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]),i.useEffect(()=>{s&&x.current&&x.current.focus()},[s]);const S=i.useMemo(()=>{if(!d.trim())return r;const m=d.toLowerCase();return r.filter(w=>w.modelId.toLowerCase().includes(m)||w.modelName.toLowerCase().includes(m)||w.provider.toLowerCase().includes(m)||w.providerLabel.toLowerCase().includes(m)||w.tier&&w.tier.toLowerCase().includes(m))},[r,d]),N=i.useMemo(()=>{const m=new Map;for(const $ of S){const B=$.providerLabel;m.has(B)||m.set(B,[]),m.get(B).push($)}const w={max:0,pro:1,base:2};for(const $ of m.values())$.sort((B,I)=>(w[B.tier??"base"]??9)-(w[I.tier??"base"]??9));return m},[S]),j=i.useMemo(()=>{const m=[];for(const w of N.values())m.push(...w);return m},[N]),p=i.useMemo(()=>{if(!t)return o??n("modelRouting.auto");const m=r.find(w=>`${w.provider}/${w.modelId}`===t);return m?`${m.providerLabel}/${m.modelName}`:t},[t,r,o,n]);function A(m){if(!s){(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),c(!0));return}switch(m.key){case"ArrowDown":m.preventDefault(),y(w=>Math.min(w+1,j.length-1));break;case"ArrowUp":m.preventDefault(),y(w=>Math.max(w-1,-1));break;case"Enter":m.preventDefault(),v===-1?a(""):j[v]&&a(`${j[v].provider}/${j[v].modelId}`),c(!1),u("");break;case"Escape":c(!1),u("");break}}return i.useEffect(()=>{k.current&&v>=0&&k.current.querySelector(`[data-focus-index="${v}"]`)?.scrollIntoView({block:"nearest"})},[v]),e.jsxs("div",{ref:h,className:"relative min-w-0",onKeyDown:A,children:[e.jsx("button",{type:"button",onClick:()=>{c(!s),u(""),y(-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:p}),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),y(-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 ${v===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{a(""),c(!1),u("")},children:o??n("modelRouting.auto")}),[...N.entries()].map(([m,w])=>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}),w.map($=>{const B=j.indexOf($),I=`${$.provider}/${$.modelId}`===t;return e.jsxs("div",{"data-focus-index":B,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${B===v?"bg-brand-500/20":I?"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(ui,{tier:$.tier}),$.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:$.costTier})]},`${$.provider}/${$.modelId}`)})]},m)),j.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:n("modelPicker.empty")})]})]})]})}function ui({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 mi=500,Hn=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function xi({onSave:t,configuredProviders:r}){const{t:o}=xe(["settings","common"]),[a,n]=i.useState({}),[s,c]=i.useState(null),[d,u]=i.useState(!1),[h,x]=i.useState(null),[k,v]=i.useState(!0),[y,S]=i.useState("idle"),[N,j]=i.useState(null),[p,A]=i.useState({}),[m,w]=i.useState(!1),[$,B]=i.useState("idle"),[I,V]=i.useState(null),[C,M]=i.useState(!1),O=i.useRef(null),L=i.useRef(null),U=i.useMemo(()=>r.map(g=>g.name).sort().join(","),[r]);i.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]),i.useEffect(()=>{let g=!1;return v(!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 q of K.models)f.push({provider:K.provider,providerLabel:K.displayName,modelId:q.id,modelName:q.name,mode:q.mode,tier:q.tier,costTier:q.costTier,capabilities:q.capabilities});j(f)}).catch(()=>{g||j(null)}).finally(()=>{g||v(!1)}),()=>{g=!0}},[U]),i.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{A(g.suggestions),w(!0)}).catch(()=>w(!0))},[U]);const H=i.useCallback(g=>{S("saving"),t(g).then(()=>{S("saved"),setTimeout(()=>S(T=>T==="saved"?"idle":T),2e3)}).catch(()=>{S("error"),setTimeout(()=>S(T=>T==="error"?"idle":T),3e3)})},[t]),J=i.useCallback((g,T)=>{L.current={capabilityRouting:g!==void 0?{assignments:g}:L.current?.capabilityRouting,routingDefaultModel:T!==void 0?T:L.current?.routingDefaultModel},O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{const f=L.current;L.current=null,f&&H(f)},mi)},[H]),D=i.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]),_=N??D,ee=i.useMemo(()=>Object.entries(a).map(([g,T])=>`${g}:${T?.provider??""}/${T?.model??""}`).sort().join("|"),[a]);i.useEffect(()=>{!d||!N||N.length===0||N.some(g=>!!g.modelId)&&(n(g=>{let T=!1;const f={...g};for(const K of Hn)for(const q of K.capabilities){const ne=f[q];if(!ne?.model)continue;const oe=Ua(N,q);if(oe.length===0)continue;oe.some(se=>se.provider===ne.provider&&se.modelId===ne.model)||(delete f[q],T=!0)}return T?(J(f),f):g}),c(g=>{if(!g?.model||N.some(q=>q.provider===g.provider&&q.modelId===g.model))return g;const f=N.find(q=>q.provider==="markus"),K=f?{provider:f.provider,model:f.modelId}:{provider:N[0].provider,model:N[0].modelId};return t({routingDefaultModel:K}),K}))},[d,N,U,J,ee]);const ue=i.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(()=>{}),v(!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});j(T)}).catch(()=>{}).finally(()=>v(!1))},[]),le=i.useCallback(async()=>{if($!=="working"){B("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),ue(),B("idle"),S("saved"),setTimeout(()=>S(f=>f==="saved"?"idle":f),2e3)}catch(g){B("error"),V(g instanceof Error?g.message:String(g)),setTimeout(()=>B("idle"),4e3)}}},[$,ue]),te=_.length>0;return d?h?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:o("modelRouting.loadError",{error:h})}):k&&!te?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:o("modelRouting.loadingModels")})]})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(pi,{status:y,t:o}),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:o($==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),I&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:I})]})]}),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:o("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Kt,{value:s?`${s.provider}/${s.model}`:"",options:_,placeholder:o("modelRouting.defaultModelPlaceholder"),onChange:g=>{if(!g)c(null),J(void 0,null);else{const[T,...f]=g.split("/"),K={provider:T,model:f.join("/")};if(c(K),a.text){const q={...a};delete q.text,n(q),J(q,K)}else J(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:o("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("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:o("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:Hn.map(g=>e.jsx(gi,{groupKey:g.groupKey,capabilities:g.capabilities,assignments:a,suggestions:p,allModels:_,configuredProviderNames:new Set(r.map(T=>T.name)),t:o,onAssign:(T,f)=>{const K={...a};f?K[T]=f:delete K[T],n(K),J(K)}},g.groupKey))})]}),C&&e.jsx(Cs,{variant:"primary",title:o("modelRouting.restoreRecommended"),message:o("modelRouting.restoreConfirm"),confirmLabel:o("common:confirm"),onConfirm:()=>{M(!1),le()},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 gi({groupKey:t,capabilities:r,assignments:o,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 h=o[u],x=a[u],k=h?`${h.provider}/${h.model}`:"",v=Ua(n,u),y=x?v.find(A=>A.provider===x.provider&&A.modelId===x.model)?.modelName??x.model:void 0,S=v.length>0,N=h?fi(n,h.provider,h.model):void 0,j=h&&!s.has(h.provider),p=!!(h&&S&&u!=="text"&&!v.some(A=>A.provider===h.provider&&A.modelId===h.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 ${p?"bg-red-500/10 border border-red-500/30":j?"bg-yellow-500/10 border border-yellow-500/30":!S&&!h?"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:p?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:["⚠ ",h.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:c("modelRouting.mismatchHint")})]}),e.jsx(Kt,{value:"",options:v,placeholder:c("modelRouting.selectModel"),onChange:A=>{if(!A)d(u,null);else{const[m,...w]=A.split("/");d(u,{provider:m,model:w.join("/")})}}})]}):S?e.jsx(Kt,{value:k,options:v,placeholder:y?`${y} (${c("modelRouting.suggested")})`:c("modelRouting.selectModel"),onChange:A=>{if(!A)d(u,null);else{const[m,...w]=A.split("/");d(u,{provider:m,model:w.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:[p&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:c("modelRouting.mismatchHint"),children:"⚠"}),!p&&j&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:c("modelRouting.staleProvider"),children:"⚠"}),!p&&!j&&N&&e.jsx(zn,{tier:N}),!p&&!j&&!N&&h&&e.jsx(zn,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:h&&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 fi(t,r,o){return t.find(n=>n.provider===r&&n.modelId===o)?.tier}function pi({status:t,t:r}){if(t==="idle")return null;const o={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 ${o[t]}`,children:a[t]})}function zn({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 Ua(t,r){if(r==="text")return t.filter(c=>ii(c));const o={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=o[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 hi({configuredProviders:t}){const{t:r}=xe("settings"),[o,a]=i.useState(null),[n,s]=i.useState([]),[c,d]=i.useState(null),[u,h]=i.useState(null),x=i.useMemo(()=>t.map(N=>`${N.name}:${N.models?.length??0}`).sort().join(","),[t]),k=i.useCallback(async()=>{d(null);try{const[{agents:N},j]=await Promise.all([F.agents.list({lean:!0}),F.teams.list()]),p=j.teams.map(m=>({id:m.id,name:m.name}));s(p);const A=await Promise.all(N.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(N.length?A:null)}catch(N){d(String(N))}},[x]);i.useEffect(()=>{k()},[k,x]);const v=i.useMemo(()=>{const N=[];for(const j of t)for(const p of j.models??[])N.push({provider:j.name,providerLabel:j.displayName??j.name,modelId:p.id,modelName:p.name??p.id});return N},[t]),y=async(N,j)=>{h(N),d(null);try{if(j){const[p,A]=[j.slice(0,j.lastIndexOf("/")),j.slice(j.lastIndexOf("/")+1)];await F.agents.updateConfig(N,{llmConfig:{modelMode:"custom",primary:p,defaultModel:A}})}else await F.agents.updateConfig(N,{llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}});a(p=>p?.map(A=>A.id===N?{...A,override:j}:A)??p)}catch(p){d(String(p))}finally{h(null)}},S=i.useMemo(()=>{if(!o)return[];const N=new Map,j=[];for(const A of o)if(A.teamId){const m=N.get(A.teamId)??[];m.push(A),N.set(A.teamId,m)}else j.push(A);const p=[];j.length&&p.push({key:"ungrouped",label:r("perAgentModel.ungrouped",{defaultValue:"Ungrouped"}),rows:j});for(const A of n){const m=N.get(A.id);m?.length&&p.push({key:`team:${A.id}`,label:A.name,rows:m})}for(const[A,m]of N)n.some(w=>w.id===A)||p.push({key:`team:${A}`,label:A,rows:m});return p},[o,n,r]);return o===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}),(!o||o.length===0)&&!c&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:r("perAgentModel.noAgents",{defaultValue:"No agents available."})}),o&&o.length>0&&e.jsx("div",{className:"space-y-5",children:S.map(N=>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:N.label}),e.jsx("span",{className:"text-[10px] text-fg-tertiary/70 tabular-nums shrink-0",children:N.rows.length})]}),e.jsx("div",{className:"space-y-2",children:N.rows.map(j=>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:j.name}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 truncate",children:j.id})]}),e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2 md:w-[320px]",children:[j.override?e.jsxs(e.Fragment,{children:[e.jsx(Kt,{value:j.override,options:v,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:p=>{y(j.id,p||null)}}),e.jsx("button",{type:"button",disabled:u===j.id,onClick:()=>{y(j.id,null)},className:"shrink-0 px-2.5 py-1.5 text-xs border border-border-default rounded-lg hover:bg-surface-primary disabled:opacity-40 transition-colors",children:r("perAgentModel.reset",{defaultValue:"Reset"})})]}):e.jsx(Kt,{value:"",options:v,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:p=>{y(j.id,p||null)}}),u===j.id&&e.jsx("span",{className:"shrink-0 text-[10px] text-fg-tertiary",children:r("common:loading",{defaultValue:"…"})})]})]},j.id))})]},N.key))})]})}let ws=[],ps=null;async function bi(){return ps||(ps=(async()=>{try{ws=(await F.modelCatalog.providerCatalog()).providers??[]}catch{ws=[]}return ws})(),ps)}function yi(){const[t,r]=i.useState(ws);return i.useEffect(()=>{let o=!0;return bi().then(a=>{o&&r(a)}),()=>{o=!1}},[]),t}const vi="integrations.platforms",zr=(t,r)=>`settings:${vi}.${t}.${r}`,ji={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 Ni(t){return ji[t]}function wi(t,r){return t(zr(r.id,"label"),{defaultValue:r.label})}function Ka(t,r,o){const a=zr(r,`fields.${o.key}`);return{label:t(`${a}.label`,{defaultValue:o.label}),help:o.help?t(`${a}.help`,{defaultValue:o.help}):void 0,placeholder:o.placeholder?t(`${a}.placeholder`,{defaultValue:o.placeholder}):void 0,options:o.options?.map(n=>({value:n.value,label:t(`${a}.options.${n.value}`,{defaultValue:n.label})}))}}function ki(t,r,o){const a=[],n=zr(o,"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 Ci(t){return t("settings:integrations.guide.heading",{defaultValue:"Setup guide"})}function Si(t){return t.type==="boolean"?t.default===!0:t.multiple?Array.isArray(t.default)?[...t.default]:[]:t.default!==void 0?t.default:""}function Ss(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 qn(t){const r={};for(const o of t.fields){if(o.secret){r[o.key]="";continue}const a=t.values[o.key];r[o.key]=a??Si(o)}return r}function Wn(t,r,o={}){const a=[];for(const n of t)if(n.required){if(n.secret){if(!Ss(n,r[n.key]))continue;o[n.key]?.hasValue||a.push(n.key);continue}Ss(n,r[n.key])&&a.push(n.key)}return a}function Ai(t,r,o){const a={enabled:o};for(const n of t.fields){const s=r[n.key];if(n.secret){if(Ss(n,s))continue;a[n.key]=s;continue}s!==void 0&&(a[n.key]=s)}return a}function Pi(t){return t.filter(r=>r.required||r.type==="agent")}function Mi(t){return t.filter(r=>!(r.required||r.type==="agent"))}function Vr(t){return Array.isArray(t)?`[${t.map(Vr).join(",")}]`:t&&typeof t=="object"?`{${Object.entries(t).filter(([,o])=>o!==void 0).sort(([o],[a])=>o<a?-1:o>a?1:0).map(([o,a])=>`${JSON.stringify(o)}:${Vr(a)}`).join(",")}}`:JSON.stringify(t)??"null"}function Ti(t){return Vr({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 Ei(t){const r=t.ok===!0||t.success===!0;return{ok:r,text:t.message??t.error??(r?"OK":"Failed"),code:t.code}}function Ri(t){return t?.status==="awaiting_reply"||t?.status==="awaiting_inbound"}function Li(t,r=!1){return t.hasConfig?t.enabled?t.lastVerifiedAt||r?"verified":"unverified":"off":"unconfigured"}function Ii(t){return{id:"",platform:t.id,label:"",enabled:!0,connected:!1,hasConfig:!1,capabilities:t.capabilities,fields:t.fields,values:{},secrets:Bi(t.fields),agentId:null,notifyAgentId:null,channels:[],lastError:null,canListChannels:!1,lastVerifiedAt:null}}function Bi(t){const r={};for(const o of t)o.secret&&(r[o.key]={hasValue:!1});return r}function Oi(t){return t.id===""}function Gn(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 ur(t,r){return t.find(o=>o.nativeId===r)}function Jn(t,r,o,a){const n=t.filter(s=>s.nativeId!==r);return n.push({nativeId:r,kind:a??null,agentId:o}),n.sort((s,c)=>s.nativeId.localeCompare(c.nativeId))}function Yn(t,r){return t.filter(o=>o.nativeId!==r)}function Di(t,r){const o=new Set(r.map(a=>a.id));return t.filter(a=>!o.has(a.nativeId))}function $i(t,r){const o=r.trim().toLowerCase();return o?t.filter(a=>a.name.toLowerCase().includes(o)||a.id.toLowerCase().includes(o)):t}function Vi(t){const r=new Map;for(const o of t){const a=r.get(o.platform);a?a.push(o):r.set(o.platform,[o])}return[...r.entries()].map(([o,a])=>({platform:o,instances:a}))}function _i(t,r,o={}){const a=o.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 Fi(t,r,o){const[a,n]=i.useState([]),[s,c]=i.useState(null),[d,u]=i.useState(!1),h=i.useRef(t);h.current=t;const x=i.useRef(0),k=i.useCallback(()=>{if(!o||!r)return;const v=++x.current;u(!0),h.current(r).then(y=>{v===x.current&&(n(y.channels??[]),c(y.error??null))}).catch(y=>{v===x.current&&(n([]),c(y instanceof Error?y.message:String(y)))}).finally(()=>{v===x.current&&u(!1)})},[o,r]);return i.useEffect(()=>(k(),()=>{x.current+=1}),[k]),{channels:a,error:s,loading:d,reloadChannels:k}}const Ha=/^notify[A-Z]/,za="notifyEnabled";function Ui(t){return t.find(r=>r.key===za)}function Ki(t){return t.notifyTarget==="chat"||t.notifyTarget==="user"||Ha.test(t.key)}function Ht(t){return t.filter(r=>r.notifyTarget==="chat"||r.notifyTarget==="user")}function Hi(t){return t.filter(r=>!r.notifyTarget&&!r.secret&&r.key!==za&&Ha.test(r.key))}function zi(t){return t.filter(Ki)}function qa(t){return Ht(t).find(r=>r.notifyTarget==="chat")}function qi(t,r){const o=Ht(t);return o.length===0?"unsupported":o.some(a=>!Ss(a,r[a.key]))?"configured":"not-configured"}function Qn(t){return typeof t=="string"?{value:t,label:t}:{value:t.value,label:t.label??t.value,hint:t.hint}}function Zn(t,r,o){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(o)||n.startsWith(o))return 0;const c=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[\\s./:_-])${c}`).test(a)?1:2}function Wa({value:t,options:r,onChange:o,placeholder:a,filterPlaceholder:n,emptyText:s,customHint:c,disabled:d,ariaLabel:u,className:h}){const[x,k]=i.useState(!1),[v,y]=i.useState(""),[S,N]=i.useState(!1),[j,p]=i.useState(-1),A=i.useRef(null),m=i.useRef(null),w=i.useRef(null),$=i.useRef(null),B=i.useId(),[I,V]=i.useState({}),C=i.useMemo(()=>t?r.map(Qn).find(D=>D.value===t)?.label??t:a??"",[t,r,a]);i.useEffect(()=>{x||(y(C),N(!1))},[C,x]),i.useEffect(()=>{function D(_){const ee=_.target;$.current?.contains(ee)||A.current&&!A.current.contains(ee)&&k(!1)}return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);function M(){const D=m.current;if(!D)return;const _=D.getBoundingClientRect(),ee=Math.max(_.width,240),ue=window.innerHeight-_.bottom-8,le=ue<180&&_.top>ue;V({position:"fixed",left:_.left,width:ee,maxHeight:Math.min(260,le?Math.max(_.top-12,120):ue),...le?{bottom:window.innerHeight-_.top+4}:{top:_.bottom+4}})}i.useLayoutEffect(()=>{if(!x)return;M();const D=()=>M();return window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[x]);const O=i.useMemo(()=>{const D=r.map(Qn),_=v.trim(),ee=S?_.toLowerCase().split(/\s+/).filter(Boolean):[],ue=[];D.forEach((g,T)=>{const f=ee.length?Zn(g,ee,_.toLowerCase()):0;f!==null&&ue.push({row:g,score:f,idx:T})}),ue.sort((g,T)=>g.score-T.score||g.idx-T.idx);const le=[];if(a!==void 0){const g={value:"",label:a};(ee.length?Zn(g,ee,_.toLowerCase()):0)!==null&&le.push(g)}le.push(...ue.map(g=>g.row));const te=_&&!D.some(g=>g.value.toLowerCase()===_.toLowerCase());return c&&S&&te&&le.push({value:_,label:_,custom:!0}),le},[r,v,S,a,c]);i.useEffect(()=>{if(!x||j<0||!w.current)return;w.current.querySelector(`[data-index="${j}"]`)?.scrollIntoView({block:"nearest"})},[j,x,O.length]);function L(){d||(y(C),N(!1),p(O.findIndex(D=>D.value===t)),k(!0),requestAnimationFrame(()=>m.current?.select()))}function U(){k(!1),y(C),N(!1),p(-1)}function H(D){o(D.value),k(!1),y(D.value?D.label:a??""),N(!1),p(-1),m.current?.focus()}function J(D){if(D.key==="ArrowDown"||D.key==="ArrowUp"){if(D.preventDefault(),!x){L();return}p(_=>{const ee=D.key==="ArrowDown"?_+1:_-1;return Math.max(-1,Math.min(ee,O.length-1))});return}if(D.key==="Enter"){if(!x){D.preventDefault(),L();return}const _=O[j];_?(D.preventDefault(),H(_)):U();return}if(D.key==="Escape"&&x){D.preventDefault(),D.stopPropagation(),U();return}D.key==="Tab"&&x&&U()}return e.jsxs("div",{ref:A,className:`relative ${h??""}`,children:[e.jsx("input",{ref:m,type:"text",role:"combobox","aria-expanded":x,"aria-controls":x?B:void 0,"aria-autocomplete":"list","aria-label":u,"aria-activedescendant":x&&j>=0?`${B}-opt-${j}`:void 0,disabled:d,value:x?v:C,placeholder:n,onMouseDown:()=>{x?k(!1):L()},onChange:D=>{x||k(!0),y(D.target.value),N(!0),p(0)},onKeyDown:J,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&&$o.createPortal(e.jsxs("div",{id:B,role:"listbox",ref:D=>{w.current=D,$.current=D},style:I,onMouseDown:D=>D.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:[O.map((D,_)=>e.jsxs("div",{id:`${B}-opt-${_}`,"data-index":_,role:"option","aria-selected":D.value===t,onMouseDown:ee=>{ee.preventDefault(),H(D)},className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${_===j?"bg-brand-500/20":D.value===t?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,children:[e.jsx("span",{className:`flex-1 truncate ${D.custom?"text-brand-500":"text-fg-primary"}`,children:D.label}),D.hint&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:D.hint}),D.custom&&c&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:typeof c=="function"?c(D.value):c})]},`${D.custom?"custom:":""}${D.value}`)),O.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:s})]}),document.body)]})}async function Wi(){const{agents:t}=await F.agents.list({lean:!0});return t.map(r=>({id:r.id,name:r.name,role:r.role}))}let hs=null;function Ga(){return hs||(hs=Wi().catch(t=>{throw hs=null,t})),hs}function Gi(t=Ga,r=!0){const[o,a]=i.useState([]);return i.useEffect(()=>{if(!r)return;let n=!0;return t().then(s=>{n&&a(s)}).catch(()=>{n&&a([])}),()=>{n=!1}},[t,r]),o}function As({value:t,options:r,onChange:o,fieldKey:a,ariaLabel:n,disabled:s}){const{t:c}=xe(["settings"]);return e.jsx(Wa,{value:typeof t=="string"?t:"",options:r.map(d=>({value:d.id,label:d.name,hint:d.role})),onChange:d=>o(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 Ja({loading:t,error:r,onReload:o,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:o,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 ks="rounded-xl border border-border-default bg-surface-secondary p-4",Vt="text-sm font-semibold text-fg-primary",Ya="flex flex-wrap items-center justify-between gap-x-4 gap-y-2",Ji="flex flex-wrap items-start justify-between gap-x-4 gap-y-2",_r="shrink-0 text-sm text-fg-secondary",Qa="flex-1 min-w-[10rem] flex justify-end",vt="text-xs text-fg-tertiary",Fr="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 Ur(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 Yi={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"},Qi={verified:"bg-green-500",unverified:"bg-amber-400",off:"bg-gray-400",unconfigured:"bg-gray-400"},Zi={verified:"settings:integrations.status.verified",unverified:"settings:integrations.status.unverified",off:"settings:integrations.status.off",unconfigured:"settings:integrations.status.unconfigured"},Xi={verified:"Connected",unverified:"Not verified",off:"Off",unconfigured:"Not configured"};function el({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 ${Yi[t]}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qi[t]}`}),r(Zi[t],{defaultValue:Xi[t]})]})}function Ft({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 It({label:t,control:r,help:o,htmlFor:a,start:n=!1}){return e.jsxs("div",{children:[e.jsxs("div",{className:n?Ji:Ya,children:[a?e.jsx("label",{htmlFor:a,className:_r,children:t}):e.jsx("span",{className:_r,children:t}),e.jsx("div",{className:Qa,children:r})]}),o?e.jsx("p",{className:`${vt} mt-1.5`,children:o}):null]})}function tl({field:t,value:r,hasStored:o,onChange:a,platformId:n="",agentOptions:s=[]}){const{t:c}=xe(["settings"]),d=`integration-field-${t.key}`,[u,h]=i.useState(!1),x=i.useMemo(()=>n?Ka(c,n,t):{label:t.label,help:t.help,placeholder:t.placeholder,options:t.options},[c,n,t]),k=x.label,v=x.help,y=x.placeholder,S=x.options??t.options??[],N=e.jsxs(e.Fragment,{children:[k,t.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),j=t.secret&&o?c("settings:integrations.secretStored"):v||void 0;if(t.type==="boolean"){const m=r===!0;return e.jsx(It,{label:k,help:v,control:e.jsx(Ut,{checked:m,onChange:w=>a(t.key,w),label:k,size:"md",testId:`integration-field-${t.key}`})})}if(t.type==="agent")return e.jsx(It,{label:N,help:j,control:e.jsx("div",{className:"w-full","data-testid":`integration-field-${t.key}`,children:e.jsx(As,{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(It,{start:!0,label:N,help:j,control:e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5","data-testid":`integration-field-${t.key}`,children:S.map(w=>{const $=m.includes(w.value);return e.jsx("button",{type:"button","aria-pressed":$,"data-option":w.value,onClick:()=>a(t.key,$?m.filter(B=>B!==w.value):[...m,w.value]),className:Ur($),children:w.label},w.value)})})})}if(t.type==="select")return e.jsx(It,{label:N,help:j,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:Fr,children:(t.options??[]).map(m=>{const w=S.find($=>$.value===m.value)?.label??m.label;return e.jsx("option",{value:m.value,children:w},m.value)})})});const p=t.type==="password",A=t.type==="number";return e.jsx(It,{label:N,help:j,htmlFor:d,control:e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:d,"data-testid":`integration-field-${t.key}`,type:A?"number":p&&!u?"password":"text",value:r==null?"":String(r),placeholder:p&&o?c("settings:integrations.secretStoredPlaceholder"):y,onChange:m=>a(t.key,m.target.value),className:`${Fr}${p?" font-mono pr-10":""}`}),p&&e.jsx("button",{type:"button","aria-label":u?c("settings:integrations.hide",{defaultValue:"Hide"}):c("settings:integrations.show",{defaultValue:"Show"}),onClick:()=>h(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 jt({status:t,draft:r,fields:o=t.fields,onChange:a,agentOptions:n=[]}){return e.jsx(e.Fragment,{children:o.map(s=>e.jsx(tl,{field:s,platformId:t.id,value:r[s.key],hasStored:t.secrets[s.key]?.hasValue===!0,agentOptions:n,onChange:a},s.key))})}const Xn={pending:"bg-amber-400 animate-pulse",ok:"bg-emerald-500",failed:"bg-red-500"};function ea({label:t,hint:r,leg:o}){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 ${Xn[o.state]??Xn.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:o.state==="ok"?o.detail??a("integrations.connectionTest.legOk",{defaultValue:"Verified"}):o.state==="failed"?o.detail??a("integrations.connectionTest.legFailed",{defaultValue:"Failed"}):r})]})]})}function sl(t,r){const o=new Date(t);return Number.isNaN(o.getTime())?t:o.toLocaleString(r,{dateStyle:"medium",timeStyle:"short"})}function rl({test:t,starting:r,onStart:o,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(ea,{label:n("integrations.connectionTest.outbound",{defaultValue:"Outbound (bot → IM)"}),hint:n("integrations.connectionTest.outboundPending",{defaultValue:"Not sent yet"}),leg:t.outbound}),e.jsx(ea,{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(Ft,{type:t.status==="verified"?"ok":"err",text:c}):e.jsx("div",{className:"px-3 py-2 rounded-lg text-xs bg-surface-elevated text-fg-secondary",children:c}))]}):a?e.jsx(Ft,{type:"ok",text:n("integrations.connectionTest.lastVerified",{defaultValue:"Verified {{when}}.",when:sl(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:o,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-elevated 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 nl({status:t,values:r,setValue:o,channels:a=[],canListChannels:n=!1,channelsLoading:s=!1,channelsError:c=null,onReloadChannels:d=()=>{},channelsGuidance:u=null,testSlot:h}){const{t:x}=xe(["settings","common"]),[k,v]=i.useState(!1),y=Ht(t.fields),S=Hi(t.fields),N=Ui(t.fields),j=qi(t.fields,r),p=qa(t.fields),A=N?r[N.key]!==!1:!0,m=n&&p?p.key:null,w=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"})},B={configured:"text-green-600","not-configured":"text-amber-600",unsupported:"text-fg-tertiary"},I={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&&w!==""&&!a.some(L=>L.id===w),O="text-xs font-medium text-fg-secondary mb-2";return e.jsxs("section",{"data-testid":"notification-panel","data-reachability":j,className:ks,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsx("h3",{className:Vt,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 ${B[j]}`,"data-testid":"notification-reachability","data-state":j,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${I[j]}`}),$[j]]}),N&&e.jsx(Ut,{checked:A,onChange:L=>o(N.key,L),label:x("settings:instances.notify.masterLabel",{defaultValue:"Enable notifications"}),size:"md",testId:`integration-field-${N.key}`})]})]}),e.jsxs("div",{className:`space-y-4${A?"":" opacity-60"}`,children:[y.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:O,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(Ja,{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":w===L.id,"data-testid":`notification-chat-pick-${L.id}`,onClick:()=>o(m,L.id),className:Ur(w===L.id),children:L.name},L.id))}),a.length===0&&!s&&!c&&e.jsx("p",{"data-testid":"notification-chat-empty",className:vt,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:()=>o(m,w),className:Ur(!0),children:w})})]}),m===null&&e.jsx("p",{"data-testid":"notification-chat-guidance",className:vt,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:()=>v(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(jt,{status:t,draft:r,fields:y,onChange:o})})]}):e.jsx("div",{className:"mt-2",children:e.jsx(jt,{status:t,draft:r,fields:y,onChange:o})})]}),S.length>0&&e.jsxs("div",{"data-testid":"notification-preferences",className:"space-y-3",children:[e.jsx("div",{className:O,children:x("settings:instances.notify.content",{defaultValue:"What to send"})}),e.jsx(jt,{status:t,draft:r,fields:S,onChange:o})]}),h]})]})}const yt={fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round"},al={color:"#64748b",glyph:e.jsx("g",{...yt,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"})})},ol={feishu:{color:"#3370ff",glyph:e.jsx("g",{...yt,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",{...yt,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",{...yt,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",{...yt,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",{...yt,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 il(t){return ol[t]??al}function Za({id:t,size:r=36}){const o=il(t);return e.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded-lg",style:{width:r,height:r,backgroundColor:`${o.color}1a`,color:o.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:o.glyph})})}function ll({status:t,configured:r,canListChannels:o=!1,channelsGuidance:a=null}){const{t:n,i18n:s}=xe(["settings","common"]),[c,d]=i.useState(!r),u=i.useMemo(()=>{const k=ki(s,n,t.id);if(Ht(t.fields).length===0)return k;const v=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."}),y=o?{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:v}):v};return[...k,y]},[s,n,t.id,t.fields,o,a]),h=Ni(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:Ci(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,v)=>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:v+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:[h&&e.jsxs("a",{href:h,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-on-brand 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 Xa={create:(t,r)=>F.settings.createInstance(t,r).then(o=>o.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(o=>o.test),getConnectionTest:t=>F.settings.getConnectionTest(t).then(r=>r.test)},dl=700;function ta({instance:t,client:r=Xa,extras:o={},onChanged:a,onCreated:n,loadAgents:s,defaultExpanded:c}){const{t:d}=xe(["settings","common"]),u=Oi(t),[h,x]=i.useState(c??u),[k,v]=i.useState(!1),y=i.useMemo(()=>Gn(t),[t]),[S,N]=i.useState(t.label),[j,p]=i.useState(()=>qn(y)),[A,m]=i.useState(t.enabled),[w,$]=i.useState(t.channels),[B,I]=i.useState(typeof t.notifyAgentId=="string"?t.notifyAgentId:""),[V,C]=i.useState({kind:"idle"}),M=!!o[t.platform]?.guidedSetup,[O,L]=i.useState(M&&!t.hasConfig?"guided":"manual"),U=M&&O==="guided",{channels:H,error:J,loading:D,reloadChannels:_}=Fi(r.listChannels,t.id,h&&t.canListChannels),[ee,ue]=i.useState(""),[le,te]=i.useState(null),[g,T]=i.useState(!1),[f,K]=i.useState(null),q=Ri(le),[ne,oe]=i.useState(!1),ge=t.fields.some(E=>E.type==="agent"),se=Gi(i.useMemo(()=>s??Ga,[s]),ge),Je=i.useCallback(E=>E?se.find(ae=>ae.id===E)?.name??E:"",[se]),Ae=Ti(y),Se=i.useRef(t);Se.current=t;const Oe=i.useRef(!1),rt=i.useRef(!1);i.useEffect(()=>{if(Oe.current)return;const E=Se.current;N(E.label),p(qn(Gn(E))),m(E.enabled),$(E.channels),I(typeof E.notifyAgentId=="string"?E.notifyAgentId:"")},[Ae]),i.useEffect(()=>{C({kind:"idle"}),te(null),K(null),it(!1)},[t.id]),i.useEffect(()=>{L(M&&!t.hasConfig?"guided":"manual")},[t.id,t.hasConfig,M]);const we=i.useCallback(()=>{Oe.current=!0,C({kind:"idle"})},[]),fe=i.useCallback((E,ae)=>{we(),p(Z=>({...Z,[E]:ae}))},[we]),zt=i.useCallback(E=>{we(),N(E)},[we]),Ye=i.useCallback(E=>{we(),m(E)},[we]),Nt=i.useRef(()=>Promise.resolve()),De=i.useCallback(async()=>{if(!rt.current){rt.current=!0,C({kind:"saving"});try{let E=Se.current.id;E||(E=(await r.create(Se.current.platform,S.trim())).id),await r.save(E,{...Ai(y,j,A),notifyAgentId:B}),Se.current.canListChannels&&await r.saveChannels(E,w);let ae=null;try{const{ok:Z,text:Ze,code:Xt}=Ei(await r.test(E,{}));!Z&&!/not supported/i.test(Ze)&&(ae=Xt==="network_unreachable"?d("settings:integrations.savedNotVerifiedNetwork"):d("settings:integrations.savedNotVerified",{reason:Ze}))}catch(Z){ae=d("settings:integrations.savedNotVerified",{reason:String(Z)})}Oe.current=!1,C(ae?{kind:"error",text:ae}:{kind:"saved"}),await a?.(),Se.current.id===""&&n?.(E)}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}finally{rt.current=!1}}},[r,y,j,A,B,w,S,d,a,n]);Nt.current=De;const nt=Wn(y.fields,j,t.secrets),qt=u&&S.trim()==="",Wt=w.every(E=>E.agentId),Qe=!U&&!qt&&nt.length===0&&Wt,Re=i.useMemo(()=>JSON.stringify([S,A,B,w,j]),[S,A,B,w,j]);i.useEffect(()=>{if(!Oe.current||!Qe)return;const E=setTimeout(()=>{Nt.current()},dl);return()=>clearTimeout(E)},[Re,Qe]),i.useEffect(()=>{if(!h||u)return;let E=!0;return r.getConnectionTest(t.id).then(ae=>{E&&ae&&te(ae)}).catch(()=>{}),()=>{E=!1}},[h,u,r,t.id]),i.useEffect(()=>{if(!h||!q)return;let E=!0;const ae=setInterval(()=>{r.getConnectionTest(t.id).then(Z=>{E&&Z&&te(Z)}).catch(()=>{})},2500);return()=>{E=!1,clearInterval(ae)}},[h,q,r,t.id]);const wt=i.useRef(null);i.useEffect(()=>{le?.status==="verified"&&wt.current!==t.id&&(wt.current=t.id,a?.())},[le?.status,t.id,a]);const Gt=i.useCallback(async()=>{T(!0),K(null);try{te(await r.startConnectionTest(t.id))}catch(E){K(E instanceof Error?E.message:String(E))}finally{T(!1)}},[r,t.id]),ye=o[t.platform],_e=i.useMemo(()=>({platformId:t.platform,instanceId:t.id||void 0,status:y,values:j,setValue:fe,reload:()=>{a?.()},agents:se,onCreated:n,setupMethod:M?O:void 0,setSetupMethod:M?L:void 0}),[t.platform,t.id,y,j,fe,a,se,n,M,O]),Jt=i.useMemo(()=>new Set(ye?.ownedFields??[]),[ye]),at=Ht(y.fields).length>0,Yt=i.useMemo(()=>new Set(at?zi(y.fields).map(E=>E.key):[]),[y.fields,at]),ot=i.useMemo(()=>y.fields.filter(E=>!Jt.has(E.key)&&!Yt.has(E.key)),[y.fields,Jt,Yt]),kt=i.useMemo(()=>Pi(ot),[ot]),Qt=i.useMemo(()=>Mi(ot),[ot]),Zt=i.useMemo(()=>kt.filter(E=>E.type==="agent"),[kt]),Ct=i.useMemo(()=>kt.filter(E=>E.type!=="agent"),[kt]),[Ps,it]=i.useState(!1),Ms=i.useMemo(()=>Wn(t.fields,t.values,t.secrets),[t.fields,t.values,t.secrets]),lt=t.hasConfig&&!Ms.some(E=>Ct.some(ae=>ae.key===E)),dt=i.useMemo(()=>$i(H,ee),[H,ee]),St=i.useMemo(()=>Di(w,H),[w,H]),Fe=w.filter(E=>!E.agentId).length,Ts=i.useCallback((E,ae)=>{we(),$(Z=>ae?Jn(Z,E.id,ur(Z,E.id)?.agentId??t.agentId??"",E.kind??null):Yn(Z,E.id))},[we,t.agentId]),Pe=i.useCallback((E,ae)=>{we(),$(Z=>Jn(Z,E,ae,ur(Z,E)?.kind??null))},[we]),Es=i.useCallback(async()=>{oe(!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=Li(t,le?.status==="verified"),re=t.id||`new-${t.platform}`,ct=`instance-name-${re}`,At=nt.map(E=>{const ae=y.fields.find(Z=>Z.key===E);return ae?Ka(d,t.platform,ae).label:E}).join(", ");return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden border border-border-default","data-testid":`instance-card-${re}`,"data-instance":t.id,"data-platform":t.platform,"data-draft":u?"true":"false","data-expanded":h?"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":h,"data-testid":`instance-toggle-${re}`,className:"flex-1 min-w-0 flex items-center gap-3 text-left",children:[e.jsx(Za,{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-${re}`,children:S.trim()===""?d("settings:instances.newBot",{defaultValue:"New bot"}):S}),!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-${re}`,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-${re}`,title:d("settings:instances.boundAgent",{defaultValue:"Bound agent"}),children:[e.jsx("span",{className:"text-fg-muted",children:"→"}),Je(t.agentId)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(el,{state:Ue}),!u&&e.jsx(Ut,{checked:A,onChange:Ye,size:"md",testId:`instance-enabled-${re}`,label:d("settings:instances.toggleLabel",{defaultValue:"Turn this bot on or off"})}),e.jsx("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":h,"data-testid":`instance-chevron-${re}`,className:"p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:e.jsx("svg",{className:`w-4 h-4 transition-transform ${h?"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"})})})]})]}),h&&e.jsxs("div",{className:"px-6 pb-6 pt-5 border-t border-border-default space-y-6",children:[!t.hasConfig&&!U&&e.jsx(ll,{status:y,configured:t.hasConfig,canListChannels:t.canListChannels,channelsGuidance:t.channelsGuidance??null}),!M&&ye?.placement==="before"&&ye.render(_e),e.jsxs("section",{"data-testid":`instance-credentials-${re}`,className:ks,children:[e.jsx("h3",{className:`${Vt} 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":O===E,onClick:()=>L(E),"data-testid":`setup-method-${E}-${re}`,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${O===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:Ya,children:[e.jsxs("label",{htmlFor:ct,className:_r,children:[d("settings:instances.addBot.name",{defaultValue:"Bot name"}),e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:Qa,children:e.jsx("input",{id:ct,"data-testid":`new-bot-name-${t.platform}`,value:S,onChange:E=>zt(E.target.value),placeholder:d("settings:instances.addBot.namePlaceholder",{defaultValue:"e.g. Sales"}),className:Fr})})]}),Zt.length>0&&e.jsx(jt,{status:y,draft:j,fields:Zt,onChange:fe,agentOptions:se}),Ct.length>0&&(lt&&!Ps?e.jsx("div",{"data-testid":`instance-credentials-configured-${re}`,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:()=>it(!0),"data-testid":`instance-credentials-edit-${re}`,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:[lt&&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:()=>it(!1),"data-testid":`instance-credentials-hide-${re}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsHide",{defaultValue:"Hide"})})]}),e.jsx(jt,{status:y,draft:j,fields:Ct,onChange:fe,agentOptions:se})]}))]}),e.jsx("div",{className:"mt-3 min-h-[1.25rem]","data-testid":`instance-save-state-${re}`,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-${re}`,children:nt.length>0?d("settings:integrations.missingRequired",{defaultValue:"Required: {{fields}}",fields:At}):d("settings:instances.addBot.labelRequired",{defaultValue:"Give the bot a name."})})]})}),V.kind==="error"&&e.jsx("div",{className:"mt-2",children:e.jsx(Ft,{type:"err",text:V.text})})]}),!u&&e.jsxs("section",{children:[e.jsx(rl,{test:le,starting:g,lastVerifiedAt:t.lastVerifiedAt,onStart:()=>{Gt()}}),f&&e.jsx("div",{className:"mt-3",children:e.jsx(Ft,{type:"err",text:f})})]}),!u&&at&&e.jsx(nl,{status:y,values:j,setValue:fe,channels:H,canListChannels:t.canListChannels,channelsLoading:D,channelsError:J,onReloadChannels:_,channelsGuidance:t.channelsGuidance??null,testSlot:ye?.sendTest?.(_e)}),e.jsxs("section",{"data-testid":`instance-more-${re}`,children:[e.jsxs("button",{type:"button",onClick:()=>v(E=>!E),"aria-expanded":k,"data-testid":`instance-more-toggle-${re}`,className:"w-full flex items-center gap-2 text-left group px-1",children:[e.jsx("span",{className:Vt,children:d("settings:instances.moreSettings",{defaultValue:"Advanced"})}),e.jsx("span",{className:`${vt} 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:[Qt.length>0&&e.jsxs("div",{className:ks,children:[e.jsx("h4",{className:`${Vt} mb-1`,children:d("settings:instances.advancedTitle",{defaultValue:"Platform options"})}),!u&&e.jsx("p",{className:`${vt} 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(jt,{status:y,draft:j,fields:Qt,onChange:fe,agentOptions:se})]}),!u&&e.jsxs("div",{className:ks,children:[e.jsx("h4",{className:`${Vt} mb-1`,children:d("settings:instances.routing.chats",{defaultValue:"Chat routing"})}),e.jsx("p",{className:`${vt} 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-${re}`,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(Ja,{loading:D,error:J,onReload:_,empty:H.length===0,buttonTestId:`instance-chats-refresh-${re}`,errorTestId:`instance-chats-error-${re}`})}),t.canListChannels&&H.length>0&&e.jsx("input",{type:"text",value:ee,onChange:E=>ue(E.target.value),placeholder:d("settings:instances.routing.searchChats",{defaultValue:"Search chats…"}),"data-testid":`instance-chat-search-${re}`,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-${re}`,children:[dt.map(E=>{const ae=ur(w,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:!!ae,"data-testid":`instance-chat-toggle-${re}-${E.id}`,onChange:Z=>Ts(E,Z.target.checked),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate",title:E.id,children:E.name})]}),ae&&e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${re}-${E.id}`,children:e.jsx(As,{value:ae.agentId,options:se,onChange:(Z,Ze)=>Pe(E.id,typeof Ze=="string"?Ze:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.id)}),St.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-${re}-${E.nativeId}`,onChange:()=>$(ae=>Yn(ae,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-${re}-${E.nativeId}`,children:e.jsx(As,{value:E.agentId,options:se,onChange:(ae,Z)=>Pe(E.nativeId,typeof Z=="string"?Z:""),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."})}),Fe>0&&e.jsx("div",{className:"mt-3",children:e.jsx(Ft,{type:"err",text:d("settings:instances.routing.agentRequired",{defaultValue:"Pick an agent for every selected chat ({{count}} still unassigned).",count:Fe})})})]})]})]}),!M&&ye&&ye.placement!=="before"&&ye.render(_e),!u&&e.jsx("div",{className:"pt-1",children:e.jsx("button",{type:"button",onClick:()=>oe(!0),"data-testid":`instance-disconnect-${re}`,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"})})})]}),ne&&e.jsx(Cs,{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:()=>{Es()},onCancel:()=>oe(!1)})]})}var ht={},mr,sa;function cl(){return sa||(sa=1,mr=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),mr}var xr={},We={},ra;function tt(){if(ra)return We;ra=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 We.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},We.getSymbolTotalCodewords=function(a){return r[a]},We.getBCHDigit=function(o){let a=0;for(;o!==0;)a++,o>>>=1;return a},We.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},We.isKanjiModeEnabled=function(){return typeof t<"u"},We.toSJIS=function(a){return t(a)},We}var gr={},na;function qr(){return na||(na=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.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: "+o)}}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}}})(gr)),gr}var fr,aa;function ul(){if(aa)return fr;aa=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(r){const o=Math.floor(r/8);return(this.buffer[o]>>>7-r%8&1)===1},put:function(r,o){for(let a=0;a<o;a++)this.putBit((r>>>o-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),r&&(this.buffer[o]|=128>>>this.length%8),this.length++}},fr=t,fr}var pr,oa;function ml(){if(oa)return pr;oa=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,o,a,n){const s=r*this.size+o;this.data[s]=a,n&&(this.reservedBit[s]=!0)},t.prototype.get=function(r,o){return this.data[r*this.size+o]},t.prototype.xor=function(r,o,a){this.data[r*this.size+o]^=a},t.prototype.isReserved=function(r,o){return this.reservedBit[r*this.size+o]},pr=t,pr}var hr={},ia;function xl(){return ia||(ia=1,(function(t){const r=tt().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}})(hr)),hr}var br={},la;function gl(){if(la)return br;la=1;const t=tt().getSymbolSize,r=7;return br.getPositions=function(a){const n=t(a);return[[0,0],[n-r,0],[0,n-r]]},br}var yr={},da;function fl(){return da||(da=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,h=null,x=null;for(let k=0;k<s;k++){d=u=0,h=x=null;for(let v=0;v<s;v++){let y=n.get(k,v);y===h?d++:(d>=5&&(c+=r.N1+(d-5)),h=y,d=1),y=n.get(v,k),y===x?u++:(u>=5&&(c+=r.N1+(u-5)),x=y,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 h=n.get(d,u)+n.get(d,u+1)+n.get(d+1,u)+n.get(d+1,u+1);(h===4||h===0)&&c++}return c*r.N2},t.getPenaltyN3=function(n){const s=n.size;let c=0,d=0,u=0;for(let h=0;h<s;h++){d=u=0;for(let x=0;x<s;x++)d=d<<1&2047|n.get(h,x),x>=10&&(d===1488||d===93)&&c++,u=u<<1&2047|n.get(x,h),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 o(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,o(n,u,d))},t.getBestMask=function(n,s){const c=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let h=0;h<c;h++){s(h),t.applyMask(h,n);const x=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(h,n),x<u&&(u=x,d=h)}return d}})(yr)),yr}var bs={},ca;function eo(){if(ca)return bs;ca=1;const t=qr(),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],o=[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 bs.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}},bs.getTotalCodewordsCount=function(n,s){switch(s){case t.L:return o[(n-1)*4+0];case t.M:return o[(n-1)*4+1];case t.Q:return o[(n-1)*4+2];case t.H:return o[(n-1)*4+3];default:return}},bs}var vr={},Bt={},ua;function pl(){if(ua)return Bt;ua=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]})(),Bt.log=function(a){if(a<1)throw new Error("log("+a+")");return r[a]},Bt.exp=function(a){return t[a]},Bt.mul=function(a,n){return a===0||n===0?0:t[r[a]+r[n]]},Bt}var ma;function hl(){return ma||(ma=1,(function(t){const r=pl();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}})(vr)),vr}var jr,xa;function bl(){if(xa)return jr;xa=1;const t=hl();function r(o){this.genPoly=void 0,this.degree=o,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},jr=r,jr}var Nr={},wr={},kr={},ga;function to(){return ga||(ga=1,kr.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),kr}var Ie={},fa;function so(){if(fa)return Ie;fa=1;const t="[0-9]+",r="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
1
+ import{u as xe,r as i,j as e,a4 as Cs,k as F,a3 as $o,a1 as Vo,a6 as _o,a7 as Fo,h as _t,a8 as $a,a9 as Uo,aa as Ko,U as Ho,ab as zo,$ as Va,ac as qo,ad as Wo,ae as Go,af as Vn,ag as Jo,n as Ns,P as $r,_ as Yo,ah as Qo,ai as _n,aj as Zo,a as Xo,b as ei,c as ti,ak as Fn,al as si,am as ri,an as Un,ao as _a,i as ni,ap as ai,V as dr}from"./index-BHu6brRf.js";import{L as oi}from"./AsyncState-D2omBzdj.js";import{i as ii,S as Ut}from"./Switch-CXRQn2gn.js";function li(t,r){for(var o=0;o<r.length;o++){const a=r[o];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 di(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 ci(t){return t.maxInputTokens>0||t.inputCostPer1MTokens>0||t.outputCostPer1MTokens>0}function cr(t){if(t.tier)return t.tier;const r=t.id.toLowerCase(),o=/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":o.test(r)?"max":a.test(r)?"base":"pro"}const Kn={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 Fa({models:t,selectedModel:r,onSelect:o,loading:a,compact:n,maxVisible:s,showTiers:c}){const{t:d}=xe("settings"),[u,h]=i.useState(""),[x,k]=i.useState(!1),[v,y]=i.useState(""),S=i.useMemo(()=>{let m=t;if(u){const w=u.toLowerCase();m=m.filter($=>$.id.toLowerCase().includes(w))}return v&&(m=m.filter(w=>cr(w)===v)),m},[t,u,v]),N=i.useMemo(()=>{const m={max:0,pro:0,base:0};for(const w of t)m[cr(w)]++;return m},[t]),j=s??(n?5:10),p=x?S:S.slice(0,j),A=S.length>j;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:()=>y(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${v?"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=>N[m]>0).map(m=>e.jsx("button",{onClick:()=>y(v===m?"":m),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${v===m?Kn[m]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:d("modelPicker.tierCount",{tier:d(`modelRouting.tier.${m}`),count:N[m]})},m))]}),t.length>5&&e.jsx("input",{type:"text",value:u,onChange:m=>{h(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:p.map(m=>{const w=m.id===r,$=cr(m);return e.jsxs("button",{type:"button",onClick:()=>o(m.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${w?"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 ${w?"border-brand-500":"border-border-default"}`,children:w&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${w?"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 ${Kn[$]}`,children:d(`modelRouting.tier.${$}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:w&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:d("modelPicker.active")})})]}),ci(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:[di(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(Lt,{label:d("modelPicker.capabilities.tools")}),m.capabilities.vision&&e.jsx(Lt,{label:d("modelPicker.capabilities.vision")}),m.capabilities.reasoning&&e.jsx(Lt,{label:d("modelPicker.capabilities.reasoning")}),m.capabilities.promptCaching&&e.jsx(Lt,{label:d("modelPicker.capabilities.caching")}),m.capabilities.webSearch&&e.jsx(Lt,{label:d("modelPicker.capabilities.search")})]})]},m.id)})}),A&&!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:S.length})}),x&&A&&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 Lt({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 Kt({value:t,options:r,placeholder:o,onChange:a}){const{t:n}=xe("settings"),[s,c]=i.useState(!1),[d,u]=i.useState(""),h=i.useRef(null),x=i.useRef(null),k=i.useRef(null),[v,y]=i.useState(-1);i.useEffect(()=>{function m(w){h.current&&!h.current.contains(w.target)&&c(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]),i.useEffect(()=>{s&&x.current&&x.current.focus()},[s]);const S=i.useMemo(()=>{if(!d.trim())return r;const m=d.toLowerCase();return r.filter(w=>w.modelId.toLowerCase().includes(m)||w.modelName.toLowerCase().includes(m)||w.provider.toLowerCase().includes(m)||w.providerLabel.toLowerCase().includes(m)||w.tier&&w.tier.toLowerCase().includes(m))},[r,d]),N=i.useMemo(()=>{const m=new Map;for(const $ of S){const B=$.providerLabel;m.has(B)||m.set(B,[]),m.get(B).push($)}const w={max:0,pro:1,base:2};for(const $ of m.values())$.sort((B,I)=>(w[B.tier??"base"]??9)-(w[I.tier??"base"]??9));return m},[S]),j=i.useMemo(()=>{const m=[];for(const w of N.values())m.push(...w);return m},[N]),p=i.useMemo(()=>{if(!t)return o??n("modelRouting.auto");const m=r.find(w=>`${w.provider}/${w.modelId}`===t);return m?`${m.providerLabel}/${m.modelName}`:t},[t,r,o,n]);function A(m){if(!s){(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),c(!0));return}switch(m.key){case"ArrowDown":m.preventDefault(),y(w=>Math.min(w+1,j.length-1));break;case"ArrowUp":m.preventDefault(),y(w=>Math.max(w-1,-1));break;case"Enter":m.preventDefault(),v===-1?a(""):j[v]&&a(`${j[v].provider}/${j[v].modelId}`),c(!1),u("");break;case"Escape":c(!1),u("");break}}return i.useEffect(()=>{k.current&&v>=0&&k.current.querySelector(`[data-focus-index="${v}"]`)?.scrollIntoView({block:"nearest"})},[v]),e.jsxs("div",{ref:h,className:"relative min-w-0",onKeyDown:A,children:[e.jsx("button",{type:"button",onClick:()=>{c(!s),u(""),y(-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:p}),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),y(-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 ${v===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{a(""),c(!1),u("")},children:o??n("modelRouting.auto")}),[...N.entries()].map(([m,w])=>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}),w.map($=>{const B=j.indexOf($),I=`${$.provider}/${$.modelId}`===t;return e.jsxs("div",{"data-focus-index":B,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${B===v?"bg-brand-500/20":I?"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(ui,{tier:$.tier}),$.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:$.costTier})]},`${$.provider}/${$.modelId}`)})]},m)),j.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:n("modelPicker.empty")})]})]})]})}function ui({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 mi=500,Hn=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function xi({onSave:t,configuredProviders:r}){const{t:o}=xe(["settings","common"]),[a,n]=i.useState({}),[s,c]=i.useState(null),[d,u]=i.useState(!1),[h,x]=i.useState(null),[k,v]=i.useState(!0),[y,S]=i.useState("idle"),[N,j]=i.useState(null),[p,A]=i.useState({}),[m,w]=i.useState(!1),[$,B]=i.useState("idle"),[I,V]=i.useState(null),[C,M]=i.useState(!1),O=i.useRef(null),L=i.useRef(null),U=i.useMemo(()=>r.map(g=>g.name).sort().join(","),[r]);i.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]),i.useEffect(()=>{let g=!1;return v(!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 q of K.models)f.push({provider:K.provider,providerLabel:K.displayName,modelId:q.id,modelName:q.name,mode:q.mode,tier:q.tier,costTier:q.costTier,capabilities:q.capabilities});j(f)}).catch(()=>{g||j(null)}).finally(()=>{g||v(!1)}),()=>{g=!0}},[U]),i.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}`);return g.json()}).then(g=>{A(g.suggestions),w(!0)}).catch(()=>w(!0))},[U]);const H=i.useCallback(g=>{S("saving"),t(g).then(()=>{S("saved"),setTimeout(()=>S(T=>T==="saved"?"idle":T),2e3)}).catch(()=>{S("error"),setTimeout(()=>S(T=>T==="error"?"idle":T),3e3)})},[t]),J=i.useCallback((g,T)=>{L.current={capabilityRouting:g!==void 0?{assignments:g}:L.current?.capabilityRouting,routingDefaultModel:T!==void 0?T:L.current?.routingDefaultModel},O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{const f=L.current;L.current=null,f&&H(f)},mi)},[H]),D=i.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]),_=N??D,ee=i.useMemo(()=>Object.entries(a).map(([g,T])=>`${g}:${T?.provider??""}/${T?.model??""}`).sort().join("|"),[a]);i.useEffect(()=>{!d||!N||N.length===0||N.some(g=>!!g.modelId)&&(n(g=>{let T=!1;const f={...g};for(const K of Hn)for(const q of K.capabilities){const ne=f[q];if(!ne?.model)continue;const oe=Ua(N,q);if(oe.length===0)continue;oe.some(se=>se.provider===ne.provider&&se.modelId===ne.model)||(delete f[q],T=!0)}return T?(J(f),f):g}),c(g=>{if(!g?.model||N.some(q=>q.provider===g.provider&&q.modelId===g.model))return g;const f=N.find(q=>q.provider==="markus"),K=f?{provider:f.provider,model:f.modelId}:{provider:N[0].provider,model:N[0].modelId};return t({routingDefaultModel:K}),K}))},[d,N,U,J,ee]);const ue=i.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(()=>{}),v(!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});j(T)}).catch(()=>{}).finally(()=>v(!1))},[]),le=i.useCallback(async()=>{if($!=="working"){B("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),ue(),B("idle"),S("saved"),setTimeout(()=>S(f=>f==="saved"?"idle":f),2e3)}catch(g){B("error"),V(g instanceof Error?g.message:String(g)),setTimeout(()=>B("idle"),4e3)}}},[$,ue]),te=_.length>0;return d?h?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:o("modelRouting.loadError",{error:h})}):k&&!te?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:o("modelRouting.loadingModels")})]})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(pi,{status:y,t:o}),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:o($==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),I&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:I})]})]}),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:o("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(Kt,{value:s?`${s.provider}/${s.model}`:"",options:_,placeholder:o("modelRouting.defaultModelPlaceholder"),onChange:g=>{if(!g)c(null),J(void 0,null);else{const[T,...f]=g.split("/"),K={provider:T,model:f.join("/")};if(c(K),a.text){const q={...a};delete q.text,n(q),J(q,K)}else J(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:o("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:o("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:o("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:Hn.map(g=>e.jsx(gi,{groupKey:g.groupKey,capabilities:g.capabilities,assignments:a,suggestions:p,allModels:_,configuredProviderNames:new Set(r.map(T=>T.name)),t:o,onAssign:(T,f)=>{const K={...a};f?K[T]=f:delete K[T],n(K),J(K)}},g.groupKey))})]}),C&&e.jsx(Cs,{variant:"primary",title:o("modelRouting.restoreRecommended"),message:o("modelRouting.restoreConfirm"),confirmLabel:o("common:confirm"),onConfirm:()=>{M(!1),le()},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 gi({groupKey:t,capabilities:r,assignments:o,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 h=o[u],x=a[u],k=h?`${h.provider}/${h.model}`:"",v=Ua(n,u),y=x?v.find(A=>A.provider===x.provider&&A.modelId===x.model)?.modelName??x.model:void 0,S=v.length>0,N=h?fi(n,h.provider,h.model):void 0,j=h&&!s.has(h.provider),p=!!(h&&S&&u!=="text"&&!v.some(A=>A.provider===h.provider&&A.modelId===h.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 ${p?"bg-red-500/10 border border-red-500/30":j?"bg-yellow-500/10 border border-yellow-500/30":!S&&!h?"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:p?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:["⚠ ",h.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:c("modelRouting.mismatchHint")})]}),e.jsx(Kt,{value:"",options:v,placeholder:c("modelRouting.selectModel"),onChange:A=>{if(!A)d(u,null);else{const[m,...w]=A.split("/");d(u,{provider:m,model:w.join("/")})}}})]}):S?e.jsx(Kt,{value:k,options:v,placeholder:y?`${y} (${c("modelRouting.suggested")})`:c("modelRouting.selectModel"),onChange:A=>{if(!A)d(u,null);else{const[m,...w]=A.split("/");d(u,{provider:m,model:w.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:[p&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:c("modelRouting.mismatchHint"),children:"⚠"}),!p&&j&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:c("modelRouting.staleProvider"),children:"⚠"}),!p&&!j&&N&&e.jsx(zn,{tier:N}),!p&&!j&&!N&&h&&e.jsx(zn,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:h&&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 fi(t,r,o){return t.find(n=>n.provider===r&&n.modelId===o)?.tier}function pi({status:t,t:r}){if(t==="idle")return null;const o={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 ${o[t]}`,children:a[t]})}function zn({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 Ua(t,r){if(r==="text")return t.filter(c=>ii(c));const o={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=o[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 hi({configuredProviders:t}){const{t:r}=xe("settings"),[o,a]=i.useState(null),[n,s]=i.useState([]),[c,d]=i.useState(null),[u,h]=i.useState(null),x=i.useMemo(()=>t.map(N=>`${N.name}:${N.models?.length??0}`).sort().join(","),[t]),k=i.useCallback(async()=>{d(null);try{const[{agents:N},j]=await Promise.all([F.agents.list({lean:!0}),F.teams.list()]),p=j.teams.map(m=>({id:m.id,name:m.name}));s(p);const A=await Promise.all(N.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(N.length?A:null)}catch(N){d(String(N))}},[x]);i.useEffect(()=>{k()},[k,x]);const v=i.useMemo(()=>{const N=[];for(const j of t)for(const p of j.models??[])N.push({provider:j.name,providerLabel:j.displayName??j.name,modelId:p.id,modelName:p.name??p.id});return N},[t]),y=async(N,j)=>{h(N),d(null);try{if(j){const[p,A]=[j.slice(0,j.lastIndexOf("/")),j.slice(j.lastIndexOf("/")+1)];await F.agents.updateConfig(N,{llmConfig:{modelMode:"custom",primary:p,defaultModel:A}})}else await F.agents.updateConfig(N,{llmConfig:{modelMode:"default",primary:"",defaultModel:void 0}});a(p=>p?.map(A=>A.id===N?{...A,override:j}:A)??p)}catch(p){d(String(p))}finally{h(null)}},S=i.useMemo(()=>{if(!o)return[];const N=new Map,j=[];for(const A of o)if(A.teamId){const m=N.get(A.teamId)??[];m.push(A),N.set(A.teamId,m)}else j.push(A);const p=[];j.length&&p.push({key:"ungrouped",label:r("perAgentModel.ungrouped",{defaultValue:"Ungrouped"}),rows:j});for(const A of n){const m=N.get(A.id);m?.length&&p.push({key:`team:${A.id}`,label:A.name,rows:m})}for(const[A,m]of N)n.some(w=>w.id===A)||p.push({key:`team:${A}`,label:A,rows:m});return p},[o,n,r]);return o===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}),(!o||o.length===0)&&!c&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:r("perAgentModel.noAgents",{defaultValue:"No agents available."})}),o&&o.length>0&&e.jsx("div",{className:"space-y-5",children:S.map(N=>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:N.label}),e.jsx("span",{className:"text-[10px] text-fg-tertiary/70 tabular-nums shrink-0",children:N.rows.length})]}),e.jsx("div",{className:"space-y-2",children:N.rows.map(j=>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:j.name}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 truncate",children:j.id})]}),e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2 md:w-[320px]",children:[j.override?e.jsxs(e.Fragment,{children:[e.jsx(Kt,{value:j.override,options:v,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:p=>{y(j.id,p||null)}}),e.jsx("button",{type:"button",disabled:u===j.id,onClick:()=>{y(j.id,null)},className:"shrink-0 px-2.5 py-1.5 text-xs border border-border-default rounded-lg hover:bg-surface-primary disabled:opacity-40 transition-colors",children:r("perAgentModel.reset",{defaultValue:"Reset"})})]}):e.jsx(Kt,{value:"",options:v,placeholder:r("perAgentModel.followGlobal",{defaultValue:"Follow global"}),onChange:p=>{y(j.id,p||null)}}),u===j.id&&e.jsx("span",{className:"shrink-0 text-[10px] text-fg-tertiary",children:r("common:loading",{defaultValue:"…"})})]})]},j.id))})]},N.key))})]})}let ws=[],ps=null;async function bi(){return ps||(ps=(async()=>{try{ws=(await F.modelCatalog.providerCatalog()).providers??[]}catch{ws=[]}return ws})(),ps)}function yi(){const[t,r]=i.useState(ws);return i.useEffect(()=>{let o=!0;return bi().then(a=>{o&&r(a)}),()=>{o=!1}},[]),t}const vi="integrations.platforms",zr=(t,r)=>`settings:${vi}.${t}.${r}`,ji={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 Ni(t){return ji[t]}function wi(t,r){return t(zr(r.id,"label"),{defaultValue:r.label})}function Ka(t,r,o){const a=zr(r,`fields.${o.key}`);return{label:t(`${a}.label`,{defaultValue:o.label}),help:o.help?t(`${a}.help`,{defaultValue:o.help}):void 0,placeholder:o.placeholder?t(`${a}.placeholder`,{defaultValue:o.placeholder}):void 0,options:o.options?.map(n=>({value:n.value,label:t(`${a}.options.${n.value}`,{defaultValue:n.label})}))}}function ki(t,r,o){const a=[],n=zr(o,"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 Ci(t){return t("settings:integrations.guide.heading",{defaultValue:"Setup guide"})}function Si(t){return t.type==="boolean"?t.default===!0:t.multiple?Array.isArray(t.default)?[...t.default]:[]:t.default!==void 0?t.default:""}function Ss(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 qn(t){const r={};for(const o of t.fields){if(o.secret){r[o.key]="";continue}const a=t.values[o.key];r[o.key]=a??Si(o)}return r}function Wn(t,r,o={}){const a=[];for(const n of t)if(n.required){if(n.secret){if(!Ss(n,r[n.key]))continue;o[n.key]?.hasValue||a.push(n.key);continue}Ss(n,r[n.key])&&a.push(n.key)}return a}function Ai(t,r,o){const a={enabled:o};for(const n of t.fields){const s=r[n.key];if(n.secret){if(Ss(n,s))continue;a[n.key]=s;continue}s!==void 0&&(a[n.key]=s)}return a}function Pi(t){return t.filter(r=>r.required||r.type==="agent")}function Mi(t){return t.filter(r=>!(r.required||r.type==="agent"))}function Vr(t){return Array.isArray(t)?`[${t.map(Vr).join(",")}]`:t&&typeof t=="object"?`{${Object.entries(t).filter(([,o])=>o!==void 0).sort(([o],[a])=>o<a?-1:o>a?1:0).map(([o,a])=>`${JSON.stringify(o)}:${Vr(a)}`).join(",")}}`:JSON.stringify(t)??"null"}function Ti(t){return Vr({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 Ei(t){const r=t.ok===!0||t.success===!0;return{ok:r,text:t.message??t.error??(r?"OK":"Failed"),code:t.code}}function Ri(t){return t?.status==="awaiting_reply"||t?.status==="awaiting_inbound"}function Li(t,r=!1){return t.hasConfig?t.enabled?t.lastVerifiedAt||r?"verified":"unverified":"off":"unconfigured"}function Ii(t){return{id:"",platform:t.id,label:"",enabled:!0,connected:!1,hasConfig:!1,capabilities:t.capabilities,fields:t.fields,values:{},secrets:Bi(t.fields),agentId:null,notifyAgentId:null,channels:[],lastError:null,canListChannels:!1,lastVerifiedAt:null}}function Bi(t){const r={};for(const o of t)o.secret&&(r[o.key]={hasValue:!1});return r}function Oi(t){return t.id===""}function Gn(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 ur(t,r){return t.find(o=>o.nativeId===r)}function Jn(t,r,o,a){const n=t.filter(s=>s.nativeId!==r);return n.push({nativeId:r,kind:a??null,agentId:o}),n.sort((s,c)=>s.nativeId.localeCompare(c.nativeId))}function Yn(t,r){return t.filter(o=>o.nativeId!==r)}function Di(t,r){const o=new Set(r.map(a=>a.id));return t.filter(a=>!o.has(a.nativeId))}function $i(t,r){const o=r.trim().toLowerCase();return o?t.filter(a=>a.name.toLowerCase().includes(o)||a.id.toLowerCase().includes(o)):t}function Vi(t){const r=new Map;for(const o of t){const a=r.get(o.platform);a?a.push(o):r.set(o.platform,[o])}return[...r.entries()].map(([o,a])=>({platform:o,instances:a}))}function _i(t,r,o={}){const a=o.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 Fi(t,r,o){const[a,n]=i.useState([]),[s,c]=i.useState(null),[d,u]=i.useState(!1),h=i.useRef(t);h.current=t;const x=i.useRef(0),k=i.useCallback(()=>{if(!o||!r)return;const v=++x.current;u(!0),h.current(r).then(y=>{v===x.current&&(n(y.channels??[]),c(y.error??null))}).catch(y=>{v===x.current&&(n([]),c(y instanceof Error?y.message:String(y)))}).finally(()=>{v===x.current&&u(!1)})},[o,r]);return i.useEffect(()=>(k(),()=>{x.current+=1}),[k]),{channels:a,error:s,loading:d,reloadChannels:k}}const Ha=/^notify[A-Z]/,za="notifyEnabled";function Ui(t){return t.find(r=>r.key===za)}function Ki(t){return t.notifyTarget==="chat"||t.notifyTarget==="user"||Ha.test(t.key)}function Ht(t){return t.filter(r=>r.notifyTarget==="chat"||r.notifyTarget==="user")}function Hi(t){return t.filter(r=>!r.notifyTarget&&!r.secret&&r.key!==za&&Ha.test(r.key))}function zi(t){return t.filter(Ki)}function qa(t){return Ht(t).find(r=>r.notifyTarget==="chat")}function qi(t,r){const o=Ht(t);return o.length===0?"unsupported":o.some(a=>!Ss(a,r[a.key]))?"configured":"not-configured"}function Qn(t){return typeof t=="string"?{value:t,label:t}:{value:t.value,label:t.label??t.value,hint:t.hint}}function Zn(t,r,o){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(o)||n.startsWith(o))return 0;const c=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[\\s./:_-])${c}`).test(a)?1:2}function Wa({value:t,options:r,onChange:o,placeholder:a,filterPlaceholder:n,emptyText:s,customHint:c,disabled:d,ariaLabel:u,className:h}){const[x,k]=i.useState(!1),[v,y]=i.useState(""),[S,N]=i.useState(!1),[j,p]=i.useState(-1),A=i.useRef(null),m=i.useRef(null),w=i.useRef(null),$=i.useRef(null),B=i.useId(),[I,V]=i.useState({}),C=i.useMemo(()=>t?r.map(Qn).find(D=>D.value===t)?.label??t:a??"",[t,r,a]);i.useEffect(()=>{x||(y(C),N(!1))},[C,x]),i.useEffect(()=>{function D(_){const ee=_.target;$.current?.contains(ee)||A.current&&!A.current.contains(ee)&&k(!1)}return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);function M(){const D=m.current;if(!D)return;const _=D.getBoundingClientRect(),ee=Math.max(_.width,240),ue=window.innerHeight-_.bottom-8,le=ue<180&&_.top>ue;V({position:"fixed",left:_.left,width:ee,maxHeight:Math.min(260,le?Math.max(_.top-12,120):ue),...le?{bottom:window.innerHeight-_.top+4}:{top:_.bottom+4}})}i.useLayoutEffect(()=>{if(!x)return;M();const D=()=>M();return window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[x]);const O=i.useMemo(()=>{const D=r.map(Qn),_=v.trim(),ee=S?_.toLowerCase().split(/\s+/).filter(Boolean):[],ue=[];D.forEach((g,T)=>{const f=ee.length?Zn(g,ee,_.toLowerCase()):0;f!==null&&ue.push({row:g,score:f,idx:T})}),ue.sort((g,T)=>g.score-T.score||g.idx-T.idx);const le=[];if(a!==void 0){const g={value:"",label:a};(ee.length?Zn(g,ee,_.toLowerCase()):0)!==null&&le.push(g)}le.push(...ue.map(g=>g.row));const te=_&&!D.some(g=>g.value.toLowerCase()===_.toLowerCase());return c&&S&&te&&le.push({value:_,label:_,custom:!0}),le},[r,v,S,a,c]);i.useEffect(()=>{if(!x||j<0||!w.current)return;w.current.querySelector(`[data-index="${j}"]`)?.scrollIntoView({block:"nearest"})},[j,x,O.length]);function L(){d||(y(C),N(!1),p(O.findIndex(D=>D.value===t)),k(!0),requestAnimationFrame(()=>m.current?.select()))}function U(){k(!1),y(C),N(!1),p(-1)}function H(D){o(D.value),k(!1),y(D.value?D.label:a??""),N(!1),p(-1),m.current?.focus()}function J(D){if(D.key==="ArrowDown"||D.key==="ArrowUp"){if(D.preventDefault(),!x){L();return}p(_=>{const ee=D.key==="ArrowDown"?_+1:_-1;return Math.max(-1,Math.min(ee,O.length-1))});return}if(D.key==="Enter"){if(!x){D.preventDefault(),L();return}const _=O[j];_?(D.preventDefault(),H(_)):U();return}if(D.key==="Escape"&&x){D.preventDefault(),D.stopPropagation(),U();return}D.key==="Tab"&&x&&U()}return e.jsxs("div",{ref:A,className:`relative ${h??""}`,children:[e.jsx("input",{ref:m,type:"text",role:"combobox","aria-expanded":x,"aria-controls":x?B:void 0,"aria-autocomplete":"list","aria-label":u,"aria-activedescendant":x&&j>=0?`${B}-opt-${j}`:void 0,disabled:d,value:x?v:C,placeholder:n,onMouseDown:()=>{x?k(!1):L()},onChange:D=>{x||k(!0),y(D.target.value),N(!0),p(0)},onKeyDown:J,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&&$o.createPortal(e.jsxs("div",{id:B,role:"listbox",ref:D=>{w.current=D,$.current=D},style:I,onMouseDown:D=>D.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:[O.map((D,_)=>e.jsxs("div",{id:`${B}-opt-${_}`,"data-index":_,role:"option","aria-selected":D.value===t,onMouseDown:ee=>{ee.preventDefault(),H(D)},className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${_===j?"bg-brand-500/20":D.value===t?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,children:[e.jsx("span",{className:`flex-1 truncate ${D.custom?"text-brand-500":"text-fg-primary"}`,children:D.label}),D.hint&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:D.hint}),D.custom&&c&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:typeof c=="function"?c(D.value):c})]},`${D.custom?"custom:":""}${D.value}`)),O.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:s})]}),document.body)]})}async function Wi(){const{agents:t}=await F.agents.list({lean:!0});return t.map(r=>({id:r.id,name:r.name,role:r.role}))}let hs=null;function Ga(){return hs||(hs=Wi().catch(t=>{throw hs=null,t})),hs}function Gi(t=Ga,r=!0){const[o,a]=i.useState([]);return i.useEffect(()=>{if(!r)return;let n=!0;return t().then(s=>{n&&a(s)}).catch(()=>{n&&a([])}),()=>{n=!1}},[t,r]),o}function As({value:t,options:r,onChange:o,fieldKey:a,ariaLabel:n,disabled:s}){const{t:c}=xe(["settings"]);return e.jsx(Wa,{value:typeof t=="string"?t:"",options:r.map(d=>({value:d.id,label:d.name,hint:d.role})),onChange:d=>o(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 Ja({loading:t,error:r,onReload:o,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:o,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 ks="rounded-xl border border-border-default bg-surface-secondary p-4",Vt="text-sm font-semibold text-fg-primary",Ya="flex flex-wrap items-center justify-between gap-x-4 gap-y-2",Ji="flex flex-wrap items-start justify-between gap-x-4 gap-y-2",_r="shrink-0 text-sm text-fg-secondary",Qa="flex-1 min-w-[10rem] flex justify-end",vt="text-xs text-fg-tertiary",Fr="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 Ur(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 Yi={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"},Qi={verified:"bg-green-500",unverified:"bg-amber-400",off:"bg-gray-400",unconfigured:"bg-gray-400"},Zi={verified:"settings:integrations.status.verified",unverified:"settings:integrations.status.unverified",off:"settings:integrations.status.off",unconfigured:"settings:integrations.status.unconfigured"},Xi={verified:"Connected",unverified:"Not verified",off:"Off",unconfigured:"Not configured"};function el({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 ${Yi[t]}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qi[t]}`}),r(Zi[t],{defaultValue:Xi[t]})]})}function Ft({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 It({label:t,control:r,help:o,htmlFor:a,start:n=!1}){return e.jsxs("div",{children:[e.jsxs("div",{className:n?Ji:Ya,children:[a?e.jsx("label",{htmlFor:a,className:_r,children:t}):e.jsx("span",{className:_r,children:t}),e.jsx("div",{className:Qa,children:r})]}),o?e.jsx("p",{className:`${vt} mt-1.5`,children:o}):null]})}function tl({field:t,value:r,hasStored:o,onChange:a,platformId:n="",agentOptions:s=[]}){const{t:c}=xe(["settings"]),d=`integration-field-${t.key}`,[u,h]=i.useState(!1),x=i.useMemo(()=>n?Ka(c,n,t):{label:t.label,help:t.help,placeholder:t.placeholder,options:t.options},[c,n,t]),k=x.label,v=x.help,y=x.placeholder,S=x.options??t.options??[],N=e.jsxs(e.Fragment,{children:[k,t.required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),j=t.secret&&o?c("settings:integrations.secretStored"):v||void 0;if(t.type==="boolean"){const m=r===!0;return e.jsx(It,{label:k,help:v,control:e.jsx(Ut,{checked:m,onChange:w=>a(t.key,w),label:k,size:"md",testId:`integration-field-${t.key}`})})}if(t.type==="agent")return e.jsx(It,{label:N,help:j,control:e.jsx("div",{className:"w-full","data-testid":`integration-field-${t.key}`,children:e.jsx(As,{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(It,{start:!0,label:N,help:j,control:e.jsx("div",{className:"flex flex-wrap justify-end gap-1.5","data-testid":`integration-field-${t.key}`,children:S.map(w=>{const $=m.includes(w.value);return e.jsx("button",{type:"button","aria-pressed":$,"data-option":w.value,onClick:()=>a(t.key,$?m.filter(B=>B!==w.value):[...m,w.value]),className:Ur($),children:w.label},w.value)})})})}if(t.type==="select")return e.jsx(It,{label:N,help:j,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:Fr,children:(t.options??[]).map(m=>{const w=S.find($=>$.value===m.value)?.label??m.label;return e.jsx("option",{value:m.value,children:w},m.value)})})});const p=t.type==="password",A=t.type==="number";return e.jsx(It,{label:N,help:j,htmlFor:d,control:e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{id:d,"data-testid":`integration-field-${t.key}`,type:A?"number":p&&!u?"password":"text",value:r==null?"":String(r),placeholder:p&&o?c("settings:integrations.secretStoredPlaceholder"):y,onChange:m=>a(t.key,m.target.value),className:`${Fr}${p?" font-mono pr-10":""}`}),p&&e.jsx("button",{type:"button","aria-label":u?c("settings:integrations.hide",{defaultValue:"Hide"}):c("settings:integrations.show",{defaultValue:"Show"}),onClick:()=>h(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 jt({status:t,draft:r,fields:o=t.fields,onChange:a,agentOptions:n=[]}){return e.jsx(e.Fragment,{children:o.map(s=>e.jsx(tl,{field:s,platformId:t.id,value:r[s.key],hasStored:t.secrets[s.key]?.hasValue===!0,agentOptions:n,onChange:a},s.key))})}const Xn={pending:"bg-amber-400 animate-pulse",ok:"bg-emerald-500",failed:"bg-red-500"};function ea({label:t,hint:r,leg:o}){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 ${Xn[o.state]??Xn.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:o.state==="ok"?o.detail??a("integrations.connectionTest.legOk",{defaultValue:"Verified"}):o.state==="failed"?o.detail??a("integrations.connectionTest.legFailed",{defaultValue:"Failed"}):r})]})]})}function sl(t,r){const o=new Date(t);return Number.isNaN(o.getTime())?t:o.toLocaleString(r,{dateStyle:"medium",timeStyle:"short"})}function rl({test:t,starting:r,onStart:o,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(ea,{label:n("integrations.connectionTest.outbound",{defaultValue:"Outbound (bot → IM)"}),hint:n("integrations.connectionTest.outboundPending",{defaultValue:"Not sent yet"}),leg:t.outbound}),e.jsx(ea,{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(Ft,{type:t.status==="verified"?"ok":"err",text:c}):e.jsx("div",{className:"px-3 py-2 rounded-lg text-xs bg-surface-elevated text-fg-secondary",children:c}))]}):a?e.jsx(Ft,{type:"ok",text:n("integrations.connectionTest.lastVerified",{defaultValue:"Verified {{when}}.",when:sl(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:o,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-elevated 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 nl({status:t,values:r,setValue:o,channels:a=[],canListChannels:n=!1,channelsLoading:s=!1,channelsError:c=null,onReloadChannels:d=()=>{},channelsGuidance:u=null,testSlot:h}){const{t:x}=xe(["settings","common"]),[k,v]=i.useState(!1),y=Ht(t.fields),S=Hi(t.fields),N=Ui(t.fields),j=qi(t.fields,r),p=qa(t.fields),A=N?r[N.key]!==!1:!0,m=n&&p?p.key:null,w=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"})},B={configured:"text-green-600","not-configured":"text-amber-600",unsupported:"text-fg-tertiary"},I={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&&w!==""&&!a.some(L=>L.id===w),O="text-xs font-medium text-fg-secondary mb-2";return e.jsxs("section",{"data-testid":"notification-panel","data-reachability":j,className:ks,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsx("h3",{className:Vt,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 ${B[j]}`,"data-testid":"notification-reachability","data-state":j,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${I[j]}`}),$[j]]}),N&&e.jsx(Ut,{checked:A,onChange:L=>o(N.key,L),label:x("settings:instances.notify.masterLabel",{defaultValue:"Enable notifications"}),size:"md",testId:`integration-field-${N.key}`})]})]}),e.jsxs("div",{className:`space-y-4${A?"":" opacity-60"}`,children:[y.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:O,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(Ja,{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":w===L.id,"data-testid":`notification-chat-pick-${L.id}`,onClick:()=>o(m,L.id),className:Ur(w===L.id),children:L.name},L.id))}),a.length===0&&!s&&!c&&e.jsx("p",{"data-testid":"notification-chat-empty",className:vt,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:()=>o(m,w),className:Ur(!0),children:w})})]}),m===null&&e.jsx("p",{"data-testid":"notification-chat-guidance",className:vt,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:()=>v(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(jt,{status:t,draft:r,fields:y,onChange:o})})]}):e.jsx("div",{className:"mt-2",children:e.jsx(jt,{status:t,draft:r,fields:y,onChange:o})})]}),S.length>0&&e.jsxs("div",{"data-testid":"notification-preferences",className:"space-y-3",children:[e.jsx("div",{className:O,children:x("settings:instances.notify.content",{defaultValue:"What to send"})}),e.jsx(jt,{status:t,draft:r,fields:S,onChange:o})]}),h]})]})}const yt={fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round"},al={color:"#64748b",glyph:e.jsx("g",{...yt,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"})})},ol={feishu:{color:"#3370ff",glyph:e.jsx("g",{...yt,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",{...yt,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",{...yt,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",{...yt,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",{...yt,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 il(t){return ol[t]??al}function Za({id:t,size:r=36}){const o=il(t);return e.jsx("span",{className:"shrink-0 inline-flex items-center justify-center rounded-lg",style:{width:r,height:r,backgroundColor:`${o.color}1a`,color:o.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:o.glyph})})}function ll({status:t,configured:r,canListChannels:o=!1,channelsGuidance:a=null}){const{t:n,i18n:s}=xe(["settings","common"]),[c,d]=i.useState(!r),u=i.useMemo(()=>{const k=ki(s,n,t.id);if(Ht(t.fields).length===0)return k;const v=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."}),y=o?{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:v}):v};return[...k,y]},[s,n,t.id,t.fields,o,a]),h=Ni(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:Ci(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,v)=>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:v+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:[h&&e.jsxs("a",{href:h,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-on-brand 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 Xa={create:(t,r)=>F.settings.createInstance(t,r).then(o=>o.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(o=>o.test),getConnectionTest:t=>F.settings.getConnectionTest(t).then(r=>r.test)},dl=700;function ta({instance:t,client:r=Xa,extras:o={},onChanged:a,onCreated:n,loadAgents:s,defaultExpanded:c}){const{t:d}=xe(["settings","common"]),u=Oi(t),[h,x]=i.useState(c??u),[k,v]=i.useState(!1),y=i.useMemo(()=>Gn(t),[t]),[S,N]=i.useState(t.label),[j,p]=i.useState(()=>qn(y)),[A,m]=i.useState(t.enabled),[w,$]=i.useState(t.channels),[B,I]=i.useState(typeof t.notifyAgentId=="string"?t.notifyAgentId:""),[V,C]=i.useState({kind:"idle"}),M=!!o[t.platform]?.guidedSetup,[O,L]=i.useState(M&&!t.hasConfig?"guided":"manual"),U=M&&O==="guided",{channels:H,error:J,loading:D,reloadChannels:_}=Fi(r.listChannels,t.id,h&&t.canListChannels),[ee,ue]=i.useState(""),[le,te]=i.useState(null),[g,T]=i.useState(!1),[f,K]=i.useState(null),q=Ri(le),[ne,oe]=i.useState(!1),ge=t.fields.some(E=>E.type==="agent"),se=Gi(i.useMemo(()=>s??Ga,[s]),ge),Je=i.useCallback(E=>E?se.find(ae=>ae.id===E)?.name??E:"",[se]),Ae=Ti(y),Se=i.useRef(t);Se.current=t;const Oe=i.useRef(!1),rt=i.useRef(!1);i.useEffect(()=>{if(Oe.current)return;const E=Se.current;N(E.label),p(qn(Gn(E))),m(E.enabled),$(E.channels),I(typeof E.notifyAgentId=="string"?E.notifyAgentId:"")},[Ae]),i.useEffect(()=>{C({kind:"idle"}),te(null),K(null),it(!1)},[t.id]),i.useEffect(()=>{L(M&&!t.hasConfig?"guided":"manual")},[t.id,t.hasConfig,M]);const we=i.useCallback(()=>{Oe.current=!0,C({kind:"idle"})},[]),fe=i.useCallback((E,ae)=>{we(),p(Z=>({...Z,[E]:ae}))},[we]),zt=i.useCallback(E=>{we(),N(E)},[we]),Ye=i.useCallback(E=>{we(),m(E)},[we]),Nt=i.useRef(()=>Promise.resolve()),De=i.useCallback(async()=>{if(!rt.current){rt.current=!0,C({kind:"saving"});try{let E=Se.current.id;E||(E=(await r.create(Se.current.platform,S.trim())).id),await r.save(E,{...Ai(y,j,A),notifyAgentId:B}),Se.current.canListChannels&&await r.saveChannels(E,w);let ae=null;try{const{ok:Z,text:Ze,code:Xt}=Ei(await r.test(E,{}));!Z&&!/not supported/i.test(Ze)&&(ae=Xt==="network_unreachable"?d("settings:integrations.savedNotVerifiedNetwork"):d("settings:integrations.savedNotVerified",{reason:Ze}))}catch(Z){ae=d("settings:integrations.savedNotVerified",{reason:String(Z)})}Oe.current=!1,C(ae?{kind:"error",text:ae}:{kind:"saved"}),await a?.(),Se.current.id===""&&n?.(E)}catch(E){C({kind:"error",text:E instanceof Error?E.message:String(E)})}finally{rt.current=!1}}},[r,y,j,A,B,w,S,d,a,n]);Nt.current=De;const nt=Wn(y.fields,j,t.secrets),qt=u&&S.trim()==="",Wt=w.every(E=>E.agentId),Qe=!U&&!qt&&nt.length===0&&Wt,Re=i.useMemo(()=>JSON.stringify([S,A,B,w,j]),[S,A,B,w,j]);i.useEffect(()=>{if(!Oe.current||!Qe)return;const E=setTimeout(()=>{Nt.current()},dl);return()=>clearTimeout(E)},[Re,Qe]),i.useEffect(()=>{if(!h||u)return;let E=!0;return r.getConnectionTest(t.id).then(ae=>{E&&ae&&te(ae)}).catch(()=>{}),()=>{E=!1}},[h,u,r,t.id]),i.useEffect(()=>{if(!h||!q)return;let E=!0;const ae=setInterval(()=>{r.getConnectionTest(t.id).then(Z=>{E&&Z&&te(Z)}).catch(()=>{})},2500);return()=>{E=!1,clearInterval(ae)}},[h,q,r,t.id]);const wt=i.useRef(null);i.useEffect(()=>{le?.status==="verified"&&wt.current!==t.id&&(wt.current=t.id,a?.())},[le?.status,t.id,a]);const Gt=i.useCallback(async()=>{T(!0),K(null);try{te(await r.startConnectionTest(t.id))}catch(E){K(E instanceof Error?E.message:String(E))}finally{T(!1)}},[r,t.id]),ye=o[t.platform],_e=i.useMemo(()=>({platformId:t.platform,instanceId:t.id||void 0,status:y,values:j,setValue:fe,reload:()=>{a?.()},agents:se,onCreated:n,setupMethod:M?O:void 0,setSetupMethod:M?L:void 0}),[t.platform,t.id,y,j,fe,a,se,n,M,O]),Jt=i.useMemo(()=>new Set(ye?.ownedFields??[]),[ye]),at=Ht(y.fields).length>0,Yt=i.useMemo(()=>new Set(at?zi(y.fields).map(E=>E.key):[]),[y.fields,at]),ot=i.useMemo(()=>y.fields.filter(E=>!Jt.has(E.key)&&!Yt.has(E.key)),[y.fields,Jt,Yt]),kt=i.useMemo(()=>Pi(ot),[ot]),Qt=i.useMemo(()=>Mi(ot),[ot]),Zt=i.useMemo(()=>kt.filter(E=>E.type==="agent"),[kt]),Ct=i.useMemo(()=>kt.filter(E=>E.type!=="agent"),[kt]),[Ps,it]=i.useState(!1),Ms=i.useMemo(()=>Wn(t.fields,t.values,t.secrets),[t.fields,t.values,t.secrets]),lt=t.hasConfig&&!Ms.some(E=>Ct.some(ae=>ae.key===E)),dt=i.useMemo(()=>$i(H,ee),[H,ee]),St=i.useMemo(()=>Di(w,H),[w,H]),Fe=w.filter(E=>!E.agentId).length,Ts=i.useCallback((E,ae)=>{we(),$(Z=>ae?Jn(Z,E.id,ur(Z,E.id)?.agentId??t.agentId??"",E.kind??null):Yn(Z,E.id))},[we,t.agentId]),Pe=i.useCallback((E,ae)=>{we(),$(Z=>Jn(Z,E,ae,ur(Z,E)?.kind??null))},[we]),Es=i.useCallback(async()=>{oe(!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=Li(t,le?.status==="verified"),re=t.id||`new-${t.platform}`,ct=`instance-name-${re}`,At=nt.map(E=>{const ae=y.fields.find(Z=>Z.key===E);return ae?Ka(d,t.platform,ae).label:E}).join(", ");return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden border border-border-default","data-testid":`instance-card-${re}`,"data-instance":t.id,"data-platform":t.platform,"data-draft":u?"true":"false","data-expanded":h?"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":h,"data-testid":`instance-toggle-${re}`,className:"flex-1 min-w-0 flex items-center gap-3 text-left",children:[e.jsx(Za,{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-${re}`,children:S.trim()===""?d("settings:instances.newBot",{defaultValue:"New bot"}):S}),!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-${re}`,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-${re}`,title:d("settings:instances.boundAgent",{defaultValue:"Bound agent"}),children:[e.jsx("span",{className:"text-fg-muted",children:"→"}),Je(t.agentId)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(el,{state:Ue}),!u&&e.jsx(Ut,{checked:A,onChange:Ye,size:"md",testId:`instance-enabled-${re}`,label:d("settings:instances.toggleLabel",{defaultValue:"Turn this bot on or off"})}),e.jsx("button",{type:"button",onClick:()=>x(E=>!E),"aria-expanded":h,"data-testid":`instance-chevron-${re}`,className:"p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:e.jsx("svg",{className:`w-4 h-4 transition-transform ${h?"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"})})})]})]}),h&&e.jsxs("div",{className:"px-6 pb-6 pt-5 border-t border-border-default space-y-6",children:[!t.hasConfig&&!U&&e.jsx(ll,{status:y,configured:t.hasConfig,canListChannels:t.canListChannels,channelsGuidance:t.channelsGuidance??null}),!M&&ye?.placement==="before"&&ye.render(_e),e.jsxs("section",{"data-testid":`instance-credentials-${re}`,className:ks,children:[e.jsx("h3",{className:`${Vt} 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":O===E,onClick:()=>L(E),"data-testid":`setup-method-${E}-${re}`,className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${O===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:Ya,children:[e.jsxs("label",{htmlFor:ct,className:_r,children:[d("settings:instances.addBot.name",{defaultValue:"Bot name"}),e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),e.jsx("div",{className:Qa,children:e.jsx("input",{id:ct,"data-testid":`new-bot-name-${t.platform}`,value:S,onChange:E=>zt(E.target.value),placeholder:d("settings:instances.addBot.namePlaceholder",{defaultValue:"e.g. Sales"}),className:Fr})})]}),Zt.length>0&&e.jsx(jt,{status:y,draft:j,fields:Zt,onChange:fe,agentOptions:se}),Ct.length>0&&(lt&&!Ps?e.jsx("div",{"data-testid":`instance-credentials-configured-${re}`,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:()=>it(!0),"data-testid":`instance-credentials-edit-${re}`,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:[lt&&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:()=>it(!1),"data-testid":`instance-credentials-hide-${re}`,className:"text-xs text-brand-600 hover:text-brand-700",children:d("settings:instances.credentialsHide",{defaultValue:"Hide"})})]}),e.jsx(jt,{status:y,draft:j,fields:Ct,onChange:fe,agentOptions:se})]}))]}),e.jsx("div",{className:"mt-3 min-h-[1.25rem]","data-testid":`instance-save-state-${re}`,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-${re}`,children:nt.length>0?d("settings:integrations.missingRequired",{defaultValue:"Required: {{fields}}",fields:At}):d("settings:instances.addBot.labelRequired",{defaultValue:"Give the bot a name."})})]})}),V.kind==="error"&&e.jsx("div",{className:"mt-2",children:e.jsx(Ft,{type:"err",text:V.text})})]}),!u&&e.jsxs("section",{children:[e.jsx(rl,{test:le,starting:g,lastVerifiedAt:t.lastVerifiedAt,onStart:()=>{Gt()}}),f&&e.jsx("div",{className:"mt-3",children:e.jsx(Ft,{type:"err",text:f})})]}),!u&&at&&e.jsx(nl,{status:y,values:j,setValue:fe,channels:H,canListChannels:t.canListChannels,channelsLoading:D,channelsError:J,onReloadChannels:_,channelsGuidance:t.channelsGuidance??null,testSlot:ye?.sendTest?.(_e)}),e.jsxs("section",{"data-testid":`instance-more-${re}`,children:[e.jsxs("button",{type:"button",onClick:()=>v(E=>!E),"aria-expanded":k,"data-testid":`instance-more-toggle-${re}`,className:"w-full flex items-center gap-2 text-left group px-1",children:[e.jsx("span",{className:Vt,children:d("settings:instances.moreSettings",{defaultValue:"Advanced"})}),e.jsx("span",{className:`${vt} 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:[Qt.length>0&&e.jsxs("div",{className:ks,children:[e.jsx("h4",{className:`${Vt} mb-1`,children:d("settings:instances.advancedTitle",{defaultValue:"Platform options"})}),!u&&e.jsx("p",{className:`${vt} 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(jt,{status:y,draft:j,fields:Qt,onChange:fe,agentOptions:se})]}),!u&&e.jsxs("div",{className:ks,children:[e.jsx("h4",{className:`${Vt} mb-1`,children:d("settings:instances.routing.chats",{defaultValue:"Chat routing"})}),e.jsx("p",{className:`${vt} 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-${re}`,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(Ja,{loading:D,error:J,onReload:_,empty:H.length===0,buttonTestId:`instance-chats-refresh-${re}`,errorTestId:`instance-chats-error-${re}`})}),t.canListChannels&&H.length>0&&e.jsx("input",{type:"text",value:ee,onChange:E=>ue(E.target.value),placeholder:d("settings:instances.routing.searchChats",{defaultValue:"Search chats…"}),"data-testid":`instance-chat-search-${re}`,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-${re}`,children:[dt.map(E=>{const ae=ur(w,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:!!ae,"data-testid":`instance-chat-toggle-${re}-${E.id}`,onChange:Z=>Ts(E,Z.target.checked),className:"rounded border-border-default"}),e.jsx("span",{className:"truncate",title:E.id,children:E.name})]}),ae&&e.jsx("div",{className:"w-56","data-testid":`instance-chat-agent-${re}-${E.id}`,children:e.jsx(As,{value:ae.agentId,options:se,onChange:(Z,Ze)=>Pe(E.id,typeof Ze=="string"?Ze:""),fieldKey:"agentId",ariaLabel:d("settings:instances.routing.chatAgent",{defaultValue:"Agent for this chat"})})})]},E.id)}),St.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-${re}-${E.nativeId}`,onChange:()=>$(ae=>Yn(ae,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-${re}-${E.nativeId}`,children:e.jsx(As,{value:E.agentId,options:se,onChange:(ae,Z)=>Pe(E.nativeId,typeof Z=="string"?Z:""),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."})}),Fe>0&&e.jsx("div",{className:"mt-3",children:e.jsx(Ft,{type:"err",text:d("settings:instances.routing.agentRequired",{defaultValue:"Pick an agent for every selected chat ({{count}} still unassigned).",count:Fe})})})]})]})]}),!M&&ye&&ye.placement!=="before"&&ye.render(_e),!u&&e.jsx("div",{className:"pt-1",children:e.jsx("button",{type:"button",onClick:()=>oe(!0),"data-testid":`instance-disconnect-${re}`,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"})})})]}),ne&&e.jsx(Cs,{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:()=>{Es()},onCancel:()=>oe(!1)})]})}var ht={},mr,sa;function cl(){return sa||(sa=1,mr=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),mr}var xr={},We={},ra;function tt(){if(ra)return We;ra=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 We.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},We.getSymbolTotalCodewords=function(a){return r[a]},We.getBCHDigit=function(o){let a=0;for(;o!==0;)a++,o>>>=1;return a},We.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},We.isKanjiModeEnabled=function(){return typeof t<"u"},We.toSJIS=function(a){return t(a)},We}var gr={},na;function qr(){return na||(na=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.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: "+o)}}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}}})(gr)),gr}var fr,aa;function ul(){if(aa)return fr;aa=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(r){const o=Math.floor(r/8);return(this.buffer[o]>>>7-r%8&1)===1},put:function(r,o){for(let a=0;a<o;a++)this.putBit((r>>>o-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),r&&(this.buffer[o]|=128>>>this.length%8),this.length++}},fr=t,fr}var pr,oa;function ml(){if(oa)return pr;oa=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,o,a,n){const s=r*this.size+o;this.data[s]=a,n&&(this.reservedBit[s]=!0)},t.prototype.get=function(r,o){return this.data[r*this.size+o]},t.prototype.xor=function(r,o,a){this.data[r*this.size+o]^=a},t.prototype.isReserved=function(r,o){return this.reservedBit[r*this.size+o]},pr=t,pr}var hr={},ia;function xl(){return ia||(ia=1,(function(t){const r=tt().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}})(hr)),hr}var br={},la;function gl(){if(la)return br;la=1;const t=tt().getSymbolSize,r=7;return br.getPositions=function(a){const n=t(a);return[[0,0],[n-r,0],[0,n-r]]},br}var yr={},da;function fl(){return da||(da=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,h=null,x=null;for(let k=0;k<s;k++){d=u=0,h=x=null;for(let v=0;v<s;v++){let y=n.get(k,v);y===h?d++:(d>=5&&(c+=r.N1+(d-5)),h=y,d=1),y=n.get(v,k),y===x?u++:(u>=5&&(c+=r.N1+(u-5)),x=y,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 h=n.get(d,u)+n.get(d,u+1)+n.get(d+1,u)+n.get(d+1,u+1);(h===4||h===0)&&c++}return c*r.N2},t.getPenaltyN3=function(n){const s=n.size;let c=0,d=0,u=0;for(let h=0;h<s;h++){d=u=0;for(let x=0;x<s;x++)d=d<<1&2047|n.get(h,x),x>=10&&(d===1488||d===93)&&c++,u=u<<1&2047|n.get(x,h),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 o(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,o(n,u,d))},t.getBestMask=function(n,s){const c=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let h=0;h<c;h++){s(h),t.applyMask(h,n);const x=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(h,n),x<u&&(u=x,d=h)}return d}})(yr)),yr}var bs={},ca;function eo(){if(ca)return bs;ca=1;const t=qr(),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],o=[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 bs.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}},bs.getTotalCodewordsCount=function(n,s){switch(s){case t.L:return o[(n-1)*4+0];case t.M:return o[(n-1)*4+1];case t.Q:return o[(n-1)*4+2];case t.H:return o[(n-1)*4+3];default:return}},bs}var vr={},Bt={},ua;function pl(){if(ua)return Bt;ua=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]})(),Bt.log=function(a){if(a<1)throw new Error("log("+a+")");return r[a]},Bt.exp=function(a){return t[a]},Bt.mul=function(a,n){return a===0||n===0?0:t[r[a]+r[n]]},Bt}var ma;function hl(){return ma||(ma=1,(function(t){const r=pl();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}})(vr)),vr}var jr,xa;function bl(){if(xa)return jr;xa=1;const t=hl();function r(o){this.genPoly=void 0,this.degree=o,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},jr=r,jr}var Nr={},wr={},kr={},ga;function to(){return ga||(ga=1,kr.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),kr}var Ie={},fa;function so(){if(fa)return Ie;fa=1;const t="[0-9]+",r="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
2
2
  ]))+`;Ie.KANJI=new RegExp(o,"g"),Ie.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ie.BYTE=new RegExp(a,"g"),Ie.NUMERIC=new RegExp(t,"g"),Ie.ALPHANUMERIC=new RegExp(r,"g");const n=new RegExp("^"+o+"$"),s=new RegExp("^"+t+"$"),c=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ie.testKanji=function(u){return n.test(u)},Ie.testNumeric=function(u){return s.test(u)},Ie.testAlphanumeric=function(u){return c.test(u)},Ie}var pa;function st(){return pa||(pa=1,(function(t){const r=to(),o=so();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 o.testNumeric(s)?t.NUMERIC:o.testAlphanumeric(s)?t.ALPHANUMERIC:o.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}}})(wr)),wr}var ha;function yl(){return ha||(ha=1,(function(t){const r=tt(),o=eo(),a=qr(),n=st(),s=to(),c=7973,d=r.getBCHDigit(c);function u(v,y,S){for(let N=1;N<=40;N++)if(y<=t.getCapacity(N,S,v))return N}function h(v,y){return n.getCharCountIndicator(v,y)+4}function x(v,y){let S=0;return v.forEach(function(N){const j=h(N.mode,y);S+=j+N.getBitsLength()}),S}function k(v,y){for(let S=1;S<=40;S++)if(x(v,S)<=t.getCapacity(S,y,n.MIXED))return S}t.from=function(y,S){return s.isValid(y)?parseInt(y,10):S},t.getCapacity=function(y,S,N){if(!s.isValid(y))throw new Error("Invalid QR Code version");typeof N>"u"&&(N=n.BYTE);const j=r.getSymbolTotalCodewords(y),p=o.getTotalCodewordsCount(y,S),A=(j-p)*8;if(N===n.MIXED)return A;const m=A-h(N,y);switch(N){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(y,S){let N;const j=a.from(S,a.M);if(Array.isArray(y)){if(y.length>1)return k(y,j);if(y.length===0)return 1;N=y[0]}else N=y;return u(N.mode,N.getLength(),j)},t.getEncodedBits=function(y){if(!s.isValid(y)||y<7)throw new Error("Invalid QR Code version");let S=y<<12;for(;r.getBCHDigit(S)-d>=0;)S^=c<<r.getBCHDigit(S)-d;return y<<12|S}})(Nr)),Nr}var Cr={},ba;function vl(){if(ba)return Cr;ba=1;const t=tt(),r=1335,o=21522,a=t.getBCHDigit(r);return Cr.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)^o},Cr}var Sr={},Ar,ya;function jl(){if(ya)return Ar;ya=1;const t=st();function r(o){this.mode=t.NUMERIC,this.data=o.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))},Ar=r,Ar}var Pr,va;function Nl(){if(va)return Pr;va=1;const t=st(),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 o(a){this.mode=t.ALPHANUMERIC,this.data=a}return o.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.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)},Pr=o,Pr}var Mr,ja;function wl(){if(ja)return Mr;ja=1;const t=st();function r(o){this.mode=t.BYTE,typeof o=="string"?this.data=new TextEncoder().encode(o):this.data=new Uint8Array(o)}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(o){for(let a=0,n=this.data.length;a<n;a++)o.put(this.data[a],8)},Mr=r,Mr}var Tr,Na;function kl(){if(Na)return Tr;Na=1;const t=st(),r=tt();function o(a){this.mode=t.KANJI,this.data=a}return o.getBitsLength=function(n){return n*13},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.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)}},Tr=o,Tr}var Er={exports:{}},wa;function Cl(){return wa||(wa=1,(function(t){var r={single_source_shortest_paths:function(o,a,n){var s={},c={};c[a]=0;var d=r.PriorityQueue.make();d.push(a,0);for(var u,h,x,k,v,y,S,N,j;!d.empty();){u=d.pop(),h=u.value,k=u.cost,v=o[h]||{};for(x in v)v.hasOwnProperty(x)&&(y=v[x],S=k+y,N=c[x],j=typeof c[x]>"u",(j||N>S)&&(c[x]=S,d.push(x,S),s[x]=h))}if(typeof n<"u"&&typeof c[n]>"u"){var p=["Could not find a path from ",a," to ",n,"."].join("");throw new Error(p)}return s},extract_shortest_path_from_predecessor_list:function(o,a){for(var n=[],s=a;s;)n.push(s),o[s],s=o[s];return n.reverse(),n},find_path:function(o,a,n){var s=r.single_source_shortest_paths(o,a,n);return r.extract_shortest_path_from_predecessor_list(s,n)},PriorityQueue:{make:function(o){var a=r.PriorityQueue,n={},s;o=o||{};for(s in a)a.hasOwnProperty(s)&&(n[s]=a[s]);return n.queue=[],n.sorter=o.sorter||a.default_sorter,n},default_sorter:function(o,a){return o.cost-a.cost},push:function(o,a){var n={value:o,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})(Er)),Er.exports}var ka;function Sl(){return ka||(ka=1,(function(t){const r=st(),o=jl(),a=Nl(),n=wl(),s=kl(),c=so(),d=tt(),u=Cl();function h(p){return unescape(encodeURIComponent(p)).length}function x(p,A,m){const w=[];let $;for(;($=p.exec(m))!==null;)w.push({data:$[0],index:$.index,mode:A,length:$[0].length});return w}function k(p){const A=x(c.NUMERIC,r.NUMERIC,p),m=x(c.ALPHANUMERIC,r.ALPHANUMERIC,p);let w,$;return d.isKanjiModeEnabled()?(w=x(c.BYTE,r.BYTE,p),$=x(c.KANJI,r.KANJI,p)):(w=x(c.BYTE_KANJI,r.BYTE,p),$=[]),A.concat(m,w,$).sort(function(I,V){return I.index-V.index}).map(function(I){return{data:I.data,mode:I.mode,length:I.length}})}function v(p,A){switch(A){case r.NUMERIC:return o.getBitsLength(p);case r.ALPHANUMERIC:return a.getBitsLength(p);case r.KANJI:return s.getBitsLength(p);case r.BYTE:return n.getBitsLength(p)}}function y(p){return p.reduce(function(A,m){const w=A.length-1>=0?A[A.length-1]:null;return w&&w.mode===m.mode?(A[A.length-1].data+=m.data,A):(A.push(m),A)},[])}function S(p){const A=[];for(let m=0;m<p.length;m++){const w=p[m];switch(w.mode){case r.NUMERIC:A.push([w,{data:w.data,mode:r.ALPHANUMERIC,length:w.length},{data:w.data,mode:r.BYTE,length:w.length}]);break;case r.ALPHANUMERIC:A.push([w,{data:w.data,mode:r.BYTE,length:w.length}]);break;case r.KANJI:A.push([w,{data:w.data,mode:r.BYTE,length:h(w.data)}]);break;case r.BYTE:A.push([{data:w.data,mode:r.BYTE,length:h(w.data)}])}}return A}function N(p,A){const m={},w={start:{}};let $=["start"];for(let B=0;B<p.length;B++){const I=p[B],V=[];for(let C=0;C<I.length;C++){const M=I[C],O=""+B+C;V.push(O),m[O]={node:M,lastCount:0},w[O]={};for(let L=0;L<$.length;L++){const U=$[L];m[U]&&m[U].node.mode===M.mode?(w[U][O]=v(m[U].lastCount+M.length,M.mode)-v(m[U].lastCount,M.mode),m[U].lastCount+=M.length):(m[U]&&(m[U].lastCount=M.length),w[U][O]=v(M.length,M.mode)+4+r.getCharCountIndicator(M.mode,A))}}$=V}for(let B=0;B<$.length;B++)w[$[B]].end=0;return{map:w,table:m}}function j(p,A){let m;const w=r.getBestModeForData(p);if(m=r.from(A,w),m!==r.BYTE&&m.bit<w.bit)throw new Error('"'+p+'" cannot be encoded with mode '+r.toString(m)+`.
4
4
  Suggested mode is: `+r.toString(w));switch(m===r.KANJI&&!d.isKanjiModeEnabled()&&(m=r.BYTE),m){case r.NUMERIC:return new o(p);case r.ALPHANUMERIC:return new a(p);case r.KANJI:return new s(p);case r.BYTE:return new n(p)}}t.fromArray=function(A){return A.reduce(function(m,w){return typeof w=="string"?m.push(j(w,null)):w.data&&m.push(j(w.data,w.mode)),m},[])},t.fromString=function(A,m){const w=k(A,d.isKanjiModeEnabled()),$=S(w),B=N($,m),I=u.find_path(B.map,"start","end"),V=[];for(let C=1;C<I.length-1;C++)V.push(B.table[I[C]].node);return t.fromArray(y(V))},t.rawSplit=function(A){return t.fromArray(k(A,d.isKanjiModeEnabled()))}})(Sr)),Sr}var Ca;function Al(){if(Ca)return xr;Ca=1;const t=tt(),r=qr(),o=ul(),a=ml(),n=xl(),s=gl(),c=fl(),d=eo(),u=bl(),h=yl(),x=vl(),k=st(),v=Sl();function y(B,I){const V=B.size,C=s.getPositions(I);for(let M=0;M<C.length;M++){const O=C[M][0],L=C[M][1];for(let U=-1;U<=7;U++)if(!(O+U<=-1||V<=O+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?B.set(O+U,L+H,!0,!0):B.set(O+U,L+H,!1,!0))}}function S(B){const I=B.size;for(let V=8;V<I-8;V++){const C=V%2===0;B.set(V,6,C,!0),B.set(6,V,C,!0)}}function N(B,I){const V=n.getPositions(I);for(let C=0;C<V.length;C++){const M=V[C][0],O=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?B.set(M+L,O+U,!0,!0):B.set(M+L,O+U,!1,!0)}}function j(B,I){const V=B.size,C=h.getEncodedBits(I);let M,O,L;for(let U=0;U<18;U++)M=Math.floor(U/3),O=U%3+V-8-3,L=(C>>U&1)===1,B.set(M,O,L,!0),B.set(O,M,L,!0)}function p(B,I,V){const C=B.size,M=x.getEncodedBits(I,V);let O,L;for(O=0;O<15;O++)L=(M>>O&1)===1,O<6?B.set(O,8,L,!0):O<8?B.set(O+1,8,L,!0):B.set(C-15+O,8,L,!0),O<8?B.set(8,C-O-1,L,!0):O<9?B.set(8,15-O-1+1,L,!0):B.set(8,15-O-1,L,!0);B.set(C-8,8,1,!0)}function A(B,I){const V=B.size;let C=-1,M=V-1,O=7,L=0;for(let U=V-1;U>0;U-=2)for(U===6&&U--;;){for(let H=0;H<2;H++)if(!B.isReserved(M,U-H)){let J=!1;L<I.length&&(J=(I[L]>>>O&1)===1),B.set(M,U-H,J),O--,O===-1&&(L++,O=7)}if(M+=C,M<0||V<=M){M-=C,C=-C;break}}}function m(B,I,V){const C=new o;V.forEach(function(H){C.put(H.mode.bit,4),C.put(H.getLength(),k.getCharCountIndicator(H.mode,B)),H.write(C)});const M=t.getSymbolTotalCodewords(B),O=d.getTotalCodewordsCount(B,I),L=(M-O)*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 w(C,B,I)}function w(B,I,V){const C=t.getSymbolTotalCodewords(I),M=d.getTotalCodewordsCount(I,V),O=C-M,L=d.getBlocksCount(I,V),U=C%L,H=L-U,J=Math.floor(C/L),D=Math.floor(O/L),_=D+1,ee=J-D,ue=new u(ee);let le=0;const te=new Array(L),g=new Array(L);let T=0;const f=new Uint8Array(B.buffer);for(let ge=0;ge<L;ge++){const se=ge<H?D:_;te[ge]=f.slice(le,le+se),g[ge]=ue.encode(te[ge]),le+=se,T=Math.max(T,se)}const K=new Uint8Array(C);let q=0,ne,oe;for(ne=0;ne<T;ne++)for(oe=0;oe<L;oe++)ne<te[oe].length&&(K[q++]=te[oe][ne]);for(ne=0;ne<ee;ne++)for(oe=0;oe<L;oe++)K[q++]=g[oe][ne];return K}function $(B,I,V,C){let M;if(Array.isArray(B))M=v.fromArray(B);else if(typeof B=="string"){let J=I;if(!J){const D=v.rawSplit(B);J=h.getBestVersionForData(D,V)}M=v.fromString(B,J||40)}else throw new Error("Invalid data");const O=h.getBestVersionForData(M,V);if(!O)throw new Error("The amount of data is too big to be stored in a QR Code");if(!I)I=O;else if(I<O)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-BdiEUYQB.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-on-brand 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
+ 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-BHu6brRf.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-on-brand 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-BdiEUYQB.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};
1
+ import{j as a}from"./index-BHu6brRf.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};