botmux 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/cli/pi.d.ts.map +1 -1
- package/dist/adapters/cli/pi.js +4 -0
- package/dist/adapters/cli/pi.js.map +1 -1
- package/dist/adapters/cli/types.d.ts +8 -1
- package/dist/adapters/cli/types.d.ts.map +1 -1
- package/dist/cli/deferred-topic-send.d.ts +37 -0
- package/dist/cli/deferred-topic-send.d.ts.map +1 -0
- package/dist/cli/deferred-topic-send.js +69 -0
- package/dist/cli/deferred-topic-send.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +160 -34
- package/dist/cli.js.map +1 -1
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +17 -12
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/dashboard-ipc-server.d.ts +4 -1
- package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
- package/dist/core/dashboard-ipc-server.js +78 -8
- package/dist/core/dashboard-ipc-server.js.map +1 -1
- package/dist/core/deferred-schedule-settlement.d.ts +20 -0
- package/dist/core/deferred-schedule-settlement.d.ts.map +1 -0
- package/dist/core/deferred-schedule-settlement.js +18 -0
- package/dist/core/deferred-schedule-settlement.js.map +1 -0
- package/dist/core/deferred-topic-binding.d.ts +19 -0
- package/dist/core/deferred-topic-binding.d.ts.map +1 -0
- package/dist/core/deferred-topic-binding.js +55 -0
- package/dist/core/deferred-topic-binding.js.map +1 -0
- package/dist/core/scheduler.d.ts +26 -20
- package/dist/core/scheduler.d.ts.map +1 -1
- package/dist/core/scheduler.js +114 -56
- package/dist/core/scheduler.js.map +1 -1
- package/dist/core/session-discovery.d.ts.map +1 -1
- package/dist/core/session-discovery.js +47 -15
- package/dist/core/session-discovery.js.map +1 -1
- package/dist/core/session-manager.d.ts +17 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +178 -84
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/types.d.ts +4 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/worker-pool.d.ts +7 -0
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/core/worker-pool.js +51 -1
- package/dist/core/worker-pool.js.map +1 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +90 -5
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/schedule-card-model.d.ts +12 -3
- package/dist/dashboard/schedule-card-model.d.ts.map +1 -1
- package/dist/dashboard/schedule-card-model.js +32 -8
- package/dist/dashboard/schedule-card-model.js.map +1 -1
- package/dist/dashboard/web/dashboard-components.d.ts +7 -0
- package/dist/dashboard/web/dashboard-components.d.ts.map +1 -1
- package/dist/dashboard/web/dashboard-components.js +11 -2
- package/dist/dashboard/web/dashboard-components.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +30 -6
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/web/schedules-page.d.ts +2 -0
- package/dist/dashboard/web/schedules-page.d.ts.map +1 -1
- package/dist/dashboard/web/schedules-page.js +74 -27
- package/dist/dashboard/web/schedules-page.js.map +1 -1
- package/dist/dashboard-web/app.js +1 -1
- package/dist/dashboard-web/chunks/{bot-defaults-page-O37SAQD5.js → bot-defaults-page-B5AY4B2J.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-6QHMLMIM.js → chunk-CUV65BIQ.js} +3 -3
- package/dist/dashboard-web/chunks/{chunk-O2DPQL7C.js → chunk-JNRSPKLS.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-FYALHCPG.js → chunk-P6GO5KT4.js} +1 -1
- package/dist/dashboard-web/chunks/chunk-QFMH6ITB.js +1 -0
- package/dist/dashboard-web/chunks/{chunk-B42PCL5P.js → chunk-UBOLHQCK.js} +1 -1
- package/dist/dashboard-web/chunks/{connectors-page-DZBQ42MH.js → connectors-page-KTC2QWNW.js} +1 -1
- package/dist/dashboard-web/chunks/{groups-page-3IEGRZKQ.js → groups-page-B3EKGOLY.js} +1 -1
- package/dist/dashboard-web/chunks/{insights-page-X3ADRON3.js → insights-page-X6RXNCWX.js} +1 -1
- package/dist/dashboard-web/chunks/{monitor-room-IV36RGQY.js → monitor-room-LLRA5LQW.js} +1 -1
- package/dist/dashboard-web/chunks/{monitoring-page-ADFKVON4.js → monitoring-page-7MT5FEOS.js} +1 -1
- package/dist/dashboard-web/chunks/{office-page-CALAOWNS.js → office-page-KD46D5TD.js} +1 -1
- package/dist/dashboard-web/chunks/{overview-page-SLMGLK3M.js → overview-page-JUWNH32O.js} +1 -1
- package/dist/dashboard-web/chunks/{roles-page-L7JJ4FFV.js → roles-page-P6F7NLOI.js} +1 -1
- package/dist/dashboard-web/chunks/schedules-page-XIHWZST4.js +1 -0
- package/dist/dashboard-web/chunks/{sessions-page-OKJ5YWUZ.js → sessions-page-2VECQ27T.js} +1 -1
- package/dist/dashboard-web/chunks/{settings-page-P6MI2ZUE.js → settings-page-HMIUE2JA.js} +1 -1
- package/dist/dashboard-web/chunks/{skills-page-FT7BVZ6X.js → skills-page-A46KVWBL.js} +1 -1
- package/dist/dashboard-web/chunks/{team-federation-page-DEYCPUFB.js → team-federation-page-SDUC56DF.js} +1 -1
- package/dist/dashboard-web/chunks/{v3-page-4IOWREZG.js → v3-page-J5JOTUSQ.js} +1 -1
- package/dist/dashboard-web/chunks/{whiteboards-page-2VMBETZH.js → whiteboards-page-U7LSOAWI.js} +1 -1
- package/dist/dashboard-web/style.css +34 -4
- package/dist/dashboard.js +16 -1
- package/dist/dashboard.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +16 -7
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +16 -7
- package/dist/i18n/zh.js.map +1 -1
- package/dist/im/lark/card-handler.d.ts.map +1 -1
- package/dist/im/lark/card-handler.js +3 -0
- package/dist/im/lark/card-handler.js.map +1 -1
- package/dist/im/lark/event-dispatcher.d.ts +1 -0
- package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
- package/dist/im/lark/event-dispatcher.js +1 -1
- package/dist/im/lark/event-dispatcher.js.map +1 -1
- package/dist/im/lark/schedules-card.d.ts +2 -2
- package/dist/im/lark/schedules-card.d.ts.map +1 -1
- package/dist/im/lark/schedules-card.js +50 -34
- package/dist/im/lark/schedules-card.js.map +1 -1
- package/dist/index-daemon.js +13 -1
- package/dist/index-daemon.js.map +1 -1
- package/dist/services/schedule-store.d.ts +6 -2
- package/dist/services/schedule-store.d.ts.map +1 -1
- package/dist/services/schedule-store.js +19 -4
- package/dist/services/schedule-store.js.map +1 -1
- package/dist/skills/definitions.d.ts.map +1 -1
- package/dist/skills/definitions.js +4 -5
- package/dist/skills/definitions.js.map +1 -1
- package/dist/types.d.ts +36 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/child-env.d.ts +40 -1
- package/dist/utils/child-env.d.ts.map +1 -1
- package/dist/utils/child-env.js +45 -0
- package/dist/utils/child-env.js.map +1 -1
- package/dist/utils/pending-input-queue.d.ts +10 -0
- package/dist/utils/pending-input-queue.d.ts.map +1 -1
- package/dist/utils/pending-input-queue.js +15 -0
- package/dist/utils/pending-input-queue.js.map +1 -1
- package/dist/worker.js +102 -9
- package/dist/worker.js.map +1 -1
- package/dist/workflows/hostExecutors/botmux-schedule.d.ts +3 -1
- package/dist/workflows/hostExecutors/botmux-schedule.d.ts.map +1 -1
- package/dist/workflows/hostExecutors/botmux-schedule.js +14 -3
- package/dist/workflows/hostExecutors/botmux-schedule.js.map +1 -1
- package/dist/workflows/v3/architect.js +1 -1
- package/dist/workflows/v3/architect.js.map +1 -1
- package/dist/workflows/v3/contract.d.ts +8 -0
- package/dist/workflows/v3/contract.d.ts.map +1 -1
- package/dist/workflows/v3/contract.js.map +1 -1
- package/dist/workflows/v3/daemon-run.d.ts.map +1 -1
- package/dist/workflows/v3/daemon-run.js +2 -0
- package/dist/workflows/v3/daemon-run.js.map +1 -1
- package/dist/workflows/v3/ephemeral-pool.d.ts.map +1 -1
- package/dist/workflows/v3/ephemeral-pool.js +10 -2
- package/dist/workflows/v3/ephemeral-pool.js.map +1 -1
- package/dist/workflows/v3/run-envelope.d.ts +24 -24
- package/dist/workflows/v3/runtime.d.ts +5 -0
- package/dist/workflows/v3/runtime.d.ts.map +1 -1
- package/dist/workflows/v3/runtime.js +1 -0
- package/dist/workflows/v3/runtime.js.map +1 -1
- package/package.json +1 -1
- package/dist/dashboard-web/chunks/chunk-I35DXGM4.js +0 -1
- package/dist/dashboard-web/chunks/schedules-page-Z3672POL.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as i,F as c,d as r}from"./chunk-
|
|
1
|
+
import{B as i,F as c,d as r}from"./chunk-CUV65BIQ.js";var l={chats:[],bots:[]};async function A(){try{l=await r()}catch{}}var u=new Set(["working","analyzing","active","starting"]);function m(d){let s=new Map,e=t=>{let o=s.get(t);return o||(o={botName:t,larkAppId:t,cliId:"unknown",online:!1,sessions:[],active:[],busy:[],attention:[],lastActiveAt:0},s.set(t,o)),o};for(let t of l.bots??[]){let o=e(t.larkAppId??t.botName??"-");o.online=!0,t.botName&&(o.botName=t.botName),t.botAvatarUrl&&(o.botAvatarUrl=t.botAvatarUrl),t.cliId&&(o.cliId=t.cliId)}let p=[...d].sort((t,o)=>+(t.status==="closed")-+(o.status==="closed"));for(let t of p){let o=t.larkAppId??t.botName??"-";if(t.status==="closed"&&!s.has(o))continue;let a=e(o);t.botName&&(a.botName===a.larkAppId||!a.botName)&&(a.botName=t.botName),a.sessions.push(t),t.cliId&&a.cliId==="unknown"&&(a.cliId=t.cliId),a.lastActiveAt=Math.max(a.lastActiveAt,Number(t.lastMessageAt??0)),t.status!=="closed"&&(a.active.push(t),u.has(t.status)&&a.busy.push(t),c(t)&&a.attention.push(t))}for(let t of s.values())if(t.botName===t.larkAppId){let o=i(t.larkAppId);o&&(t.botName=o)}return[...s.values()].sort((t,o)=>{let a=n=>n.attention.length?0:n.busy.length?1:n.online||n.active.length?2:3;return a(t)!==a(o)?a(t)-a(o):o.lastActiveAt-t.lastActiveAt})}export{A as a,m as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as n,r as s,s as i}from"./chunk-
|
|
1
|
+
import{a as n,r as s,s as i}from"./chunk-CUV65BIQ.js";import{a as l}from"./chunk-5THX4DI2.js";import{c as S}from"./chunk-7SZRL6FY.js";var e=S(l(),1);function f(o){return n.on(o)}function m(o){let u=(0,e.useRef)(o),r=(0,e.useRef)(null);u.current=o;let a=()=>{let t=n.getSnapshot();if(r.current&&r.current.version===t.version)return r.current.value;let c=u.current(t);return r.current={version:t.version,value:c},c};return(0,e.useSyncExternalStore)(f,a,a)}function h(o){return s.on(o)}function p(){return s.locale}function v(){return(0,e.useSyncExternalStore)(h,p,p)}function T(){return v(),i}export{m as a,T as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as S,b as B,d as x}from"./chunk-5THX4DI2.js";import{c as g}from"./chunk-7SZRL6FY.js";var i=g(S(),1),E=g(B(),1),t=g(x(),1);function k(e,o){return e.find(a=>a.value===o)?.label??o}function H(e){let o=e.as??"span";return(0,t.jsx)(o,{style:{display:"contents"},dangerouslySetInnerHTML:{__html:e.html}})}function O(e){let o=["page-loading",e.compact?"page-loading-compact":"",e.className].filter(Boolean).join(" ");return(0,t.jsxs)("div",{className:o,role:"status","aria-live":"polite",children:[(0,t.jsx)("i",{className:"page-loading-spin","aria-hidden":"true"}),(0,t.jsx)("span",{children:e.label})]})}function J(e){return(0,t.jsxs)("div",{className:"sect-head overview-panel-head",children:[(0,t.jsx)("h2",{children:e.title}),e.count?(0,t.jsx)("span",{className:"sect-head-count",children:e.count}):null,e.hint?(0,t.jsx)("span",{className:"sect-head-hint",children:e.hint}):null,e.children]})}function X(e){return(0,t.jsx)("a",{className:"sect-head-action",href:e.href,children:e.children})}function D(e){return(0,t.jsx)("div",{className:"sect-head-controls",children:e.children})}function T(e){return e.kind==="plus"?(0,t.jsx)("svg",{className:"ui-action-icon",viewBox:"0 0 16 16","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M8 3.25v9.5M3.25 8h9.5"})}):(0,t.jsxs)("svg",{className:"ui-action-icon",viewBox:"0 0 16 16","aria-hidden":"true",children:[(0,t.jsx)("path",{d:"M13.1 6.55A5.35 5.35 0 1 0 13 10.1"}),(0,t.jsx)("path",{d:"M13.15 2.95v3.7H9.45"})]})}function A(e){let{children:o,className:a,type:l="button",...u}=e;return(0,t.jsxs)("button",{...u,type:l,className:["ui-create-action",a].filter(Boolean).join(" "),children:[(0,t.jsx)(T,{kind:"plus"}),(0,t.jsx)("span",{className:"ui-create-action-label",children:o})]})}function j(e){let{label:o,busy:a=!1,className:l,type:u="button",...d}=e;return(0,t.jsx)("button",{...d,type:u,className:["ui-refresh-button",a?"is-loading":"",l].filter(Boolean).join(" "),title:o,"aria-label":o,"aria-busy":a||void 0,children:(0,t.jsx)(T,{kind:"refresh"})})}function M(e,o){return e?.closest("dialog[open]")??o}function C(e){let o=(0,i.useRef)(null),a=(0,i.useRef)(null),[l,u]=(0,i.useState)(!1),[d,b]=(0,i.useState)(null),s=(0,i.useCallback)(()=>{let m=o.current;if(!m||typeof window>"u")return;let h=m.getBoundingClientRect(),r=Math.min(360,Math.max(160,window.innerWidth-48)),c=24+r/2,v=window.innerWidth-24-r/2,w=h.left+h.width/2,y=Math.min(Math.max(w,c),Math.max(c,v)),N=h.top<80;b({left:y,top:N?h.bottom+8:h.top-8,placement:N?"bottom":"top"})},[]),f=(0,i.useCallback)(()=>{a.current&&(clearTimeout(a.current),a.current=null),s(),u(!0)},[s]),n=(0,i.useCallback)(()=>{a.current&&clearTimeout(a.current),a.current=setTimeout(()=>u(!1),160)},[]);(0,i.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),(0,i.useEffect)(()=>{if(l)return s(),window.addEventListener("resize",s),window.addEventListener("scroll",s,!0),()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s,!0)}},[l,s]);let p=l&&d&&typeof document<"u"?(0,E.createPortal)((0,t.jsx)("span",{className:`ui-info-pop ui-info-pop-floating ui-info-pop-${d.placement}`,role:"tooltip",style:{left:d.left,top:d.top},onMouseEnter:f,onMouseLeave:n,children:e.children}),M(o.current,document.body)):null;return(0,t.jsxs)("span",{ref:o,className:["ui-info-tip",e.className].filter(Boolean).join(" "),tabIndex:e.focusable===!1?void 0:0,"aria-label":e.label,onClick:e.preventClick===!1?void 0:m=>m.preventDefault(),onMouseEnter:f,onMouseLeave:n,onFocus:f,onBlur:n,children:[e.trigger??(0,t.jsx)("span",{className:"ui-info-mark","aria-hidden":"true",children:"?"}),p]})}function z(e){let o=(0,i.useRef)(null),[a,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(!1),[b,s]=(0,i.useState)(null),f=(0,i.useCallback)(()=>{let r=o.current;if(!r)return!1;let v=(r.querySelector(".ui-overflow-scroll")??r).scrollWidth>r.clientWidth+1;return d(v),v||l(!1),v},[]),n=(0,i.useCallback)(()=>{let r=o.current;if(!r||typeof window>"u")return;let c=r.getBoundingClientRect(),v=Math.min(460,Math.max(220,window.innerWidth-48)),w=24+v/2,y=window.innerWidth-24-v/2,N=c.left+c.width/2,R=Math.min(Math.max(N,w),Math.max(w,y)),L=c.top<84;s({left:R,top:L?c.bottom+8:c.top-8,placement:L?"bottom":"top"})},[]),p=(0,i.useCallback)(()=>{if(!(!e.text.trim()||!f())){if(e.showPopover===!1){l(!1);return}n(),l(!0)}},[f,e.showPopover,e.text,n]),m=(0,i.useCallback)(()=>l(!1),[]);(0,i.useEffect)(()=>{let r=o.current;if(!r||typeof window>"u")return;let c=window.requestAnimationFrame(f),v=typeof ResizeObserver<"u"?new ResizeObserver(()=>f()):null;return v?.observe(r),window.addEventListener("resize",f),()=>{window.cancelAnimationFrame(c),v?.disconnect(),window.removeEventListener("resize",f)}},[f,e.text]),(0,i.useEffect)(()=>{if(a)return n(),window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[a,n]);let h=e.showPopover!==!1&&a&&b&&typeof document<"u"?(0,E.createPortal)((0,t.jsx)("span",{className:["ui-info-pop","ui-info-pop-floating",`ui-info-pop-${b.placement}`,"ui-overflow-popover",e.popoverClassName].filter(Boolean).join(" "),role:"tooltip",style:{left:b.left,top:b.top},children:e.text}),M(o.current,document.body)):null;return(0,t.jsxs)("span",{ref:o,className:["ui-overflow-text",u?"is-overflowing":"",e.className].filter(Boolean).join(" "),style:e.durationMs?{"--ui-overflow-duration":`${e.durationMs}ms`}:void 0,onMouseEnter:p,onMouseLeave:m,children:[(0,t.jsx)("span",{className:["ui-overflow-scroll",e.textClassName].filter(Boolean).join(" "),children:e.children??e.text}),h]})}function I(e){return(0,t.jsxs)("span",{className:["ui-field-title",e.className].filter(Boolean).join(" "),children:[(0,t.jsx)("span",{className:"ui-field-title-text",children:e.children}),e.help?(0,t.jsx)(C,{label:e.helpLabel,children:e.help}):null]})}function W(e){return(0,t.jsx)("ul",{className:["overview-list",e.className].filter(Boolean).join(" "),id:e.id,children:e.children})}function q(e){let{kind:o,className:a,children:l,...u}=e,d=o?`overview-list-item-${o}`:"";return(0,t.jsx)("li",{...u,className:["overview-list-item",d,a].filter(Boolean).join(" "),children:l})}function F(e){return(0,t.jsx)("div",{className:"overview-list-main",children:e.children})}function K(e){return(0,t.jsx)("div",{className:"overview-list-tail",children:e.children})}function P(e){let o=(0,i.useRef)(null),a=(0,i.useRef)(null),[l,u]=(0,i.useState)(""),d=n=>{o.current?.removeAttribute("open"),n!==e.value&&e.onChange(n)},b=l.trim().toLowerCase(),s=e.searchable&&b?e.options.filter(n=>n.value.toLowerCase().includes(b)||typeof n.label=="string"&&n.label.toLowerCase().includes(b)):e.options;(0,i.useEffect)(()=>{if(typeof document>"u")return;let n=()=>{o.current?.open&&(o.current.open=!1)},p=h=>{let r=o.current;if(!r?.open)return;let c=h.target;c instanceof Node&&r.contains(c)||n()},m=h=>{h.key==="Escape"&&n()};return document.addEventListener("pointerdown",p,!0),document.addEventListener("keydown",m),()=>{document.removeEventListener("pointerdown",p,!0),document.removeEventListener("keydown",m)}},[]),(0,i.useEffect)(()=>{e.disabled&&o.current?.open&&(o.current.open=!1)},[e.disabled]);let f=["sect-sort-menu",e.disabled?"is-disabled":"",e.className].filter(Boolean).join(" ");return(0,t.jsxs)("details",{id:e.id,className:f,ref:o,hidden:e.hidden,style:e.style,onToggle:n=>{!e.searchable||!n.currentTarget.open||(u(""),a.current?.focus())},children:[(0,t.jsx)("summary",{"aria-label":e.ariaLabel,"aria-disabled":e.disabled?!0:void 0,tabIndex:e.disabled?-1:void 0,onClick:n=>{e.disabled&&n.preventDefault()},onKeyDown:n=>{e.disabled&&(n.key==="Enter"||n.key===" ")&&n.preventDefault()},children:(0,t.jsx)("span",{className:"sect-sort-value",children:e.label})}),(0,t.jsxs)("div",{className:"sect-sort-pop",children:[e.searchable?(0,t.jsx)("input",{ref:a,className:"sect-sort-search",type:"search",placeholder:e.searchPlaceholder,"aria-label":e.searchPlaceholder,autoComplete:"off",spellCheck:!1,value:l,onChange:n=>u(n.currentTarget.value),onKeyDown:n=>{if(n.key!=="Enter")return;n.preventDefault();let p=s.find(m=>!m.disabled);p&&d(p.value)}}):null,s.map(n=>(0,t.jsx)("button",{type:"button",disabled:n.disabled,"aria-current":e.value===n.value?"true":void 0,onClick:()=>d(n.value),children:n.label},n.value)),e.searchable&&s.length===0?(0,t.jsx)("p",{className:"sect-sort-empty",children:e.searchEmptyLabel}):null]})]})}function $(e){return(0,t.jsx)(P,{...e})}export{k as a,H as b,O as c,J as d,X as e,D as f,A as g,j as h,C as i,z as j,I as k,W as l,q as m,F as n,K as o,P as p,$ as q};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as T}from"./chunk-I35DXGM4.js";import{s as t}from"./chunk-6QHMLMIM.js";import{a as Z,d as B}from"./chunk-5THX4DI2.js";import{c as E}from"./chunk-7SZRL6FY.js";var r=E(Z(),1);var e=E(B(),1),nn="botmux:open-bot-onboarding",L={id:"claude-code",label:"Claude"},G="glm-5.1";function x(){return{options:[L],ttadkModelDefault:G,ttadkModelSuggestions:[],suggestedAppName:"botmux-0",webSession:{status:"checking"}}}function Q(){return{appName:"",cliId:L.id,dirMode:"fixed",workingDir:"~",model:""}}function en(n,o){return n||o==="checking"}function q(n){return n instanceof Error?n.message:String(n)}function X(n){return n.status==="completed"||n.status==="failed"||n.status==="needs_owner"}function N(n){return n==="login_failed"||n==="invalid_session"||n==="identity_unavailable"||n==="session_changed"}function tn(n){return n.status==="waiting_for_scan"?n.registrationMode==="compat"?t("botOnboarding.waitingCompat"):t("botOnboarding.waiting",{name:n.appName??""}):n.status==="verifying"?t("botOnboarding.verifying"):n.status==="configuring_permissions"?n.permissionStatusMsg?`${t("botOnboarding.configuringPermissions")} ${n.permissionStatusMsg}`:t("botOnboarding.configuringPermissions"):n.status==="waiting_for_platform_scan"?t("botOnboarding.platformScanHint"):n.status==="needs_owner"?t("botOnboarding.needsOwnerTitle"):n.status==="completed"?t("botOnboarding.completed",{name:n.appName??t("botOnboarding.botFallback")}):n.status==="failed"?n.appId?t("botOnboarding.partialFailureTitle"):n.error==="qr_expired"?t("botOnboarding.qrExpiredTitle"):N(n.error)?t("botOnboarding.authIncompleteTitle"):t("botOnboarding.createFailedTitle"):t("botOnboarding.starting")}async function on(){try{let n=await fetch("/api/cli-options"),o=await n.json();if(n.ok&&Array.isArray(o?.options)){let a=typeof o.ttadkModelDefault=="string"&&o.ttadkModelDefault.trim()?o.ttadkModelDefault.trim():G,l=Array.isArray(o.ttadkModelSuggestions)?o.ttadkModelSuggestions.filter(f=>typeof f=="string"):[],d=typeof o.suggestedAppName=="string"&&o.suggestedAppName.trim()?o.suggestedAppName.trim():"botmux-0",b=o?.webSession?.identity,c=o?.webSession?.status==="ready"&&typeof b?.userId=="string"&&typeof b?.userName=="string"&&typeof b?.tenantId=="string"&&typeof b?.tenantName=="string"?{status:"ready",source:typeof o.webSession.source=="string"?o.webSession.source:"botmux_cache",identity:{userId:b.userId,userName:b.userName,...typeof b.email=="string"?{email:b.email}:{},tenantId:b.tenantId,tenantName:b.tenantName}}:{status:"scan_required",...typeof o?.webSession?.reason=="string"?{reason:o.webSession.reason}:{}};return{options:o.options,ttadkModelDefault:a,ttadkModelSuggestions:l,suggestedAppName:d,webSession:c}}}catch{}return{...x(),webSession:{status:"scan_required"}}}function K(n,o,a){let l=a.options.find(f=>f.id===o),d=l?.gateway==="ttadk",b=d&&l?.acceptsModel!==!1,c=n.model;return d&&!b?c="":b&&!c.trim()?c=a.ttadkModelDefault:!b&&c.trim()===a.ttadkModelDefault&&(c=""),{...n,cliId:o,model:c}}function an(n,o){let a=o.options.some(l=>l.id===n.cliId)?n.cliId:o.options[0]?.id??L.id;return K({...n},a,o)}async function gn(){window.dispatchEvent(new Event(nn))}function rn(n){let{job:o}=n;if(o.status!=="completed"&&o.status!=="needs_owner"||!o.permission)return null;let a=o.permission;if(a.ok){let d=[t("botOnboarding.permissionOk",{count:a.scopeCount??0})];return a.skippedScopeCount&&a.skippedScopeCount>0&&d.push(t("botOnboarding.permissionSkipped",{count:a.skippedScopeCount})),a.versionId&&d.push(t("botOnboarding.permissionVersion",{version:a.versionId})),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"hint-ok",children:d.join(" ")}),a.scopeWarning?(0,e.jsx)("p",{className:"hint-warn",children:a.scopeWarning}):null]})}let l=o.remainingSteps??[];return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{className:"hint-warn",children:[t("botOnboarding.permissionManual"),a.message?`\uFF08${a.message}\uFF09`:""]}),l.length?(0,e.jsx)("ol",{className:"onboarding-steps",children:l.map(d=>(0,e.jsx)("li",{children:(0,e.jsx)("a",{href:d.url,target:"_blank",rel:"noopener",children:d.title})},`${d.title}:${d.url}`))}):null]})}function sn(n){let{job:o}=n;return o.appId?(0,e.jsxs)("p",{className:"onboarding-meta",children:[(0,e.jsx)("b",{children:"App ID:"})," ",(0,e.jsx)("code",{children:o.appId}),o.appName?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsxs)("b",{children:[t("botOnboarding.appNameLabel"),":"]})," ",(0,e.jsx)("code",{children:o.appName})]}):null,o.cliId?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsx)("b",{children:"CLI:"})," ",(0,e.jsx)("code",{children:o.cliId})]}):null,o.workingDir?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsxs)("b",{children:[t("botOnboarding.metaDir"),":"]})," ",(0,e.jsx)("code",{children:o.workingDir})]}):null]}):null}function W(n){return(0,e.jsxs)("div",{className:"qr-card",children:[(0,e.jsx)("img",{className:"qr-image",src:n.dataUrl,alt:n.alt}),n.link?(0,e.jsx)("a",{className:"onboarding-link",href:n.link,target:"_blank",rel:"noopener",children:t("botOnboarding.openLink")}):null]})}function z(n,o){return n.find(a=>a.value===o)?.label??o}function ln(n){let{job:o,ownerError:a}=n.view;return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:`onboarding-status status-${o.status}`,children:tn(o)}),o.status==="waiting_for_scan"&&o.qrDataUrl?(0,e.jsx)(W,{dataUrl:o.qrDataUrl,alt:t("botOnboarding.qrAlt"),link:o.qrUrl}):null,o.status==="waiting_for_platform_scan"&&o.platformQrDataUrl?(0,e.jsx)(W,{dataUrl:o.platformQrDataUrl,alt:t("botOnboarding.platformQrAlt")}):null,(0,e.jsx)(sn,{job:o}),(0,e.jsx)(rn,{job:o}),o.status==="needs_owner"?(0,e.jsxs)("form",{className:"onboarding-form",id:"ob-owner-form",onSubmit:l=>{l.preventDefault(),n.onSubmitOwner(o,n.ownerInput,n.ownerIdInput)},children:[(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.ownerLabel")}),(0,e.jsx)("input",{id:"ob-owner",type:"email",placeholder:t("botOnboarding.ownerPlaceholder"),autoComplete:"off",spellCheck:!1,value:n.ownerInput,onChange:l=>n.onOwnerInputChange(l.currentTarget.value)})]}),(0,e.jsx)("p",{className:"hint-warn",children:t("botOnboarding.needsOwnerDescription")}),(0,e.jsxs)("details",{className:"onboarding-technical",children:[(0,e.jsx)("summary",{children:t("botOnboarding.ownerUseId")}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.ownerIdLabel")}),(0,e.jsx)("input",{id:"ob-owner-id",type:"text",placeholder:t("botOnboarding.ownerIdPlaceholder"),autoComplete:"off",spellCheck:!1,value:n.ownerIdInput,onChange:l=>n.onOwnerIdInputChange(l.currentTarget.value)})]})]}),a?(0,e.jsx)("p",{className:"form-error",children:a}):null,(0,e.jsx)("div",{className:"actions onboarding-actions",children:(0,e.jsx)("button",{type:"submit",className:"primary onboarding-submit",children:t("botOnboarding.ownerSubmit")})})]}):null,o.status==="completed"?(0,e.jsx)("p",{className:"hint-ok",children:o.liveStarted?t("botOnboarding.liveOk"):t("botOnboarding.restartHint")}):null,o.status==="failed"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"hint-warn",children:o.appId?t("botOnboarding.partialFailureDescription"):o.error==="qr_expired"?t("botOnboarding.qrExpiredDescription"):N(o.error)?t("botOnboarding.authIncompleteDescription"):t("botOnboarding.createFailedDescription")}),(0,e.jsxs)("details",{className:"onboarding-technical",children:[(0,e.jsx)("summary",{children:t("botOnboarding.technicalDetails")}),(0,e.jsx)("code",{children:o.message??o.error??"unknown"})]}),(0,e.jsxs)("div",{className:"actions onboarding-actions",children:[(0,e.jsx)("button",{type:"button",onClick:n.onClose,children:t("botOnboarding.close")}),o.appId?null:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:()=>n.onRetry("compat"),children:t("botOnboarding.compatibilityMode")}),(0,e.jsx)("button",{type:"button",className:"primary onboarding-submit",onClick:()=>n.onRetry("web"),children:o.error==="qr_expired"?t("botOnboarding.generateQr"):N(o.error)?t("botOnboarding.scanAgain"):t("botOnboarding.retry")})]})]})]}):null,o.status==="completed"?(0,e.jsx)("div",{className:"actions onboarding-actions",children:(0,e.jsx)("button",{type:"button",onClick:n.onClose,children:t("botOnboarding.close")})}):null]})}function dn(n){let o=n.cliState.options.find(s=>s.id===n.form.cliId),a=o?.gateway==="ttadk"&&o.acceptsModel!==!1,l=o?.gateway==="ttadk"&&o.acceptsModel===!1,d=a?t("botOnboarding.modelTtadkPlaceholder").replace("{model}",n.cliState.ttadkModelDefault):t("botOnboarding.modelPlaceholder"),b=n.form.dirMode==="card"?t("botOnboarding.dirLabelCard"):t("botOnboarding.dirLabelFixed"),c=n.form.dirMode==="card"?t("botOnboarding.dirPlaceholderCard"):t("botOnboarding.dirPlaceholderFixed"),f=[...n.cliState.options].sort((s,p)=>s.label.localeCompare(p.label,"en",{sensitivity:"base"})).map(s=>({value:s.id,label:s.available===!1?t("botOnboarding.cliMissingOption",{label:s.label,command:s.command??s.id}):s.label})),S=[{value:"fixed",label:t("botOnboarding.dirModeFixed")},{value:"card",label:t("botOnboarding.dirModeCard")}];return(0,e.jsxs)("form",{id:"onboarding-form",className:"onboarding-form",onSubmit:n.onSubmit,children:[(0,e.jsx)("div",{className:"onboarding-session","aria-live":"polite",children:n.sessionMode==="checking"?(0,e.jsx)("p",{children:t("botOnboarding.sessionChecking")}):n.cliState.webSession.status==="ready"?n.sessionMode==="reuse"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionReady",{user:n.cliState.webSession.identity.userName,tenant:n.cliState.webSession.identity.tenantName})}),n.cliState.webSession.identity.email?(0,e.jsx)("small",{children:n.cliState.webSession.identity.email}):null]}),(0,e.jsx)("button",{type:"button",className:"onboarding-session-action",onClick:()=>n.onSessionModeChange("qr"),children:t("botOnboarding.switchAccount")})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionSwitching")}),(0,e.jsx)("small",{children:t("botOnboarding.sessionSwitchingHint")})]}),(0,e.jsx)("button",{type:"button",className:"onboarding-session-action",onClick:()=>n.onSessionModeChange("reuse"),children:t("botOnboarding.reuseCurrentAccount")})]}):(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionScanRequired")}),(0,e.jsx)("small",{children:t("botOnboarding.sessionScanRequiredHint")})]})}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.appNameLabel")}),(0,e.jsx)("input",{id:"ob-app-name",type:"text",maxLength:64,value:n.form.appName,placeholder:t("botOnboarding.appNamePlaceholder"),autoComplete:"off",spellCheck:!1,onChange:s=>n.onFormChange({...n.form,appName:s.currentTarget.value})}),(0,e.jsx)("small",{className:"onboarding-field-hint",children:t("botOnboarding.appNameHint",{name:n.cliState.suggestedAppName})})]}),(0,e.jsxs)("div",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.cliLabel")}),(0,e.jsx)(T,{id:"ob-cli",className:"onboarding-menu",ariaLabel:t("botOnboarding.cliLabel"),label:z(f,n.form.cliId),value:n.form.cliId,options:f,searchable:!0,searchPlaceholder:t("common.dropdownSearch"),searchEmptyLabel:t("common.dropdownSearchEmpty"),onChange:s=>{n.onFormChange(K(n.form,s,n.cliState))}}),o?.available===!1?(0,e.jsx)("small",{className:"hint-warn",children:t("botOnboarding.cliMissingHint",{command:o.command??n.form.cliId})}):(0,e.jsx)("small",{className:"onboarding-field-hint",children:n.form.cliId})]}),(0,e.jsxs)("div",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.dirModeLabel")}),(0,e.jsx)(T,{id:"ob-dir-mode",className:"onboarding-menu",ariaLabel:t("botOnboarding.dirModeLabel"),label:z(S,n.form.dirMode),value:n.form.dirMode,options:S,onChange:s=>n.onFormChange({...n.form,dirMode:s})})]}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:b}),(0,e.jsx)("input",{id:"ob-dir",type:"text",value:n.form.workingDir,placeholder:c,autoComplete:"off",spellCheck:!1,onChange:s=>n.onFormChange({...n.form,workingDir:s.currentTarget.value})})]}),l?null:(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.modelLabel")}),(0,e.jsx)("input",{id:"ob-model",type:"text",list:a?"ob-model-suggestions":void 0,placeholder:d,autoComplete:"off",spellCheck:!1,value:n.form.model,onChange:s=>n.onFormChange({...n.form,model:s.currentTarget.value})}),a?(0,e.jsx)("datalist",{id:"ob-model-suggestions",children:n.cliState.ttadkModelSuggestions.map(s=>(0,e.jsx)("option",{value:s},s))}):null]}),n.error?(0,e.jsx)("p",{className:"form-error",children:n.error}):null,(0,e.jsxs)("div",{className:"actions onboarding-actions",children:[(0,e.jsx)("button",{type:"button",id:"ob-cancel",disabled:n.submitting,onClick:n.onClose,children:t("botOnboarding.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary onboarding-submit",disabled:en(n.submitting,n.sessionMode),children:n.submitting?t("botOnboarding.starting"):n.sessionMode==="reuse"?t("botOnboarding.confirmReuse"):t("botOnboarding.startScan")})]})]})}function un(n){let o=(0,r.useRef)(null),a=(0,r.useRef)(null),l=(0,r.useRef)(0),[d,b]=(0,r.useState)(()=>x()),[c,f]=(0,r.useState)(()=>Q()),[S,s]=(0,r.useState)("checking"),[p,w]=(0,r.useState)({kind:"form"}),[P,I]=(0,r.useState)(!1),[A,M]=(0,r.useState)(""),[J,_]=(0,r.useState)(""),g=(0,r.useCallback)(()=>{a.current!==null&&(window.clearInterval(a.current),a.current=null)},[]),v=(0,r.useCallback)(()=>{g(),n.onClose()},[n,g]),y=(0,r.useCallback)(i=>{w({kind:"job",job:i}),i.status==="needs_owner"&&(M(i.suggestedOwner??""),_("")),X(i)&&g()},[g]),j=(0,r.useCallback)(async i=>{let m=await fetch(`/api/bot-onboarding/${encodeURIComponent(i)}`),u=await m.json();if(!m.ok||!u?.job)throw new Error(u?.error??`http_${m.status}`);y(u.job)},[y]),R=(0,r.useCallback)(i=>{g(),a.current=window.setInterval(()=>{j(i).catch(m=>{g(),w({kind:"job",job:{id:i,status:"failed",message:q(m)}})})},1200)},[j,g]),U=(0,r.useCallback)(()=>{g();let i=l.current+1;l.current=i;let m=x();b(m),f(Q()),s("checking"),w({kind:"form"}),I(!1),M(""),_(""),on().then(u=>{l.current===i&&(b(u),f(k=>an(k,u)),s(u.webSession.status==="ready"?"reuse":"qr"))})},[g]);(0,r.useEffect)(()=>{if(n.open){U();return}g(),l.current+=1},[n.open,U,g]),(0,r.useEffect)(()=>{let i=o.current;if(i)if(n.open&&!i.open)try{i.showModal()}catch{}else!n.open&&i.open&&i.close()},[n.open]),(0,r.useEffect)(()=>()=>g(),[g]);let C=(0,r.useCallback)(async(i,m)=>{g(),I(!0),w({kind:"job",job:{id:"",status:"starting"}});try{let u=m??(S==="reuse"?"reuse":"qr"),k=i==="web"&&u==="reuse"&&d.webSession.status==="ready"?{userId:d.webSession.identity.userId,tenantId:d.webSession.identity.tenantId}:void 0,h=await fetch("/api/bot-onboarding/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({appName:i==="web"&&c.appName.trim()||void 0,registrationMode:i,...i==="web"?{sessionMode:u,expectedIdentity:k}:{},cliId:c.cliId,workingDir:c.workingDir.trim(),dirMode:c.dirMode,model:c.model.trim()||void 0})}),O=await h.json();if(h.status===400){w({kind:"form",error:O?.message??O?.error??"invalid_input"});return}if(!h.ok||!O?.job?.id)throw new Error(O?.error??`http_${h.status}`);let F=O.job;y(F),X(F)||R(F.id)}catch(u){w({kind:"job",job:{id:"",status:"failed",message:q(u)}})}finally{I(!1)}},[y,d.webSession,c,S,R,g]),H=(0,r.useCallback)(i=>{i.preventDefault(),C("web")},[C]),$=(0,r.useCallback)(i=>{if(i==="compat"&&!window.confirm(t("botOnboarding.compatibilityConfirm")))return;let m=i==="web"&&p.kind==="job"&&N(p.job.error);m&&s("qr"),C(i,m?"qr":void 0)},[C,p]),V=(0,r.useCallback)(async(i,m,u)=>{let k=[m.trim(),u.trim()].filter(Boolean).join(",");if(!k){w({kind:"job",job:i,ownerError:t("botOnboarding.ownerEmpty")});return}try{let h=await fetch(`/api/bot-onboarding/${encodeURIComponent(i.id)}/owner`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({owner:k})}),O=await h.json();if(!h.ok){w({kind:"job",job:i,ownerError:O?.message??O?.error??t("botOnboarding.ownerInvalid")});return}O?.job&&y(O.job)}catch(h){w({kind:"job",job:i,ownerError:q(h)})}},[y]),Y=(0,r.useMemo)(()=>p.kind==="form"?(0,e.jsx)(dn,{cliState:d,form:c,sessionMode:S,error:p.error,submitting:P,onFormChange:f,onSessionModeChange:s,onSubmit:H,onClose:v}):(0,e.jsx)(ln,{view:p,ownerInput:A,ownerIdInput:J,onOwnerInputChange:M,onOwnerIdInputChange:_,onSubmitOwner:V,onRetry:$,onClose:v}),[d,v,c,J,A,$,S,H,V,P,p]),D=p.kind==="form"||p.kind==="job"&&(p.job.status==="completed"||p.job.status==="failed");return(0,e.jsx)("dialog",{className:"onboarding-dialog",ref:o,onCancel:i=>{D||i.preventDefault()},onClose:()=>{D&&v()},onClick:i=>{D&&i.target===i.currentTarget&&v()},children:(0,e.jsxs)("article",{className:"onboarding-card",children:[(0,e.jsxs)("header",{className:"onboarding-header",children:[(0,e.jsx)("h3",{children:t("botOnboarding.title")}),(0,e.jsx)("p",{children:t("botOnboarding.intro")})]}),Y]})})}export{nn as a,gn as b,un as c};
|
|
1
|
+
import{p as T}from"./chunk-QFMH6ITB.js";import{s as t}from"./chunk-CUV65BIQ.js";import{a as Z,d as B}from"./chunk-5THX4DI2.js";import{c as E}from"./chunk-7SZRL6FY.js";var r=E(Z(),1);var e=E(B(),1),nn="botmux:open-bot-onboarding",L={id:"claude-code",label:"Claude"},G="glm-5.1";function x(){return{options:[L],ttadkModelDefault:G,ttadkModelSuggestions:[],suggestedAppName:"botmux-0",webSession:{status:"checking"}}}function Q(){return{appName:"",cliId:L.id,dirMode:"fixed",workingDir:"~",model:""}}function en(n,o){return n||o==="checking"}function q(n){return n instanceof Error?n.message:String(n)}function X(n){return n.status==="completed"||n.status==="failed"||n.status==="needs_owner"}function N(n){return n==="login_failed"||n==="invalid_session"||n==="identity_unavailable"||n==="session_changed"}function tn(n){return n.status==="waiting_for_scan"?n.registrationMode==="compat"?t("botOnboarding.waitingCompat"):t("botOnboarding.waiting",{name:n.appName??""}):n.status==="verifying"?t("botOnboarding.verifying"):n.status==="configuring_permissions"?n.permissionStatusMsg?`${t("botOnboarding.configuringPermissions")} ${n.permissionStatusMsg}`:t("botOnboarding.configuringPermissions"):n.status==="waiting_for_platform_scan"?t("botOnboarding.platformScanHint"):n.status==="needs_owner"?t("botOnboarding.needsOwnerTitle"):n.status==="completed"?t("botOnboarding.completed",{name:n.appName??t("botOnboarding.botFallback")}):n.status==="failed"?n.appId?t("botOnboarding.partialFailureTitle"):n.error==="qr_expired"?t("botOnboarding.qrExpiredTitle"):N(n.error)?t("botOnboarding.authIncompleteTitle"):t("botOnboarding.createFailedTitle"):t("botOnboarding.starting")}async function on(){try{let n=await fetch("/api/cli-options"),o=await n.json();if(n.ok&&Array.isArray(o?.options)){let a=typeof o.ttadkModelDefault=="string"&&o.ttadkModelDefault.trim()?o.ttadkModelDefault.trim():G,l=Array.isArray(o.ttadkModelSuggestions)?o.ttadkModelSuggestions.filter(f=>typeof f=="string"):[],d=typeof o.suggestedAppName=="string"&&o.suggestedAppName.trim()?o.suggestedAppName.trim():"botmux-0",b=o?.webSession?.identity,c=o?.webSession?.status==="ready"&&typeof b?.userId=="string"&&typeof b?.userName=="string"&&typeof b?.tenantId=="string"&&typeof b?.tenantName=="string"?{status:"ready",source:typeof o.webSession.source=="string"?o.webSession.source:"botmux_cache",identity:{userId:b.userId,userName:b.userName,...typeof b.email=="string"?{email:b.email}:{},tenantId:b.tenantId,tenantName:b.tenantName}}:{status:"scan_required",...typeof o?.webSession?.reason=="string"?{reason:o.webSession.reason}:{}};return{options:o.options,ttadkModelDefault:a,ttadkModelSuggestions:l,suggestedAppName:d,webSession:c}}}catch{}return{...x(),webSession:{status:"scan_required"}}}function K(n,o,a){let l=a.options.find(f=>f.id===o),d=l?.gateway==="ttadk",b=d&&l?.acceptsModel!==!1,c=n.model;return d&&!b?c="":b&&!c.trim()?c=a.ttadkModelDefault:!b&&c.trim()===a.ttadkModelDefault&&(c=""),{...n,cliId:o,model:c}}function an(n,o){let a=o.options.some(l=>l.id===n.cliId)?n.cliId:o.options[0]?.id??L.id;return K({...n},a,o)}async function gn(){window.dispatchEvent(new Event(nn))}function rn(n){let{job:o}=n;if(o.status!=="completed"&&o.status!=="needs_owner"||!o.permission)return null;let a=o.permission;if(a.ok){let d=[t("botOnboarding.permissionOk",{count:a.scopeCount??0})];return a.skippedScopeCount&&a.skippedScopeCount>0&&d.push(t("botOnboarding.permissionSkipped",{count:a.skippedScopeCount})),a.versionId&&d.push(t("botOnboarding.permissionVersion",{version:a.versionId})),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"hint-ok",children:d.join(" ")}),a.scopeWarning?(0,e.jsx)("p",{className:"hint-warn",children:a.scopeWarning}):null]})}let l=o.remainingSteps??[];return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("p",{className:"hint-warn",children:[t("botOnboarding.permissionManual"),a.message?`\uFF08${a.message}\uFF09`:""]}),l.length?(0,e.jsx)("ol",{className:"onboarding-steps",children:l.map(d=>(0,e.jsx)("li",{children:(0,e.jsx)("a",{href:d.url,target:"_blank",rel:"noopener",children:d.title})},`${d.title}:${d.url}`))}):null]})}function sn(n){let{job:o}=n;return o.appId?(0,e.jsxs)("p",{className:"onboarding-meta",children:[(0,e.jsx)("b",{children:"App ID:"})," ",(0,e.jsx)("code",{children:o.appId}),o.appName?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsxs)("b",{children:[t("botOnboarding.appNameLabel"),":"]})," ",(0,e.jsx)("code",{children:o.appName})]}):null,o.cliId?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsx)("b",{children:"CLI:"})," ",(0,e.jsx)("code",{children:o.cliId})]}):null,o.workingDir?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{children:" / "}),(0,e.jsxs)("b",{children:[t("botOnboarding.metaDir"),":"]})," ",(0,e.jsx)("code",{children:o.workingDir})]}):null]}):null}function W(n){return(0,e.jsxs)("div",{className:"qr-card",children:[(0,e.jsx)("img",{className:"qr-image",src:n.dataUrl,alt:n.alt}),n.link?(0,e.jsx)("a",{className:"onboarding-link",href:n.link,target:"_blank",rel:"noopener",children:t("botOnboarding.openLink")}):null]})}function z(n,o){return n.find(a=>a.value===o)?.label??o}function ln(n){let{job:o,ownerError:a}=n.view;return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:`onboarding-status status-${o.status}`,children:tn(o)}),o.status==="waiting_for_scan"&&o.qrDataUrl?(0,e.jsx)(W,{dataUrl:o.qrDataUrl,alt:t("botOnboarding.qrAlt"),link:o.qrUrl}):null,o.status==="waiting_for_platform_scan"&&o.platformQrDataUrl?(0,e.jsx)(W,{dataUrl:o.platformQrDataUrl,alt:t("botOnboarding.platformQrAlt")}):null,(0,e.jsx)(sn,{job:o}),(0,e.jsx)(rn,{job:o}),o.status==="needs_owner"?(0,e.jsxs)("form",{className:"onboarding-form",id:"ob-owner-form",onSubmit:l=>{l.preventDefault(),n.onSubmitOwner(o,n.ownerInput,n.ownerIdInput)},children:[(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.ownerLabel")}),(0,e.jsx)("input",{id:"ob-owner",type:"email",placeholder:t("botOnboarding.ownerPlaceholder"),autoComplete:"off",spellCheck:!1,value:n.ownerInput,onChange:l=>n.onOwnerInputChange(l.currentTarget.value)})]}),(0,e.jsx)("p",{className:"hint-warn",children:t("botOnboarding.needsOwnerDescription")}),(0,e.jsxs)("details",{className:"onboarding-technical",children:[(0,e.jsx)("summary",{children:t("botOnboarding.ownerUseId")}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.ownerIdLabel")}),(0,e.jsx)("input",{id:"ob-owner-id",type:"text",placeholder:t("botOnboarding.ownerIdPlaceholder"),autoComplete:"off",spellCheck:!1,value:n.ownerIdInput,onChange:l=>n.onOwnerIdInputChange(l.currentTarget.value)})]})]}),a?(0,e.jsx)("p",{className:"form-error",children:a}):null,(0,e.jsx)("div",{className:"actions onboarding-actions",children:(0,e.jsx)("button",{type:"submit",className:"primary onboarding-submit",children:t("botOnboarding.ownerSubmit")})})]}):null,o.status==="completed"?(0,e.jsx)("p",{className:"hint-ok",children:o.liveStarted?t("botOnboarding.liveOk"):t("botOnboarding.restartHint")}):null,o.status==="failed"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("p",{className:"hint-warn",children:o.appId?t("botOnboarding.partialFailureDescription"):o.error==="qr_expired"?t("botOnboarding.qrExpiredDescription"):N(o.error)?t("botOnboarding.authIncompleteDescription"):t("botOnboarding.createFailedDescription")}),(0,e.jsxs)("details",{className:"onboarding-technical",children:[(0,e.jsx)("summary",{children:t("botOnboarding.technicalDetails")}),(0,e.jsx)("code",{children:o.message??o.error??"unknown"})]}),(0,e.jsxs)("div",{className:"actions onboarding-actions",children:[(0,e.jsx)("button",{type:"button",onClick:n.onClose,children:t("botOnboarding.close")}),o.appId?null:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:()=>n.onRetry("compat"),children:t("botOnboarding.compatibilityMode")}),(0,e.jsx)("button",{type:"button",className:"primary onboarding-submit",onClick:()=>n.onRetry("web"),children:o.error==="qr_expired"?t("botOnboarding.generateQr"):N(o.error)?t("botOnboarding.scanAgain"):t("botOnboarding.retry")})]})]})]}):null,o.status==="completed"?(0,e.jsx)("div",{className:"actions onboarding-actions",children:(0,e.jsx)("button",{type:"button",onClick:n.onClose,children:t("botOnboarding.close")})}):null]})}function dn(n){let o=n.cliState.options.find(s=>s.id===n.form.cliId),a=o?.gateway==="ttadk"&&o.acceptsModel!==!1,l=o?.gateway==="ttadk"&&o.acceptsModel===!1,d=a?t("botOnboarding.modelTtadkPlaceholder").replace("{model}",n.cliState.ttadkModelDefault):t("botOnboarding.modelPlaceholder"),b=n.form.dirMode==="card"?t("botOnboarding.dirLabelCard"):t("botOnboarding.dirLabelFixed"),c=n.form.dirMode==="card"?t("botOnboarding.dirPlaceholderCard"):t("botOnboarding.dirPlaceholderFixed"),f=[...n.cliState.options].sort((s,p)=>s.label.localeCompare(p.label,"en",{sensitivity:"base"})).map(s=>({value:s.id,label:s.available===!1?t("botOnboarding.cliMissingOption",{label:s.label,command:s.command??s.id}):s.label})),S=[{value:"fixed",label:t("botOnboarding.dirModeFixed")},{value:"card",label:t("botOnboarding.dirModeCard")}];return(0,e.jsxs)("form",{id:"onboarding-form",className:"onboarding-form",onSubmit:n.onSubmit,children:[(0,e.jsx)("div",{className:"onboarding-session","aria-live":"polite",children:n.sessionMode==="checking"?(0,e.jsx)("p",{children:t("botOnboarding.sessionChecking")}):n.cliState.webSession.status==="ready"?n.sessionMode==="reuse"?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionReady",{user:n.cliState.webSession.identity.userName,tenant:n.cliState.webSession.identity.tenantName})}),n.cliState.webSession.identity.email?(0,e.jsx)("small",{children:n.cliState.webSession.identity.email}):null]}),(0,e.jsx)("button",{type:"button",className:"onboarding-session-action",onClick:()=>n.onSessionModeChange("qr"),children:t("botOnboarding.switchAccount")})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionSwitching")}),(0,e.jsx)("small",{children:t("botOnboarding.sessionSwitchingHint")})]}),(0,e.jsx)("button",{type:"button",className:"onboarding-session-action",onClick:()=>n.onSessionModeChange("reuse"),children:t("botOnboarding.reuseCurrentAccount")})]}):(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:t("botOnboarding.sessionScanRequired")}),(0,e.jsx)("small",{children:t("botOnboarding.sessionScanRequiredHint")})]})}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.appNameLabel")}),(0,e.jsx)("input",{id:"ob-app-name",type:"text",maxLength:64,value:n.form.appName,placeholder:t("botOnboarding.appNamePlaceholder"),autoComplete:"off",spellCheck:!1,onChange:s=>n.onFormChange({...n.form,appName:s.currentTarget.value})}),(0,e.jsx)("small",{className:"onboarding-field-hint",children:t("botOnboarding.appNameHint",{name:n.cliState.suggestedAppName})})]}),(0,e.jsxs)("div",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.cliLabel")}),(0,e.jsx)(T,{id:"ob-cli",className:"onboarding-menu",ariaLabel:t("botOnboarding.cliLabel"),label:z(f,n.form.cliId),value:n.form.cliId,options:f,searchable:!0,searchPlaceholder:t("common.dropdownSearch"),searchEmptyLabel:t("common.dropdownSearchEmpty"),onChange:s=>{n.onFormChange(K(n.form,s,n.cliState))}}),o?.available===!1?(0,e.jsx)("small",{className:"hint-warn",children:t("botOnboarding.cliMissingHint",{command:o.command??n.form.cliId})}):(0,e.jsx)("small",{className:"onboarding-field-hint",children:n.form.cliId})]}),(0,e.jsxs)("div",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.dirModeLabel")}),(0,e.jsx)(T,{id:"ob-dir-mode",className:"onboarding-menu",ariaLabel:t("botOnboarding.dirModeLabel"),label:z(S,n.form.dirMode),value:n.form.dirMode,options:S,onChange:s=>n.onFormChange({...n.form,dirMode:s})})]}),(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:b}),(0,e.jsx)("input",{id:"ob-dir",type:"text",value:n.form.workingDir,placeholder:c,autoComplete:"off",spellCheck:!1,onChange:s=>n.onFormChange({...n.form,workingDir:s.currentTarget.value})})]}),l?null:(0,e.jsxs)("label",{className:"onboarding-field",children:[(0,e.jsx)("span",{children:t("botOnboarding.modelLabel")}),(0,e.jsx)("input",{id:"ob-model",type:"text",list:a?"ob-model-suggestions":void 0,placeholder:d,autoComplete:"off",spellCheck:!1,value:n.form.model,onChange:s=>n.onFormChange({...n.form,model:s.currentTarget.value})}),a?(0,e.jsx)("datalist",{id:"ob-model-suggestions",children:n.cliState.ttadkModelSuggestions.map(s=>(0,e.jsx)("option",{value:s},s))}):null]}),n.error?(0,e.jsx)("p",{className:"form-error",children:n.error}):null,(0,e.jsxs)("div",{className:"actions onboarding-actions",children:[(0,e.jsx)("button",{type:"button",id:"ob-cancel",disabled:n.submitting,onClick:n.onClose,children:t("botOnboarding.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary onboarding-submit",disabled:en(n.submitting,n.sessionMode),children:n.submitting?t("botOnboarding.starting"):n.sessionMode==="reuse"?t("botOnboarding.confirmReuse"):t("botOnboarding.startScan")})]})]})}function un(n){let o=(0,r.useRef)(null),a=(0,r.useRef)(null),l=(0,r.useRef)(0),[d,b]=(0,r.useState)(()=>x()),[c,f]=(0,r.useState)(()=>Q()),[S,s]=(0,r.useState)("checking"),[p,w]=(0,r.useState)({kind:"form"}),[P,I]=(0,r.useState)(!1),[A,M]=(0,r.useState)(""),[J,_]=(0,r.useState)(""),g=(0,r.useCallback)(()=>{a.current!==null&&(window.clearInterval(a.current),a.current=null)},[]),v=(0,r.useCallback)(()=>{g(),n.onClose()},[n,g]),y=(0,r.useCallback)(i=>{w({kind:"job",job:i}),i.status==="needs_owner"&&(M(i.suggestedOwner??""),_("")),X(i)&&g()},[g]),j=(0,r.useCallback)(async i=>{let m=await fetch(`/api/bot-onboarding/${encodeURIComponent(i)}`),u=await m.json();if(!m.ok||!u?.job)throw new Error(u?.error??`http_${m.status}`);y(u.job)},[y]),R=(0,r.useCallback)(i=>{g(),a.current=window.setInterval(()=>{j(i).catch(m=>{g(),w({kind:"job",job:{id:i,status:"failed",message:q(m)}})})},1200)},[j,g]),U=(0,r.useCallback)(()=>{g();let i=l.current+1;l.current=i;let m=x();b(m),f(Q()),s("checking"),w({kind:"form"}),I(!1),M(""),_(""),on().then(u=>{l.current===i&&(b(u),f(k=>an(k,u)),s(u.webSession.status==="ready"?"reuse":"qr"))})},[g]);(0,r.useEffect)(()=>{if(n.open){U();return}g(),l.current+=1},[n.open,U,g]),(0,r.useEffect)(()=>{let i=o.current;if(i)if(n.open&&!i.open)try{i.showModal()}catch{}else!n.open&&i.open&&i.close()},[n.open]),(0,r.useEffect)(()=>()=>g(),[g]);let C=(0,r.useCallback)(async(i,m)=>{g(),I(!0),w({kind:"job",job:{id:"",status:"starting"}});try{let u=m??(S==="reuse"?"reuse":"qr"),k=i==="web"&&u==="reuse"&&d.webSession.status==="ready"?{userId:d.webSession.identity.userId,tenantId:d.webSession.identity.tenantId}:void 0,h=await fetch("/api/bot-onboarding/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({appName:i==="web"&&c.appName.trim()||void 0,registrationMode:i,...i==="web"?{sessionMode:u,expectedIdentity:k}:{},cliId:c.cliId,workingDir:c.workingDir.trim(),dirMode:c.dirMode,model:c.model.trim()||void 0})}),O=await h.json();if(h.status===400){w({kind:"form",error:O?.message??O?.error??"invalid_input"});return}if(!h.ok||!O?.job?.id)throw new Error(O?.error??`http_${h.status}`);let F=O.job;y(F),X(F)||R(F.id)}catch(u){w({kind:"job",job:{id:"",status:"failed",message:q(u)}})}finally{I(!1)}},[y,d.webSession,c,S,R,g]),H=(0,r.useCallback)(i=>{i.preventDefault(),C("web")},[C]),$=(0,r.useCallback)(i=>{if(i==="compat"&&!window.confirm(t("botOnboarding.compatibilityConfirm")))return;let m=i==="web"&&p.kind==="job"&&N(p.job.error);m&&s("qr"),C(i,m?"qr":void 0)},[C,p]),V=(0,r.useCallback)(async(i,m,u)=>{let k=[m.trim(),u.trim()].filter(Boolean).join(",");if(!k){w({kind:"job",job:i,ownerError:t("botOnboarding.ownerEmpty")});return}try{let h=await fetch(`/api/bot-onboarding/${encodeURIComponent(i.id)}/owner`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({owner:k})}),O=await h.json();if(!h.ok){w({kind:"job",job:i,ownerError:O?.message??O?.error??t("botOnboarding.ownerInvalid")});return}O?.job&&y(O.job)}catch(h){w({kind:"job",job:i,ownerError:q(h)})}},[y]),Y=(0,r.useMemo)(()=>p.kind==="form"?(0,e.jsx)(dn,{cliState:d,form:c,sessionMode:S,error:p.error,submitting:P,onFormChange:f,onSessionModeChange:s,onSubmit:H,onClose:v}):(0,e.jsx)(ln,{view:p,ownerInput:A,ownerIdInput:J,onOwnerInputChange:M,onOwnerIdInputChange:_,onSubmitOwner:V,onRetry:$,onClose:v}),[d,v,c,J,A,$,S,H,V,P,p]),D=p.kind==="form"||p.kind==="job"&&(p.job.status==="completed"||p.job.status==="failed");return(0,e.jsx)("dialog",{className:"onboarding-dialog",ref:o,onCancel:i=>{D||i.preventDefault()},onClose:()=>{D&&v()},onClick:i=>{D&&i.target===i.currentTarget&&v()},children:(0,e.jsxs)("article",{className:"onboarding-card",children:[(0,e.jsxs)("header",{className:"onboarding-header",children:[(0,e.jsx)("h3",{children:t("botOnboarding.title")}),(0,e.jsx)("p",{children:t("botOnboarding.intro")})]}),Y]})})}export{nn as a,gn as b,un as c};
|
package/dist/dashboard-web/chunks/{connectors-page-DZBQ42MH.js → connectors-page-KTC2QWNW.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as H,b as Q}from"./chunk-EVK77ASG.js";import{b as W}from"./chunk-FYALHCPG.js";import{a as ce,c as le,g as Le,k as M,p as ie}from"./chunk-I35DXGM4.js";import"./chunk-6QHMLMIM.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Ce,d as re}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var l=K(Ce(),1);var m=K(Ce(),1);var n=K(re(),1),Re=50,we={total:0,ok:0,error:0,successRate:0};function $e(t,e=Date.now()){if(t==="all")return;let s=t==="24h"?24:t==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function Ae(t,e=0){let s=new URLSearchParams({limit:String(Re),offset:String(e)});t.connectorId&&s.set("connectorId",t.connectorId),t.status&&s.set("status",t.status);let g=$e(t.timeWindow);return g&&s.set("since",g),t.query.trim()&&s.set("q",t.query.trim()),s}function Ie(t){if(!t)return"\u2014";let e=new Date(t);return Number.isFinite(e.getTime())?e.toLocaleString():t}function de(t){return t===void 0||!Number.isFinite(t)?"\u2014":t<1e3?`${Math.round(t)} ms`:t<6e4?`${(t/1e3).toFixed(t<1e4?1:0)} s`:`${(t/6e4).toFixed(1)} min`}function He(t){return t===void 0?"\u2014":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ke(t){return t.value===void 0||t.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):typeof t.value=="object"&&!Array.isArray(t.value)&&Object.keys(t.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${t.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(t.value,null,2)})})}function Oe(t){let e=[["kind",t.value?.kind],["mode",t.value?.mode],["botId",t.value?.botId],["chatId",t.value?.chatId],["sessionId",t.value?.sessionId],["rootMessageId",t.value?.rootMessageId],["workflowId",t.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,g])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(g)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function ve(t){return(0,n.jsx)(ie,{id:t.id,className:"webhook-log-filter-menu",ariaLabel:t.label,style:{width:"100%",minWidth:0},value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function ue(t){return(0,n.jsxs)("article",{className:`card webhook-log-metric${t.tone?` ${t.tone}`:""}`,children:[(0,n.jsx)("span",{children:t.label}),(0,n.jsx)("strong",{children:t.value}),(0,n.jsx)("small",{children:t.hint||"\xA0"})]})}function Te(t={}){let e=W(),s=(0,m.useRef)(!1),g=(0,m.useRef)([]),[k,L]=(0,m.useState)([]),[h,I]=(0,m.useState)([]),[y,R]=(0,m.useState)(we),[C,$]=(0,m.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[d,r]=(0,m.useState)(null),[E,_]=(0,m.useState)(!0),[v,U]=(0,m.useState)(!1),[O,J]=(0,m.useState)(!1),[V,Y]=(0,m.useState)(0),[q,P]=(0,m.useState)(""),[X,Z]=(0,m.useState)(!1),T=(0,m.useMemo)(()=>new Map(k.map(c=>[c.id,c.name])),[k]),u=(0,m.useMemo)(()=>h.find(c=>c.triggerId===d)??h[0]??null,[h,d]),ee=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...k.map(c=>({value:c.id,label:c.name}))],[k,e]),B=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),be=(0,m.useMemo)(()=>[{value:"24h",label:e("webhookLogs.last24h")},{value:"7d",label:e("webhookLogs.last7d")},{value:"30d",label:e("webhookLogs.last30d")},{value:"all",label:e("webhookLogs.allTime")}],[e]),A=(0,m.useCallback)(async(c=!1,w=!1)=>{w?U(!0):_(!0),P("");let z=c?g.current.length:0,oe=Ae(C,z),f=new URLSearchParams(oe);f.delete("limit"),f.delete("offset");try{let[F,te]=await Promise.all([H(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):H(`/api/trigger-logs/summary?${f}`)]);if(!s.current)return;if(F.status!==200)throw new Error(String(F.body?.error||F.status));let S=Array.isArray(F.body?.logs)?F.body.logs:[],ne=c?[...g.current,...S]:S;g.current=ne,I(ne),Y(Number(F.body?.total??S.length)),J(F.body?.hasMore===!0),c||(R(te?.status===200?te.body?.summary??we:we),r(ae=>S.some(fe=>fe.triggerId===ae)?ae:S[0]?.triggerId??null))}catch(F){s.current&&P(F?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(_(!1),U(!1))}},[C,e]);(0,m.useEffect)(()=>(s.current=!0,H("/api/connectors").then(c=>{s.current&&c.status===200&&L(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,m.useEffect)(()=>{let c=setTimeout(()=>{A(!1)},C.query?260:0);return()=>clearTimeout(c)},[C,A]),(0,m.useEffect)(()=>{let c=setInterval(()=>{A(!1,!0)},15e3);return()=>clearInterval(c)},[A]);async function pe(){u&&(await navigator.clipboard?.writeText(JSON.stringify(u,null,2)),Z(!0),setTimeout(()=>s.current&&Z(!1),1200))}let he=u?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):u?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),j=(0,n.jsxs)(n.Fragment,{children:[t.embedded?null:(0,n.jsxs)("div",{className:"page-heading",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,n.jsx)("h1",{children:e("nav.webhookLogs")}),(0,n.jsx)("p",{className:"webhook-log-heading-copy",children:e("webhookLogs.subtitle")})]}),(0,n.jsxs)("div",{className:"page-heading-actions",children:[(0,n.jsxs)("span",{className:`webhook-log-live${v?" refreshing":""}`,children:[(0,n.jsx)("i",{}),e("webhookLogs.autoRefresh")]}),(0,n.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})]})]}),(0,n.jsxs)("section",{className:"webhook-log-metrics","aria-label":e("webhookLogs.summary"),children:[(0,n.jsx)(ue,{label:e("webhookLogs.total"),value:y.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(ue,{label:e("webhookLogs.successRate"),value:`${y.successRate.toFixed(y.successRate%1?1:0)}%`,tone:"ok",hint:`${y.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(ue,{label:e("webhookLogs.failures"),value:y.error,tone:y.error?"error":void 0,hint:y.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(ue,{label:e("webhookLogs.p95"),value:de(y.p95DurationMs),hint:`${e("webhookLogs.average")} ${de(y.avgDurationMs)}`})]}),(0,n.jsxs)("form",{className:"filters dashboard-toolbar webhook-log-toolbar",onSubmit:c=>c.preventDefault(),children:[(0,n.jsx)("input",{type:"search",name:"q","aria-label":e("webhookLogs.search"),placeholder:e("webhookLogs.searchPlaceholder"),value:C.query,onChange:c=>{let w=c.currentTarget.value;$(z=>({...z,query:w}))}}),(0,n.jsx)(ve,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:C.connectorId,options:ee,onChange:c=>$(w=>({...w,connectorId:c}))}),(0,n.jsx)(ve,{id:"webhook-log-status",label:e("webhookLogs.status"),value:C.status,options:B,onChange:c=>$(w=>({...w,status:c}))}),(0,n.jsx)(ve,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:C.timeWindow,options:be,onChange:c=>$(w=>({...w,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{A(!1,!0)},children:e("webhookLogs.refresh")})]}),q?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",q]}):null,(0,n.jsxs)("section",{className:"webhook-log-workspace",children:[(0,n.jsxs)("article",{className:"card webhook-log-list-panel",children:[(0,n.jsx)("header",{className:"webhook-log-panel-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:e("webhookLogs.records")}),(0,n.jsx)("span",{children:e("webhookLogs.matching",{count:V})})]})}),E&&!h.length?(0,n.jsx)(le,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!h.length?(0,n.jsxs)("div",{className:"webhook-log-empty",children:[(0,n.jsx)("span",{"aria-hidden":"true",children:"\u25CE"}),(0,n.jsx)("strong",{children:e("webhookLogs.empty")}),(0,n.jsx)("p",{children:e("webhookLogs.emptyHint")})]}):null,(0,n.jsx)("div",{className:"webhook-log-list",role:"listbox","aria-label":e("webhookLogs.records"),children:h.map(c=>{let w=u?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":w,className:`webhook-log-row${w?" active":""}`,onClick:()=>r(c.triggerId),children:[(0,n.jsx)("span",{className:`webhook-log-status-dot ${c.status}`,"aria-hidden":"true"}),(0,n.jsxs)("span",{className:"webhook-log-row-main",children:[(0,n.jsxs)("span",{className:"webhook-log-row-title",children:[(0,n.jsx)("strong",{children:T.get(c.connectorId||"")||c.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsx)("code",{children:c.request?.method||"POST"})]}),(0,n.jsxs)("span",{className:"webhook-log-row-meta",children:[(0,n.jsx)("span",{children:Ie(c.createdAt)}),(0,n.jsx)("span",{children:c.errorCode||c.action})]})]}),(0,n.jsxs)("span",{className:"webhook-log-row-result",children:[(0,n.jsx)("b",{className:c.status,children:c.response?.httpStatus??(c.status==="ok"?"2xx":"ERR")}),(0,n.jsx)("small",{children:de(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),O?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{A(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:u?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("header",{className:"webhook-log-detail-head",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:`webhook-log-result-pill ${u.status}`,children:u.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:T.get(u.connectorId||"")||u.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Ie(u.createdAt)," \xB7 ",u.request?.method||"POST"," ",u.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{pe()},children:e(X?"webhookLogs.copied":"webhookLogs.copyJson")})]}),u.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:u.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:u.error})]}):null,(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.overview")}),(0,n.jsxs)("dl",{className:"webhook-log-facts",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.httpStatus")}),(0,n.jsx)("dd",{children:u.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:de(u.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:u.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:He(u.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.requestId||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.remoteAddress")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.request?.remoteAddress||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.target")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.target?.chatId||u.target?.sessionId||u.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(ke,{value:u.request?.query,empty:e("webhookLogs.none")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.headers"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),(0,n.jsx)(ke,{value:u.request?.headers,empty:e("webhookLogs.headersNotStored")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.payload"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),u.request?.payloadStored?(0,n.jsx)(ke,{value:u.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:he})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Oe,{value:u.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return t.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:j}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:j})}var o=K(re(),1);function qe(t,e){return t.map(s=>s.id===e.id?e:s)}var Me={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",verify:"token",secret:"",storePayload:!0};function oo(t,e){return{promptEnvelope:{sourceName:t.promptEnvelope?.sourceName||t.name,instruction:e}}}function Be(t){return[{value:"turn",label:t("connectors.kindTurn")},{value:"workflow",label:t("connectors.kindWorkflowRetiring"),disabled:!0}]}function Ne(t){return`${location.origin}/webhook/${encodeURIComponent(t)}`}function ge(t){return(0,o.jsx)(ie,{id:t.id,className:"connector-form-menu",ariaLabel:t.label,value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function Pe(t){let e=(0,l.useRef)(null),[s,g]=(0,l.useState)(!1),[k,L]=(0,l.useState)(""),h=Array.isArray(t.value)?t.value:t.value?[t.value]:[],I=(0,l.useMemo)(()=>new Set(h),[h]),y=k.trim().toLocaleLowerCase(),R=(0,l.useMemo)(()=>y?t.groups.filter(d=>`${d.name} ${d.chatId}`.toLocaleLowerCase().includes(y)):t.groups,[y,t.groups]),C=t.multiple?h.length===0?t.allLabel||t.placeholder:t.selectedCountLabel(h.length):t.groups.find(d=>d.chatId===h[0])?.name||h[0]||t.placeholder;(0,l.useEffect)(()=>{if(!s)return;let d=r=>{e.current?.contains(r.target)||g(!1)};return document.addEventListener("pointerdown",d),()=>document.removeEventListener("pointerdown",d)},[s]);function $(d){if(!t.multiple){t.onChange(d),g(!1),L("");return}t.onChange(I.has(d)?h.filter(r=>r!==d):[...h,d])}return(0,o.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,o.jsxs)("button",{id:t.id,type:"button",className:"connector-group-picker-trigger","aria-label":t.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>g(d=>!d),children:[(0,o.jsx)("span",{className:h.length||t.multiple&&t.allLabel?"":"muted",children:C}),(0,o.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,o.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,o.jsxs)("label",{className:"connector-group-search",htmlFor:`${t.id}-search`,children:[(0,o.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,o.jsx)("input",{id:`${t.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:k,placeholder:t.searchPlaceholder,onChange:d=>L(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),g(!1))}})]}),(0,o.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":t.label,"aria-multiselectable":t.multiple||void 0,children:[t.multiple&&t.allLabel&&!y?(0,o.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${h.length===0?" selected":""}`,role:"option","aria-selected":h.length===0,onClick:()=>t.onChange([]),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:t.allLabel}),(0,o.jsx)("small",{children:t.placeholder})]})]}):null,R.map(d=>{let r=I.has(d.chatId);return(0,o.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(d.chatId),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:d.name||d.chatId}),d.name?(0,o.jsx)("small",{children:d.chatId}):null]})]},d.chatId)}),R.length?null:(0,o.jsx)("p",{className:"connector-group-empty",children:t.emptyLabel})]})]}):null]})}function me(t,e){return t.filter(s=>s.bots.includes(e))}function Ge(t,e){let s=t.target.chatId||"",g=s&&me(e,t.target.botId).some(k=>k.chatId===s);return{name:t.name,botId:t.target.botId,kind:t.target.kind,workflowId:t.target.workflowId||"",mode:t.target.mode,chatId:g?s:"",manualChat:!!(s&&!g),manualChatId:g?"":s,allowChats:t.target.allowChats||[],deduplicate:!!t.lifecycleExtractors?.dedupKey,dedup:t.lifecycleExtractors?.dedupKey||"",instruction:t.promptEnvelope?.instruction||"",topicMessageMode:t.topicMessage?.mode||"default",topicMessageText:t.topicMessage?.text||"",verify:t.verify?.type||"token",secret:"",storePayload:t.loggingPolicy?.storePayload!==!1}}function We(t){let e=W(),s=t.active==="webhooks",g=t.active==="logs";return(0,o.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,o.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,o.jsx)("a",{href:"#/connectors/logs",className:`itab${g?" on":""}`,role:"tab","aria-selected":g,children:e("connectors.tabLogs")})]})}function xe(t){let e=W(),s=(0,l.useRef)(!1),g=(0,l.useRef)(null),k=(0,l.useRef)(null),[L,h]=(0,l.useState)([]),[I,y]=(0,l.useState)([]),[R,C]=(0,l.useState)([]),[$,d]=(0,l.useState)(!0),[r,E]=(0,l.useState)(Me),[_,v]=(0,l.useState)(null),[U,O]=(0,l.useState)(null),[J,V]=(0,l.useState)(!1),[Y,q]=(0,l.useState)(!1),[P,X]=(0,l.useState)(null),[Z,T]=(0,l.useState)(null),[u,ee]=(0,l.useState)(null),B=(0,l.useMemo)(()=>me(I,r.botId),[I,r.botId]),be=(0,l.useMemo)(()=>L.length?L.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[L,e]),A=(0,l.useMemo)(()=>Be(e),[e]),pe=(0,l.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),he=(0,l.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),j=(0,l.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,l.useCallback)((a,i)=>{E(b=>{let N=b.botId&&a.some(D=>D.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",p=me(i,N),x=b.chatId&&p.some(D=>D.chatId===b.chatId)?b.chatId:p[0]?.chatId??"",G=new Set(p.map(D=>D.chatId));return{...b,botId:N,chatId:x,allowChats:b.allowChats.filter(D=>G.has(D))}})},[]),w=(0,l.useCallback)(async()=>{d(!0);try{let[a,i,b]=await Promise.all([H("/api/bots"),H("/api/connectors"),H("/api/groups")]);if(!s.current)return;let N=(a.body?.bots||[]).map(x=>({larkAppId:x.larkAppId,botName:x.botName||x.larkAppId})),p=(b.body?.chats||[]).map(x=>({chatId:x.chatId,name:x.name||"",bots:(x.memberBots||[]).filter(G=>G.inChat).map(G=>G.larkAppId)}));h(N),y(p),C(Array.isArray(i.body?.connectors)?i.body.connectors:[]),c(N,p)}finally{s.current&&d(!1)}},[c]);(0,l.useEffect)(()=>(s.current=!0,w(),()=>{s.current=!1,g.current&&clearTimeout(g.current)}),[w]),(0,l.useEffect)(()=>{let a=new Set(B.map(i=>i.chatId));E(i=>({...i,chatId:i.chatId&&a.has(i.chatId)?i.chatId:B[0]?.chatId??"",allowChats:i.allowChats.filter(b=>a.has(b))}))},[B]),(0,l.useEffect)(()=>{let a=k.current;if(a)if(Y){if(!a.open)try{a.showModal()}catch{}let i=a.querySelector(".connector-modal-body");i&&(i.scrollTop=0)}else a.open&&a.close()},[Y]),(0,l.useEffect)(()=>()=>{let a=k.current;a?.open&&a.close()},[]);function z(a){return e(a==="fixed"?"connectors.modeLabelFixed":a==="new-group"?"connectors.modeLabelNewGroup":"connectors.modeLabelDynamic")}function oe(a){return e(a==="workflow"?"connectors.kindLabelWorkflow":"connectors.kindLabelTurn")}function f(a){E(i=>({...i,...a}))}function F(){v(null),O(null),X(null),E(a=>{let i=a.botId||L[0]?.larkAppId||"";return{...Me,botId:i,chatId:me(I,i)[0]?.chatId||""}}),q(!0)}function te(a){v(null),O(null),T(null),X(a),E(Ge(a,I)),q(!0)}function S(){J||(q(!1),v(null),O(null),X(null))}async function ne(){v(null),O(null);let a=r.name.trim(),i=r.botId;if(!a){v({text:e("connectors.errName"),error:!0});return}if(!i){v({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){v({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if(r.topicMessageMode==="custom"&&!b){v({text:e("connectors.errTopicMessage"),error:!0});return}let N={name:a,enabled:P?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:i},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:{mode:r.topicMessageMode,...r.topicMessageMode==="custom"?{text:b}:{}},verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let p=r.manualChat?r.manualChatId.trim():r.chatId;if(!p){v({text:e("connectors.errChat"),error:!0});return}N.target.chatId=p}else r.mode==="dynamic"&&(N.target.allowChats=r.allowChats);if(r.mode==="new-group"){let p=r.dedup.trim();if(r.deduplicate&&!p){v({text:e("connectors.errDedup"),error:!0});return}N.lifecycleExtractors=r.deduplicate?{dedupKey:p}:null}else N.lifecycleExtractors=null;r.secret.trim()&&(N.secret=r.secret.trim()),V(!0),v({text:e(P?"connectors.saving":"connectors.creating")});try{let p=await Q(P?"PUT":"POST",P?`/api/connectors/${encodeURIComponent(P.id)}`:"/api/connectors",N);if(!s.current)return;if((p.status===201||p.status===200)&&p.body?.ok){if(P){let ye=P.id;C(De=>qe(De,p.body.connector)),T({id:ye,text:e("connectors.updated")}),q(!1),X(null);return}let x=p.body.webhookUrl||Ne(p.body.connector.id),G=(p.body.connector?.verify?.type??"token")==="token",D=r.mode==="dynamic",Ee=D?N.target.allowChats?.[0]||"<chatId>":"";v(null),O({name:a,mode:r.mode,chatId:N.target.chatId,url:x,secret:p.body.secret,isToken:G,isDynamic:D,exampleChat:Ee}),E(ye=>({...ye,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",allowChats:[],storePayload:!0})),await w()}else{let x=p.body?.error||p.status;v({text:e("connectors.createFailed",{error:String(x)}),error:!0})}}finally{s.current&&V(!1)}}async function ae(a){T({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let i=await Q("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(i.status===200&&i.body?.ok)T(null),await w();else{let b=i.body?.error||i.status;T({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function fe(a){let i=a.loggingPolicy?.storePayload!==!1;T({id:a.id,text:e("connectors.saving")});let b=await Q("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!i,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)T(null),await w();else{let N=b.body?.error||b.status;T({id:a.id,text:e("connectors.saveFailed",{error:String(N)}),error:!0})}}async function Se(a){if(!confirm(e("connectors.delConfirm")))return;T({id:a.id,text:e("connectors.deleting")});let i=await Q("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(i.status===200&&i.body?.ok)T(null),await w();else{let b=i.body?.error||i.status;T({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function Fe(a){navigator.clipboard?.writeText(Ne(a.id)),ee(a.id),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{s.current&&ee(null)},1200)}return(0,o.jsxs)("section",{className:"page connectors-page",children:[(0,o.jsxs)("div",{className:"page-heading",children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,o.jsx)("h1",{children:e("nav.connectors")})]}),(0,o.jsx)("div",{className:"page-heading-actions",children:t.tab==="webhooks"?(0,o.jsx)(Le,{className:"page-primary-action connector-create-trigger",onClick:F,children:e("connectors.createTitle")}):(0,o.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,o.jsx)(We,{active:t.tab}),t.tab==="webhooks"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("dialog",{ref:k,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),S()},onClose:S,onClick:a=>{a.target===a.currentTarget&&S()},children:(0,o.jsxs)("article",{className:"connector-modal-card",children:[(0,o.jsxs)("header",{className:"connector-modal-header",children:[(0,o.jsx)("h3",{children:e(P?"connectors.editTitle":"connectors.createTitle")}),(0,o.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:J,onClick:S,children:(0,o.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,o.jsx)("div",{className:"connector-modal-body",children:U?(0,o.jsx)(_e,{created:U,groupName:j}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"cn-form",children:[(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,o.jsx)(M,{children:e("connectors.fName")}),(0,o.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>f({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fBot")}),(0,o.jsx)(ge,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:be,onChange:a=>f({botId:a})})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fKind")}),(0,o.jsx)(ge,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:A,onChange:a=>f({kind:a})})]}),r.kind==="workflow"?(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,o.jsx)(M,{children:e("connectors.fWf")}),(0,o.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>f({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fMode")}),(0,o.jsx)(ge,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:pe,onChange:a=>f({mode:a})})]}),r.mode==="fixed"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsx)(M,{children:e("connectors.fFixedChat")}),(0,o.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,o.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>f({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,o.jsx)(Pe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:B,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>f({chatId:a})}),(0,o.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>f({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsxs)(M,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)(Pe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:B,value:r.allowChats,multiple:!0,allLabel:e("connectors.allowAll"),placeholder:e("connectors.allowAllHint"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>f({allowChats:a})})]}):null,r.mode==="dynamic"?(0,o.jsx)("div",{className:"cn-field-wide",children:(0,o.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,o.jsx)(M,{children:e("connectors.newGroupStrategy")}),(0,o.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>f({deduplicate:!1}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,o.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>f({deduplicate:!0}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,o.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,o.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,o.jsx)(M,{help:(0,o.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,o.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>f({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,o.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,o.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,o.jsxs)(M,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>f({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,o.jsx)(M,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,o.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","none"].map(a=>(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>f({topicMessageMode:a}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e(`connectors.topicMessage${a==="default"?"Default":a==="custom"?"Custom":"None"}`)}),(0,o.jsx)("small",{children:e(`connectors.topicMessage${a==="default"?"DefaultHint":a==="custom"?"CustomHint":"NoneHint"}`)})]})]},a))}),r.topicMessageMode==="custom"?(0,o.jsxs)("label",{className:"connector-topic-message-input",htmlFor:"cn-topic-message",children:[(0,o.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>f({topicMessageText:a.currentTarget.value}),placeholder:e("connectors.topicMessageCustomPh")}),(0,o.jsxs)("small",{children:[e("connectors.topicMessageCustomHelp"),(0,o.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]})]}):(0,o.jsx)("p",{className:`connector-topic-message-preview${r.topicMessageMode==="none"?" muted":""}`,children:r.topicMessageMode==="none"?e("connectors.topicMessageNonePreview"):e("connectors.topicMessagePreview",{source:r.name.trim()||e("connectors.topicMessageSourceFallback")})})]}),(0,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,o.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>f({storePayload:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.storePayload")}),(0,o.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fVerify")}),(0,o.jsx)(ge,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:he,onChange:a=>f({verify:a})})]}),(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,o.jsx)(M,{children:e("connectors.fSecret")}),(0,o.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>f({secret:a.currentTarget.value}),placeholder:e(P?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),_?(0,o.jsx)("p",{className:`connector-create-message${_.error?" err":""}`,children:_.text}):null]})}),(0,o.jsxs)("footer",{className:"connector-modal-actions",children:[(0,o.jsx)("button",{type:"button",disabled:J,onClick:S,children:e("connectors.cancel")}),U?(0,o.jsx)("button",{type:"button",className:"primary",onClick:S,children:e("connectors.close")}):(0,o.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:J,onClick:()=>{ne()},children:e(P?"connectors.btnSave":"connectors.btnCreate")})]})]})}),(0,o.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,o.jsx)("div",{className:"card connector-list-card",children:$?(0,o.jsx)(le,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,o.jsx)(Ue,{connectors:R,bots:L,copiedId:u,editMsg:Z,groupName:j,modeLabel:z,kindLabel:oe,onCopy:Fe,onEdit:te,onToggle:a=>{ae(a)},onTogglePayloadLogging:a=>{fe(a)},onDelete:a=>{Se(a)}})})})]}):(0,o.jsx)(Te,{embedded:!0})]})}function _e(t){let e=W(),s=t.created,g=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,k=s.exampleChat!=="<chatId>"?`\uFF08${t.groupName(s.exampleChat)}\uFF09`:"";return(0,o.jsx)("div",{className:"connector-created-wrap",children:(0,o.jsxs)("div",{className:"card connector-created-card",children:[(0,o.jsxs)("p",{className:"connector-created-title ok",children:[e("connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,o.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:t.groupName(s.chatId)})]}):null]}),(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsx)("code",{children:s.url})]}),s.secret?(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,o.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:k})}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ue(t){let e=W();return t.connectors.length?(0,o.jsx)(o.Fragment,{children:t.connectors.map(s=>{let g=t.bots.find(C=>C.larkAppId===s.target.botId),k=Ne(s.id),L=(s.verify?.type??"token")==="token",h=e(L?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:t.groupName(s.target.chatId)}):"",y=t.editMsg?.id===s.id?t.editMsg:null,R=t.copiedId===s.id;return(0,o.jsxs)("div",{className:"card connector-item-card",children:[(0,o.jsxs)("div",{className:"connector-item-head",children:[(0,o.jsxs)("div",{className:"connector-item-main",children:[(0,o.jsxs)("div",{className:"connector-item-title",children:[(0,o.jsx)("b",{children:s.name}),(0,o.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,o.jsxs)("div",{className:"connector-item-meta",children:[(0,o.jsx)("span",{children:g?.botName||s.target.botId}),(0,o.jsx)("span",{children:t.kindLabel(s.target.kind)}),(0,o.jsx)("span",{children:t.modeLabel(s.target.mode)}),I?(0,o.jsx)("span",{children:I}):null,(0,o.jsx)("span",{children:h}),(0,o.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,o.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>t.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,o.jsxs)("div",{className:"connector-url-row",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsxs)("code",{children:[k,L?"/<token>":""]})]}),L?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,o.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,o.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,o.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),y?(0,o.jsx)("div",{className:y.error?"err connector-item-note":"muted connector-item-note",children:y.text}):null,(0,o.jsxs)("div",{className:"connector-item-actions",children:[(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onEdit(s),children:e("connectors.btnEdit")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,o.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function to(t){return se(t,(0,o.jsx)(xe,{tab:"webhooks"}))}function no(t){return se(t,(0,o.jsx)(xe,{tab:"logs"}))}export{oo as buildConnectorInstructionUpdateBody,Be as buildConnectorKindOptions,no as renderConnectorsLogsPage,to as renderConnectorsPage,qe as replaceConnectorById};
|
|
1
|
+
import{a as H,b as Q}from"./chunk-EVK77ASG.js";import{b as W}from"./chunk-P6GO5KT4.js";import{a as ce,c as le,g as Le,k as M,p as ie}from"./chunk-QFMH6ITB.js";import"./chunk-CUV65BIQ.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Ce,d as re}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var l=K(Ce(),1);var m=K(Ce(),1);var n=K(re(),1),Re=50,we={total:0,ok:0,error:0,successRate:0};function $e(t,e=Date.now()){if(t==="all")return;let s=t==="24h"?24:t==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function Ae(t,e=0){let s=new URLSearchParams({limit:String(Re),offset:String(e)});t.connectorId&&s.set("connectorId",t.connectorId),t.status&&s.set("status",t.status);let g=$e(t.timeWindow);return g&&s.set("since",g),t.query.trim()&&s.set("q",t.query.trim()),s}function Ie(t){if(!t)return"\u2014";let e=new Date(t);return Number.isFinite(e.getTime())?e.toLocaleString():t}function de(t){return t===void 0||!Number.isFinite(t)?"\u2014":t<1e3?`${Math.round(t)} ms`:t<6e4?`${(t/1e3).toFixed(t<1e4?1:0)} s`:`${(t/6e4).toFixed(1)} min`}function He(t){return t===void 0?"\u2014":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ke(t){return t.value===void 0||t.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):typeof t.value=="object"&&!Array.isArray(t.value)&&Object.keys(t.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:t.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${t.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(t.value,null,2)})})}function Oe(t){let e=[["kind",t.value?.kind],["mode",t.value?.mode],["botId",t.value?.botId],["chatId",t.value?.chatId],["sessionId",t.value?.sessionId],["rootMessageId",t.value?.rootMessageId],["workflowId",t.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,g])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(g)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function ve(t){return(0,n.jsx)(ie,{id:t.id,className:"webhook-log-filter-menu",ariaLabel:t.label,style:{width:"100%",minWidth:0},value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function ue(t){return(0,n.jsxs)("article",{className:`card webhook-log-metric${t.tone?` ${t.tone}`:""}`,children:[(0,n.jsx)("span",{children:t.label}),(0,n.jsx)("strong",{children:t.value}),(0,n.jsx)("small",{children:t.hint||"\xA0"})]})}function Te(t={}){let e=W(),s=(0,m.useRef)(!1),g=(0,m.useRef)([]),[k,L]=(0,m.useState)([]),[h,I]=(0,m.useState)([]),[y,R]=(0,m.useState)(we),[C,$]=(0,m.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[d,r]=(0,m.useState)(null),[E,_]=(0,m.useState)(!0),[v,U]=(0,m.useState)(!1),[O,J]=(0,m.useState)(!1),[V,Y]=(0,m.useState)(0),[q,P]=(0,m.useState)(""),[X,Z]=(0,m.useState)(!1),T=(0,m.useMemo)(()=>new Map(k.map(c=>[c.id,c.name])),[k]),u=(0,m.useMemo)(()=>h.find(c=>c.triggerId===d)??h[0]??null,[h,d]),ee=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...k.map(c=>({value:c.id,label:c.name}))],[k,e]),B=(0,m.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),be=(0,m.useMemo)(()=>[{value:"24h",label:e("webhookLogs.last24h")},{value:"7d",label:e("webhookLogs.last7d")},{value:"30d",label:e("webhookLogs.last30d")},{value:"all",label:e("webhookLogs.allTime")}],[e]),A=(0,m.useCallback)(async(c=!1,w=!1)=>{w?U(!0):_(!0),P("");let z=c?g.current.length:0,oe=Ae(C,z),f=new URLSearchParams(oe);f.delete("limit"),f.delete("offset");try{let[F,te]=await Promise.all([H(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):H(`/api/trigger-logs/summary?${f}`)]);if(!s.current)return;if(F.status!==200)throw new Error(String(F.body?.error||F.status));let S=Array.isArray(F.body?.logs)?F.body.logs:[],ne=c?[...g.current,...S]:S;g.current=ne,I(ne),Y(Number(F.body?.total??S.length)),J(F.body?.hasMore===!0),c||(R(te?.status===200?te.body?.summary??we:we),r(ae=>S.some(fe=>fe.triggerId===ae)?ae:S[0]?.triggerId??null))}catch(F){s.current&&P(F?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(_(!1),U(!1))}},[C,e]);(0,m.useEffect)(()=>(s.current=!0,H("/api/connectors").then(c=>{s.current&&c.status===200&&L(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,m.useEffect)(()=>{let c=setTimeout(()=>{A(!1)},C.query?260:0);return()=>clearTimeout(c)},[C,A]),(0,m.useEffect)(()=>{let c=setInterval(()=>{A(!1,!0)},15e3);return()=>clearInterval(c)},[A]);async function pe(){u&&(await navigator.clipboard?.writeText(JSON.stringify(u,null,2)),Z(!0),setTimeout(()=>s.current&&Z(!1),1200))}let he=u?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):u?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),j=(0,n.jsxs)(n.Fragment,{children:[t.embedded?null:(0,n.jsxs)("div",{className:"page-heading",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,n.jsx)("h1",{children:e("nav.webhookLogs")}),(0,n.jsx)("p",{className:"webhook-log-heading-copy",children:e("webhookLogs.subtitle")})]}),(0,n.jsxs)("div",{className:"page-heading-actions",children:[(0,n.jsxs)("span",{className:`webhook-log-live${v?" refreshing":""}`,children:[(0,n.jsx)("i",{}),e("webhookLogs.autoRefresh")]}),(0,n.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})]})]}),(0,n.jsxs)("section",{className:"webhook-log-metrics","aria-label":e("webhookLogs.summary"),children:[(0,n.jsx)(ue,{label:e("webhookLogs.total"),value:y.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(ue,{label:e("webhookLogs.successRate"),value:`${y.successRate.toFixed(y.successRate%1?1:0)}%`,tone:"ok",hint:`${y.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(ue,{label:e("webhookLogs.failures"),value:y.error,tone:y.error?"error":void 0,hint:y.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(ue,{label:e("webhookLogs.p95"),value:de(y.p95DurationMs),hint:`${e("webhookLogs.average")} ${de(y.avgDurationMs)}`})]}),(0,n.jsxs)("form",{className:"filters dashboard-toolbar webhook-log-toolbar",onSubmit:c=>c.preventDefault(),children:[(0,n.jsx)("input",{type:"search",name:"q","aria-label":e("webhookLogs.search"),placeholder:e("webhookLogs.searchPlaceholder"),value:C.query,onChange:c=>{let w=c.currentTarget.value;$(z=>({...z,query:w}))}}),(0,n.jsx)(ve,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:C.connectorId,options:ee,onChange:c=>$(w=>({...w,connectorId:c}))}),(0,n.jsx)(ve,{id:"webhook-log-status",label:e("webhookLogs.status"),value:C.status,options:B,onChange:c=>$(w=>({...w,status:c}))}),(0,n.jsx)(ve,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:C.timeWindow,options:be,onChange:c=>$(w=>({...w,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:v,onClick:()=>{A(!1,!0)},children:e("webhookLogs.refresh")})]}),q?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",q]}):null,(0,n.jsxs)("section",{className:"webhook-log-workspace",children:[(0,n.jsxs)("article",{className:"card webhook-log-list-panel",children:[(0,n.jsx)("header",{className:"webhook-log-panel-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:e("webhookLogs.records")}),(0,n.jsx)("span",{children:e("webhookLogs.matching",{count:V})})]})}),E&&!h.length?(0,n.jsx)(le,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!h.length?(0,n.jsxs)("div",{className:"webhook-log-empty",children:[(0,n.jsx)("span",{"aria-hidden":"true",children:"\u25CE"}),(0,n.jsx)("strong",{children:e("webhookLogs.empty")}),(0,n.jsx)("p",{children:e("webhookLogs.emptyHint")})]}):null,(0,n.jsx)("div",{className:"webhook-log-list",role:"listbox","aria-label":e("webhookLogs.records"),children:h.map(c=>{let w=u?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":w,className:`webhook-log-row${w?" active":""}`,onClick:()=>r(c.triggerId),children:[(0,n.jsx)("span",{className:`webhook-log-status-dot ${c.status}`,"aria-hidden":"true"}),(0,n.jsxs)("span",{className:"webhook-log-row-main",children:[(0,n.jsxs)("span",{className:"webhook-log-row-title",children:[(0,n.jsx)("strong",{children:T.get(c.connectorId||"")||c.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsx)("code",{children:c.request?.method||"POST"})]}),(0,n.jsxs)("span",{className:"webhook-log-row-meta",children:[(0,n.jsx)("span",{children:Ie(c.createdAt)}),(0,n.jsx)("span",{children:c.errorCode||c.action})]})]}),(0,n.jsxs)("span",{className:"webhook-log-row-result",children:[(0,n.jsx)("b",{className:c.status,children:c.response?.httpStatus??(c.status==="ok"?"2xx":"ERR")}),(0,n.jsx)("small",{children:de(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),O?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{A(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:u?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("header",{className:"webhook-log-detail-head",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:`webhook-log-result-pill ${u.status}`,children:u.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:T.get(u.connectorId||"")||u.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Ie(u.createdAt)," \xB7 ",u.request?.method||"POST"," ",u.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{pe()},children:e(X?"webhookLogs.copied":"webhookLogs.copyJson")})]}),u.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:u.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:u.error})]}):null,(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.overview")}),(0,n.jsxs)("dl",{className:"webhook-log-facts",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.httpStatus")}),(0,n.jsx)("dd",{children:u.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:de(u.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:u.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:He(u.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.requestId||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.remoteAddress")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.request?.remoteAddress||"\u2014"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.target")}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:u.target?.chatId||u.target?.sessionId||u.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(ke,{value:u.request?.query,empty:e("webhookLogs.none")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.headers"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),(0,n.jsx)(ke,{value:u.request?.headers,empty:e("webhookLogs.headersNotStored")})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsxs)("h3",{children:[e("webhookLogs.payload"),(0,n.jsx)("small",{children:e("webhookLogs.redacted")})]}),u.request?.payloadStored?(0,n.jsx)(ke,{value:u.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:he})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Oe,{value:u.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return t.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:j}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:j})}var o=K(re(),1);function qe(t,e){return t.map(s=>s.id===e.id?e:s)}var Me={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",verify:"token",secret:"",storePayload:!0};function oo(t,e){return{promptEnvelope:{sourceName:t.promptEnvelope?.sourceName||t.name,instruction:e}}}function Be(t){return[{value:"turn",label:t("connectors.kindTurn")},{value:"workflow",label:t("connectors.kindWorkflowRetiring"),disabled:!0}]}function Ne(t){return`${location.origin}/webhook/${encodeURIComponent(t)}`}function ge(t){return(0,o.jsx)(ie,{id:t.id,className:"connector-form-menu",ariaLabel:t.label,value:t.value,label:ce(t.options,t.value),options:t.options,onChange:t.onChange})}function Pe(t){let e=(0,l.useRef)(null),[s,g]=(0,l.useState)(!1),[k,L]=(0,l.useState)(""),h=Array.isArray(t.value)?t.value:t.value?[t.value]:[],I=(0,l.useMemo)(()=>new Set(h),[h]),y=k.trim().toLocaleLowerCase(),R=(0,l.useMemo)(()=>y?t.groups.filter(d=>`${d.name} ${d.chatId}`.toLocaleLowerCase().includes(y)):t.groups,[y,t.groups]),C=t.multiple?h.length===0?t.allLabel||t.placeholder:t.selectedCountLabel(h.length):t.groups.find(d=>d.chatId===h[0])?.name||h[0]||t.placeholder;(0,l.useEffect)(()=>{if(!s)return;let d=r=>{e.current?.contains(r.target)||g(!1)};return document.addEventListener("pointerdown",d),()=>document.removeEventListener("pointerdown",d)},[s]);function $(d){if(!t.multiple){t.onChange(d),g(!1),L("");return}t.onChange(I.has(d)?h.filter(r=>r!==d):[...h,d])}return(0,o.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,o.jsxs)("button",{id:t.id,type:"button",className:"connector-group-picker-trigger","aria-label":t.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>g(d=>!d),children:[(0,o.jsx)("span",{className:h.length||t.multiple&&t.allLabel?"":"muted",children:C}),(0,o.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,o.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,o.jsxs)("label",{className:"connector-group-search",htmlFor:`${t.id}-search`,children:[(0,o.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,o.jsx)("input",{id:`${t.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:k,placeholder:t.searchPlaceholder,onChange:d=>L(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),g(!1))}})]}),(0,o.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":t.label,"aria-multiselectable":t.multiple||void 0,children:[t.multiple&&t.allLabel&&!y?(0,o.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${h.length===0?" selected":""}`,role:"option","aria-selected":h.length===0,onClick:()=>t.onChange([]),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:t.allLabel}),(0,o.jsx)("small",{children:t.placeholder})]})]}):null,R.map(d=>{let r=I.has(d.chatId);return(0,o.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(d.chatId),children:[(0,o.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:d.name||d.chatId}),d.name?(0,o.jsx)("small",{children:d.chatId}):null]})]},d.chatId)}),R.length?null:(0,o.jsx)("p",{className:"connector-group-empty",children:t.emptyLabel})]})]}):null]})}function me(t,e){return t.filter(s=>s.bots.includes(e))}function Ge(t,e){let s=t.target.chatId||"",g=s&&me(e,t.target.botId).some(k=>k.chatId===s);return{name:t.name,botId:t.target.botId,kind:t.target.kind,workflowId:t.target.workflowId||"",mode:t.target.mode,chatId:g?s:"",manualChat:!!(s&&!g),manualChatId:g?"":s,allowChats:t.target.allowChats||[],deduplicate:!!t.lifecycleExtractors?.dedupKey,dedup:t.lifecycleExtractors?.dedupKey||"",instruction:t.promptEnvelope?.instruction||"",topicMessageMode:t.topicMessage?.mode||"default",topicMessageText:t.topicMessage?.text||"",verify:t.verify?.type||"token",secret:"",storePayload:t.loggingPolicy?.storePayload!==!1}}function We(t){let e=W(),s=t.active==="webhooks",g=t.active==="logs";return(0,o.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,o.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,o.jsx)("a",{href:"#/connectors/logs",className:`itab${g?" on":""}`,role:"tab","aria-selected":g,children:e("connectors.tabLogs")})]})}function xe(t){let e=W(),s=(0,l.useRef)(!1),g=(0,l.useRef)(null),k=(0,l.useRef)(null),[L,h]=(0,l.useState)([]),[I,y]=(0,l.useState)([]),[R,C]=(0,l.useState)([]),[$,d]=(0,l.useState)(!0),[r,E]=(0,l.useState)(Me),[_,v]=(0,l.useState)(null),[U,O]=(0,l.useState)(null),[J,V]=(0,l.useState)(!1),[Y,q]=(0,l.useState)(!1),[P,X]=(0,l.useState)(null),[Z,T]=(0,l.useState)(null),[u,ee]=(0,l.useState)(null),B=(0,l.useMemo)(()=>me(I,r.botId),[I,r.botId]),be=(0,l.useMemo)(()=>L.length?L.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[L,e]),A=(0,l.useMemo)(()=>Be(e),[e]),pe=(0,l.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),he=(0,l.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),j=(0,l.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,l.useCallback)((a,i)=>{E(b=>{let N=b.botId&&a.some(D=>D.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",p=me(i,N),x=b.chatId&&p.some(D=>D.chatId===b.chatId)?b.chatId:p[0]?.chatId??"",G=new Set(p.map(D=>D.chatId));return{...b,botId:N,chatId:x,allowChats:b.allowChats.filter(D=>G.has(D))}})},[]),w=(0,l.useCallback)(async()=>{d(!0);try{let[a,i,b]=await Promise.all([H("/api/bots"),H("/api/connectors"),H("/api/groups")]);if(!s.current)return;let N=(a.body?.bots||[]).map(x=>({larkAppId:x.larkAppId,botName:x.botName||x.larkAppId})),p=(b.body?.chats||[]).map(x=>({chatId:x.chatId,name:x.name||"",bots:(x.memberBots||[]).filter(G=>G.inChat).map(G=>G.larkAppId)}));h(N),y(p),C(Array.isArray(i.body?.connectors)?i.body.connectors:[]),c(N,p)}finally{s.current&&d(!1)}},[c]);(0,l.useEffect)(()=>(s.current=!0,w(),()=>{s.current=!1,g.current&&clearTimeout(g.current)}),[w]),(0,l.useEffect)(()=>{let a=new Set(B.map(i=>i.chatId));E(i=>({...i,chatId:i.chatId&&a.has(i.chatId)?i.chatId:B[0]?.chatId??"",allowChats:i.allowChats.filter(b=>a.has(b))}))},[B]),(0,l.useEffect)(()=>{let a=k.current;if(a)if(Y){if(!a.open)try{a.showModal()}catch{}let i=a.querySelector(".connector-modal-body");i&&(i.scrollTop=0)}else a.open&&a.close()},[Y]),(0,l.useEffect)(()=>()=>{let a=k.current;a?.open&&a.close()},[]);function z(a){return e(a==="fixed"?"connectors.modeLabelFixed":a==="new-group"?"connectors.modeLabelNewGroup":"connectors.modeLabelDynamic")}function oe(a){return e(a==="workflow"?"connectors.kindLabelWorkflow":"connectors.kindLabelTurn")}function f(a){E(i=>({...i,...a}))}function F(){v(null),O(null),X(null),E(a=>{let i=a.botId||L[0]?.larkAppId||"";return{...Me,botId:i,chatId:me(I,i)[0]?.chatId||""}}),q(!0)}function te(a){v(null),O(null),T(null),X(a),E(Ge(a,I)),q(!0)}function S(){J||(q(!1),v(null),O(null),X(null))}async function ne(){v(null),O(null);let a=r.name.trim(),i=r.botId;if(!a){v({text:e("connectors.errName"),error:!0});return}if(!i){v({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){v({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if(r.topicMessageMode==="custom"&&!b){v({text:e("connectors.errTopicMessage"),error:!0});return}let N={name:a,enabled:P?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:i},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:{mode:r.topicMessageMode,...r.topicMessageMode==="custom"?{text:b}:{}},verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let p=r.manualChat?r.manualChatId.trim():r.chatId;if(!p){v({text:e("connectors.errChat"),error:!0});return}N.target.chatId=p}else r.mode==="dynamic"&&(N.target.allowChats=r.allowChats);if(r.mode==="new-group"){let p=r.dedup.trim();if(r.deduplicate&&!p){v({text:e("connectors.errDedup"),error:!0});return}N.lifecycleExtractors=r.deduplicate?{dedupKey:p}:null}else N.lifecycleExtractors=null;r.secret.trim()&&(N.secret=r.secret.trim()),V(!0),v({text:e(P?"connectors.saving":"connectors.creating")});try{let p=await Q(P?"PUT":"POST",P?`/api/connectors/${encodeURIComponent(P.id)}`:"/api/connectors",N);if(!s.current)return;if((p.status===201||p.status===200)&&p.body?.ok){if(P){let ye=P.id;C(De=>qe(De,p.body.connector)),T({id:ye,text:e("connectors.updated")}),q(!1),X(null);return}let x=p.body.webhookUrl||Ne(p.body.connector.id),G=(p.body.connector?.verify?.type??"token")==="token",D=r.mode==="dynamic",Ee=D?N.target.allowChats?.[0]||"<chatId>":"";v(null),O({name:a,mode:r.mode,chatId:N.target.chatId,url:x,secret:p.body.secret,isToken:G,isDynamic:D,exampleChat:Ee}),E(ye=>({...ye,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",allowChats:[],storePayload:!0})),await w()}else{let x=p.body?.error||p.status;v({text:e("connectors.createFailed",{error:String(x)}),error:!0})}}finally{s.current&&V(!1)}}async function ae(a){T({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let i=await Q("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(i.status===200&&i.body?.ok)T(null),await w();else{let b=i.body?.error||i.status;T({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function fe(a){let i=a.loggingPolicy?.storePayload!==!1;T({id:a.id,text:e("connectors.saving")});let b=await Q("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!i,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)T(null),await w();else{let N=b.body?.error||b.status;T({id:a.id,text:e("connectors.saveFailed",{error:String(N)}),error:!0})}}async function Se(a){if(!confirm(e("connectors.delConfirm")))return;T({id:a.id,text:e("connectors.deleting")});let i=await Q("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(i.status===200&&i.body?.ok)T(null),await w();else{let b=i.body?.error||i.status;T({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function Fe(a){navigator.clipboard?.writeText(Ne(a.id)),ee(a.id),g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{s.current&&ee(null)},1200)}return(0,o.jsxs)("section",{className:"page connectors-page",children:[(0,o.jsxs)("div",{className:"page-heading",children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,o.jsx)("h1",{children:e("nav.connectors")})]}),(0,o.jsx)("div",{className:"page-heading-actions",children:t.tab==="webhooks"?(0,o.jsx)(Le,{className:"page-primary-action connector-create-trigger",onClick:F,children:e("connectors.createTitle")}):(0,o.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,o.jsx)(We,{active:t.tab}),t.tab==="webhooks"?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("dialog",{ref:k,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),S()},onClose:S,onClick:a=>{a.target===a.currentTarget&&S()},children:(0,o.jsxs)("article",{className:"connector-modal-card",children:[(0,o.jsxs)("header",{className:"connector-modal-header",children:[(0,o.jsx)("h3",{children:e(P?"connectors.editTitle":"connectors.createTitle")}),(0,o.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:J,onClick:S,children:(0,o.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,o.jsx)("div",{className:"connector-modal-body",children:U?(0,o.jsx)(_e,{created:U,groupName:j}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"cn-form",children:[(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,o.jsx)(M,{children:e("connectors.fName")}),(0,o.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>f({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fBot")}),(0,o.jsx)(ge,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:be,onChange:a=>f({botId:a})})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fKind")}),(0,o.jsx)(ge,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:A,onChange:a=>f({kind:a})})]}),r.kind==="workflow"?(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,o.jsx)(M,{children:e("connectors.fWf")}),(0,o.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>f({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fMode")}),(0,o.jsx)(ge,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:pe,onChange:a=>f({mode:a})})]}),r.mode==="fixed"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsx)(M,{children:e("connectors.fFixedChat")}),(0,o.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,o.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>f({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,o.jsx)(Pe,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:B,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>f({chatId:a})}),(0,o.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>f({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,o.jsxs)(M,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)(Pe,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:B,value:r.allowChats,multiple:!0,allLabel:e("connectors.allowAll"),placeholder:e("connectors.allowAllHint"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>f({allowChats:a})})]}):null,r.mode==="dynamic"?(0,o.jsx)("div",{className:"cn-field-wide",children:(0,o.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,o.jsx)(M,{children:e("connectors.newGroupStrategy")}),(0,o.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>f({deduplicate:!1}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,o.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>f({deduplicate:!0}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,o.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,o.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,o.jsx)(M,{help:(0,o.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,o.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>f({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,o.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,o.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,o.jsxs)(M,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,o.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,o.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>f({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,o.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,o.jsx)(M,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,o.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","none"].map(a=>(0,o.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>f({topicMessageMode:a}),children:[(0,o.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("b",{children:e(`connectors.topicMessage${a==="default"?"Default":a==="custom"?"Custom":"None"}`)}),(0,o.jsx)("small",{children:e(`connectors.topicMessage${a==="default"?"DefaultHint":a==="custom"?"CustomHint":"NoneHint"}`)})]})]},a))}),r.topicMessageMode==="custom"?(0,o.jsxs)("label",{className:"connector-topic-message-input",htmlFor:"cn-topic-message",children:[(0,o.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>f({topicMessageText:a.currentTarget.value}),placeholder:e("connectors.topicMessageCustomPh")}),(0,o.jsxs)("small",{children:[e("connectors.topicMessageCustomHelp"),(0,o.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]})]}):(0,o.jsx)("p",{className:`connector-topic-message-preview${r.topicMessageMode==="none"?" muted":""}`,children:r.topicMessageMode==="none"?e("connectors.topicMessageNonePreview"):e("connectors.topicMessagePreview",{source:r.name.trim()||e("connectors.topicMessageSourceFallback")})})]}),(0,o.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,o.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>f({storePayload:a.currentTarget.checked})}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:e("connectors.storePayload")}),(0,o.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,o.jsxs)("div",{className:"cn-field",children:[(0,o.jsx)(M,{children:e("connectors.fVerify")}),(0,o.jsx)(ge,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:he,onChange:a=>f({verify:a})})]}),(0,o.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,o.jsx)(M,{children:e("connectors.fSecret")}),(0,o.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>f({secret:a.currentTarget.value}),placeholder:e(P?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),_?(0,o.jsx)("p",{className:`connector-create-message${_.error?" err":""}`,children:_.text}):null]})}),(0,o.jsxs)("footer",{className:"connector-modal-actions",children:[(0,o.jsx)("button",{type:"button",disabled:J,onClick:S,children:e("connectors.cancel")}),U?(0,o.jsx)("button",{type:"button",className:"primary",onClick:S,children:e("connectors.close")}):(0,o.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:J,onClick:()=>{ne()},children:e(P?"connectors.btnSave":"connectors.btnCreate")})]})]})}),(0,o.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,o.jsx)("div",{className:"card connector-list-card",children:$?(0,o.jsx)(le,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,o.jsx)(Ue,{connectors:R,bots:L,copiedId:u,editMsg:Z,groupName:j,modeLabel:z,kindLabel:oe,onCopy:Fe,onEdit:te,onToggle:a=>{ae(a)},onTogglePayloadLogging:a=>{fe(a)},onDelete:a=>{Se(a)}})})})]}):(0,o.jsx)(Te,{embedded:!0})]})}function _e(t){let e=W(),s=t.created,g=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,k=s.exampleChat!=="<chatId>"?`\uFF08${t.groupName(s.exampleChat)}\uFF09`:"";return(0,o.jsx)("div",{className:"connector-created-wrap",children:(0,o.jsxs)("div",{className:"card connector-created-card",children:[(0,o.jsxs)("p",{className:"connector-created-title ok",children:[e("connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,o.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:t.groupName(s.chatId)})]}):null]}),(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsx)("code",{children:s.url})]}),s.secret?(0,o.jsxs)("p",{className:"connector-created-line",children:[(0,o.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,o.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:k})}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,o.jsx)("pre",{children:(0,o.jsx)("code",{children:`curl -X POST '${g}' -H 'content-type: application/json' -d '{}'`})}),(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,o.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ue(t){let e=W();return t.connectors.length?(0,o.jsx)(o.Fragment,{children:t.connectors.map(s=>{let g=t.bots.find(C=>C.larkAppId===s.target.botId),k=Ne(s.id),L=(s.verify?.type??"token")==="token",h=e(L?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:t.groupName(s.target.chatId)}):"",y=t.editMsg?.id===s.id?t.editMsg:null,R=t.copiedId===s.id;return(0,o.jsxs)("div",{className:"card connector-item-card",children:[(0,o.jsxs)("div",{className:"connector-item-head",children:[(0,o.jsxs)("div",{className:"connector-item-main",children:[(0,o.jsxs)("div",{className:"connector-item-title",children:[(0,o.jsx)("b",{children:s.name}),(0,o.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,o.jsxs)("div",{className:"connector-item-meta",children:[(0,o.jsx)("span",{children:g?.botName||s.target.botId}),(0,o.jsx)("span",{children:t.kindLabel(s.target.kind)}),(0,o.jsx)("span",{children:t.modeLabel(s.target.mode)}),I?(0,o.jsx)("span",{children:I}):null,(0,o.jsx)("span",{children:h}),(0,o.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,o.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>t.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,o.jsxs)("div",{className:"connector-url-row",children:[(0,o.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,o.jsxs)("code",{children:[k,L?"/<token>":""]})]}),L?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,o.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,o.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,o.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,o.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),y?(0,o.jsx)("div",{className:y.error?"err connector-item-note":"muted connector-item-note",children:y.text}):null,(0,o.jsxs)("div",{className:"connector-item-actions",children:[(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onEdit(s),children:e("connectors.btnEdit")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,o.jsx)("button",{className:"ghost",type:"button",onClick:()=>t.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,o.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function to(t){return se(t,(0,o.jsx)(xe,{tab:"webhooks"}))}function no(t){return se(t,(0,o.jsx)(xe,{tab:"logs"}))}export{oo as buildConnectorInstructionUpdateBody,Be as buildConnectorKindOptions,no as renderConnectorsLogsPage,to as renderConnectorsPage,qe as replaceConnectorById};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as fe,b as he,c as ve,d as be}from"./chunk-R3FXBFQH.js";import{b as me}from"./chunk-FYALHCPG.js";import{c as Z,g as X,h as le,l as ce,m as ue,n as de,o as pe,p as ge}from"./chunk-I35DXGM4.js";import{c as j,d as J,s as z,v as ae,x as ne}from"./chunk-6QHMLMIM.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Le,d as ie}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K(Le(),1);var $e=/^[A-Za-z0-9._-]{1,64}$/,we=6,ye=30;function Y(o,t){return ve(o,t)}function ke(o,t,r=ye){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):ye,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,d=Math.min(c,Math.max(1,s)),f=(d-1)*n,I=Math.min(a,f+n);return{rows:o.slice(f,I),page:d,totalPages:c,from:a===0?0:f+1,to:I,total:a}}async function Pe(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function Q(o){return $e.test(o)&&o!=="."&&o!==".."}function ee(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return Q(t)?t:"profile"}async function V(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Ce(o){let t=await V(),r=await Pe(t,we,async s=>{try{let f=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let d of s.memberBots??[]){if(!d?.inChat||!d?.hasRole||!d?.larkAppId)continue;let f=Y(d.larkAppId,s.chatId);n.has(f)||(n.add(f),a.push({chatId:s.chatId,larkAppId:d.larkAppId}))}let c=await be(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Ie(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Pe(t,we,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,d=c?String(s??"").trim():"",f=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:d,status:d?f??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Se(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Ne(o,t){let r=t.q.trim().toLowerCase();return o.filter(n=>!r||(n.name??"").toLowerCase().includes(r)||n.chatId.toLowerCase().includes(r)||(n.ownerId??"").toLowerCase().includes(r)).filter(n=>!t.missingOnly||(n.memberBots??[]).some(a=>!a.inChat))}function Re(o,t){if(t.size===0)return!0;let r=o?.memberBots??[];for(let n of t)if(!r.some(a=>a.larkAppId===n&&a.inChat))return!1;return!0}function xe(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Ae(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:z("groups.roleProfileBootstrapDone",{name:n})}}function Ge(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(d=>({larkAppId:d.larkAppId,botName:d.botName,inChat:c.has(d.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(d=>d.chatId!==t)]}}var e=K(ie(),1);function Be(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Me(o){let t={};for(let r of ae(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function Oe(o){let t=o.chat,r=t.avatar??ne(t.chatId),[n,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:Me(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function te(o){return(0,e.jsxs)("p",{className:"hint-warn",children:[(0,e.jsx)("strong",{children:o.title}),(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:String(o.reason??"unknown")})]})}function Te(o){return(0,e.jsx)(e.Fragment,{children:Se(o.bots,o.excludeIds).map(t=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"bot",value:t.larkAppId}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]})]},t.larkAppId))})}function De(o){let t=o.summary;return t.rows.length?(0,e.jsxs)("div",{className:t.failed?"hint-warn":"hint-ok",children:[(0,e.jsxs)("strong",{children:["\u6DFB\u52A0\u7ED3\u679C\uFF1A\u6210\u529F ",t.okCount,"/",t.rows.length,t.failed?`\uFF0C\u5931\u8D25 ${t.failed}`:""]}),(0,e.jsx)("ul",{children:t.rows.map((r,n)=>{let a=String(r?.id??"?");return(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a}),": ",r?.ok?"OK":`failed (${String(r?.error??"unknown")})`]},`${a}-${n}`)})})]}):(0,e.jsx)("p",{className:"hint-warn",children:"\u6CA1\u6709\u8FD4\u56DE\u6DFB\u52A0\u7ED3\u679C\u3002"})}function Fe(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let f of t.memberBots??[])f?.inChat&&a.set(f.larkAppId,r.groupRoleContentByBot.get(Y(f.larkAppId,t.chatId))??null);if(!fe(a))return null;let s=he(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let d=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(d,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function je(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function Ue(o,t){switch(o){case"in":return t("groups.botStatusIn");case"out":return t("groups.botStatusOut");case"error":return t("groups.botStatusError");default:return t("groups.botStatusUnknown")}}function He(o){let t=new Map((o.chat.memberBots??[]).map(r=>[r.larkAppId,r]));return(0,e.jsx)("div",{className:"groups-bot-strip","aria-label":o.tr("groups.botCoverage"),children:o.bots.map(r=>{let n=t.get(r.larkAppId),a=je(n),c=Ue(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var _e=(0,i.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ue,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(Oe,{chat:r}),(0,e.jsxs)(de,{children:[(0,e.jsxs)("div",{className:"groups-row-head",children:[(0,e.jsx)("b",{children:r.name??r.chatId}),(0,e.jsxs)("span",{className:"groups-row-meta",children:[(0,e.jsx)("span",{className:"groups-row-tag",children:(0,e.jsx)("code",{children:r.chatId})}),r.ownerId?(0,e.jsxs)("span",{className:"groups-row-tag groups-row-owner-tag",children:[(0,e.jsx)("span",{children:n("groups.owner")}),(0,e.jsx)("code",{children:r.ownerId})]}):null]})]}),(0,e.jsx)(Fe,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(He,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(pe,{children:[(0,e.jsx)(X,{className:"add-bots",onClick:()=>t.onAddBots(r),children:n("groups.addBots")}),(0,e.jsx)("button",{className:"save-profile",type:"button",onClick:()=>t.onSaveProfile(r),children:n("groups.saveAsProfile")}),(0,e.jsx)("button",{className:"manage-chat",type:"button",onClick:()=>t.onManage(r),children:n("groups.manage")})]})]})]})});function We(o){let{tr:t}=o,[r,n]=(0,i.useState)(!1),[a,c]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)("");async function w(u){u.preventDefault();let v=new FormData(u.currentTarget),g=String(v.get("name")??"").trim(),y=String(v.get("bindWorkingDir")??"").trim(),C=String(v.get("roleProfileId")??"").trim(),x=v.getAll("bot");if(x.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let P=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:g||void 0,larkAppIds:x,bindWorkingDir:y||void 0,roleProfileId:C||void 0})}),S=await P.json().catch(()=>({ok:!1,error:`HTTP ${P.status}`}));S.ok&&S.chatId?(d(S),o.onCreated(S,x,g)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:S.error??`HTTP ${P.status}`}),n(!1))}catch(P){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:P}),n(!1)}}if(s){let u=String(s.chatId),v=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(u)}`,g=s.invalidBotIds??[],y=s.invalidUserIds??[],C=Array.isArray(s.oncallBindings)?s.oncallBindings:[],x=C.filter(R=>R?.ok).length,P=C.filter(R=>!R?.ok),S=Ae(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:u})," ",(0,e.jsx)("button",{type:"button","data-copy":u,onClick:()=>{navigator.clipboard.writeText(u),I(!0),o.setTimer(()=>I(!1),800)},children:t(f?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),(0,e.jsx)(Je,{resp:s}),C.length>0?P.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",x,"/",C.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",x,"/",C.length,"\u3002",P.map((R,A)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(R?.larkAppId??"?")}),": ",String(R?.error??"unknown")]},`${R?.larkAppId??"?"}-${A}`))]}):null,S?(0,e.jsx)("p",{className:S.kind==="ok"?"hint-ok":"hint-warn",children:S.text}):null,g.length||y.length?(0,e.jsxs)("ul",{children:[g.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:g.join(", ")})]}):null,y.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:y.join(", ")})]}):null]}):null,(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-close",onClick:o.onClose,children:t("sessions.dismiss")}),(0,e.jsx)("a",{className:"btn-link primary",href:v,target:"_blank",rel:"noopener",children:t("groups.openGroup")})]})]})}return(0,e.jsxs)("article",{className:"g-create-dialog",children:[(0,e.jsxs)("header",{className:"g-create-head",children:[(0,e.jsx)("h3",{children:t("groups.createTitle")}),(0,e.jsx)("p",{children:t("groups.createHelp")})]}),(0,e.jsxs)("form",{id:"g-createform",className:"g-create-form",onSubmit:u=>{w(u)},children:[(0,e.jsxs)("fieldset",{className:"g-modal-field g-create-bots",children:[(0,e.jsx)("legend",{children:t("groups.botPicker")}),(0,e.jsx)("div",{className:"g-bot-picker",children:(0,e.jsx)(Te,{bots:o.bots})})]}),(0,e.jsxs)("div",{className:"g-create-fields",children:[(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.name")}),(0,e.jsx)("input",{type:"text",name:"name",placeholder:t("groups.namePlaceholder"),maxLength:60})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.bindDir")}),(0,e.jsx)("input",{type:"text",name:"bindWorkingDir",placeholder:"e.g. ~/projects/botmux"}),(0,e.jsx)("small",{children:t("groups.bindDirHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-profile-field",children:[(0,e.jsx)("legend",{children:t("groups.roleProfile")}),(0,e.jsx)("input",{type:"hidden",name:"roleProfileId",value:p}),(0,e.jsx)(ge,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:p||t("groups.roleProfileNone"),value:p,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(u=>({value:u.profileId,label:u.profileId}))],onChange:h}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]})]}),(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(te,{...a}):null}),(0,e.jsxs)("div",{className:"actions g-create-actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:r,children:r?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("i",{className:"button-spinner","aria-hidden":"true"}),t("groups.createSubmitting")]}):t("groups.createSubmit")})]})]})]})}function Je(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,d=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8 @ \u901A\u77E5\u5931\u8D25\uFF08",d,"\uFF09\uFF0C\u65B0\u7FA4\u53EF\u80FD\u4E0D\u4F1A\u4E3B\u52A8\u51FA\u73B0\u5728\u4F60\u4FA7\u8FB9\u680F\uFF0C\u5EFA\u8BAE\u4ECE\u4E0B\u9762\u6309\u94AE\u8DF3\u8FDB\u53BB\u3002"]})]}):null]}):n?(0,e.jsxs)("p",{className:"hint-warn",children:["\u98DE\u4E66\u62D2\u7EDD\u4E86\u81EA\u52A8\u9080\u8BF7\uFF08\u4F60\u7684 open_id \u5728\u521B\u5EFA\u8005 bot \u7684 scope \u4E0B\u4E0D\u53EF\u7528\uFF09\u3002",(0,e.jsx)("strong",{children:"\u4F60\u76EE\u524D\u4E0D\u662F\u65B0\u7FA4\u6210\u5458"}),"\uFF0C\u9700\u8981\u8BA9\u7FA4\u91CC\u7684\u67D0\u4E2A\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u6765\u3002"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u6CA1\u5728 dashboard \u7F13\u5B58\u91CC\u627E\u5230 ownerOpenId\uFF0C",(0,e.jsx)("strong",{children:"\u6CA1\u6709\u81EA\u52A8\u9080\u8BF7\u4F60"}),"\u3002\u70B9\u5F00\u4E0B\u9762\u94FE\u63A5\u524D\uFF0C\u5148\u8BA9\u7FA4\u91CC\u4EFB\u4E00\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u53BB\u3002"]})}function ze(o){let{chat:t,tr:r}=o,[n,a]=(0,i.useState)(!1),[c,s]=(0,i.useState)(null),[d,f]=(0,i.useState)(null),I=(0,i.useMemo)(()=>new Set((t.memberBots??[]).filter(h=>h.inChat).map(h=>h.larkAppId)),[t]);async function p(h){h.preventDefault();let u=new FormData(h.currentTarget).getAll("bot");if(u.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),f(null);return}a(!0),s(null),f(null);try{let g=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:u})})).json();if(g.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(g.result){let y=xe(g.result);try{await o.onReloadGroups({force:!0}),f({result:y})}catch(C){f({result:y,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${C}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(g)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:h=>{p(h)},children:[(0,e.jsx)(Te,{bots:o.bots,excludeIds:I}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(te,{...c}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(De,{summary:d.result}),d.refreshError?(0,e.jsx)(te,{title:"\u5237\u65B0\u5931\u8D25",reason:d.refreshError}):null]}):null]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-cancel",onClick:o.onClose,children:r("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:n,children:n?"Adding...":r("groups.addBots")})]})]})]})}function Ve(o){let{tr:t}=o,[r,n]=(0,i.useState)([]),[a,c]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[f,I]=(0,i.useState)(null),p=(0,i.useMemo)(()=>[...a].sort((m,T)=>m.profileId.localeCompare(T.profileId)),[a]),h=p.length>0,w=r.filter(m=>m.status==="empty").length,u=r.filter(m=>m.status==="error").length,v=!s&&!f&&r.length>0&&u===0,[g,y]=(0,i.useState)("new"),[C,x]=(0,i.useState)(o.suggestedProfileId),[P,S]=(0,i.useState)(""),[R,A]=(0,i.useState)(!1),[_,G]=(0,i.useState)(null),B=g==="overwrite"?P:C.trim(),D=t(g==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=f||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?w?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:w}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,i.useEffect)(()=>{let m=!0;return d(!0),I(null),G(null),(async()=>{try{let[T,L]=await Promise.all([Ie(o.chat),V().catch(()=>[])]);if(!m)return;let M=[...L].sort((O,U)=>O.profileId.localeCompare(U.profileId));n(T),c(L),S(O=>M.some(U=>U.profileId===O)?O:M[0]?.profileId??"")}catch(T){if(!m)return;n([]),c([]),S(""),I(T instanceof Error?T.message:String(T))}finally{m&&d(!1)}})(),()=>{m=!1}},[o.chat]);async function $(m){if(m.preventDefault(),!!v){if(!Q(B)){G({text:t("groups.saveProfileInvalid"),className:"error"});return}A(!0),G({text:t("groups.saveProfileSaving")});try{let L=(await Promise.all(r.map(async M=>(await fetch(`/api/role-profiles/${encodeURIComponent(B)}/${encodeURIComponent(M.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:M.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(L!==r.length){G({text:t("groups.saveProfileFailed",{saved:L,total:r.length}),className:"error"}),A(!1);return}G({text:t("groups.saveProfileDone",{name:B,count:L}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(T){G({text:String(T),className:"error"}),A(!1)}}}function N(m){m==="overwrite"&&!h||(y(m),G(null))}return(0,e.jsxs)("article",{className:"g-save-profile-dialog",children:[(0,e.jsxs)("header",{children:[(0,e.jsx)("h3",{children:t("groups.saveProfileTitle")}),(0,e.jsx)("p",{children:t("groups.saveProfileIntro",{name:o.chat.name??o.chat.chatId,count:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:m=>{$(m)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Z,{label:t("common.loading")})}):f?(0,e.jsx)("div",{className:"g-save-profile-empty",children:f}):r.length?r.map(m=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${m.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:m.botName??m.larkAppId}),(0,e.jsx)("code",{children:m.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${m.status==="error"?"error":"ok"}`,children:t(m.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},m.larkAppId)):(0,e.jsx)("div",{className:"g-save-profile-empty",children:t("groups.saveProfileNoRoles")})})]}),(0,e.jsxs)("div",{className:"form-row",children:[(0,e.jsx)("span",{children:t("groups.saveProfileMode")}),(0,e.jsxs)("div",{className:"g-save-profile-switch",role:"tablist","aria-label":t("groups.saveProfileMode"),children:[(0,e.jsx)("button",{type:"button",className:g==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":g==="new",onClick:()=>N("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:g==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":g==="overwrite",disabled:!h,onClick:()=>N("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:g!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:C,maxLength:64,autoComplete:"off",onChange:m=>{x(m.currentTarget.value),G(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:g!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),h?(0,e.jsx)("div",{className:"g-save-profile-picker",children:p.map(m=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${m.profileId===P?"selected":""}`,"data-profile-id":m.profileId,"aria-pressed":m.profileId===P,onClick:()=>{S(m.profileId),y("overwrite"),G(null)},children:[(0,e.jsx)("span",{children:m.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:m.entryCount??0})})]},m.profileId))}):(0,e.jsx)("div",{className:"g-save-profile-summary warn",children:t("groups.saveProfileExistingEmpty")}),(0,e.jsx)("small",{children:t("groups.saveProfileOverwriteHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-target",children:[(0,e.jsx)("span",{children:t("groups.saveProfileTarget")}),(0,e.jsx)("code",{"data-save-profile-target":!0,children:B||"-"}),(0,e.jsx)("small",{"data-save-profile-target-mode":!0,children:t(g==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${v?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${_?.className??""}`,"data-save-profile-status":!0,children:_?.text??""}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-save-profile-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:!v||R||g==="overwrite"&&!P,children:R?t("groups.saveProfileSaving"):D})]})]})]})}function qe(o){let{member:t,tr:r}=o,n=(0,i.useRef)(null),[a,c]=(0,i.useState)(!!t.oncallChat),[s,d]=(0,i.useState)(t.oncallChat?.workingDir??""),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null);async function w(){h(null);let u=s.trim();if(a&&!u){h({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}I(!0);try{let v=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,g=a?await fetch(v,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(v,{method:"DELETE"}),y=await g.json().catch(()=>({}));if(g.ok&&y.ok){h({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${y.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else h({text:`\u2717 ${y.error??g.status}`,className:"hint-warn-inline"})}catch(v){h({text:`\u2717 ${v?.message??v}`,className:"hint-warn-inline"})}finally{I(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>d(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:f,onClick:()=>{w()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${p?.className??""}`,"data-status":!0,children:p?.text??""})]})]})}function Ke(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(p=>p.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,i.useState)(()=>new Set);function d(p,h){s(w=>{let u=new Set(w);return h?u.add(p):u.delete(p),u})}async function f(){let p=[...c];if(p.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${p.length} \u4E2A\u673A\u5668\u4EBA\u9000\u51FA\u7FA4\u804A\uFF1F\u8BE5 bot \u5728\u6B64\u7FA4\u7684\u4F1A\u8BDD\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))try{let w=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:p})})).json(),u=(w.result??[]).map(v=>{if(!v.ok)return`${v.larkAppId}: \u5931\u8D25 (${v.error??"unknown"})`;let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`\uFF08\u5173\u95ED ${C} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${C} \u4E2A\uFF0C${y} \u4E2A\u5931\u8D25\uFF09`;return`${v.larkAppId}: OK${x}`}).join(`
|
|
1
|
+
import{a as fe,b as he,c as ve,d as be}from"./chunk-R3FXBFQH.js";import{b as me}from"./chunk-P6GO5KT4.js";import{c as Z,g as X,h as le,l as ce,m as ue,n as de,o as pe,p as ge}from"./chunk-QFMH6ITB.js";import{c as j,d as J,s as z,v as ae,x as ne}from"./chunk-CUV65BIQ.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Le,d as ie}from"./chunk-5THX4DI2.js";import{c as K}from"./chunk-7SZRL6FY.js";var i=K(Le(),1);var $e=/^[A-Za-z0-9._-]{1,64}$/,we=6,ye=30;function Y(o,t){return ve(o,t)}function ke(o,t,r=ye){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):ye,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,d=Math.min(c,Math.max(1,s)),f=(d-1)*n,I=Math.min(a,f+n);return{rows:o.slice(f,I),page:d,totalPages:c,from:a===0?0:f+1,to:I,total:a}}async function Pe(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function Q(o){return $e.test(o)&&o!=="."&&o!==".."}function ee(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return Q(t)?t:"profile"}async function V(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Ce(o){let t=await V(),r=await Pe(t,we,async s=>{try{let f=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(f.entries)?f.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let d of s.memberBots??[]){if(!d?.inChat||!d?.hasRole||!d?.larkAppId)continue;let f=Y(d.larkAppId,s.chatId);n.has(f)||(n.add(f),a.push({chatId:s.chatId,larkAppId:d.larkAppId}))}let c=await be(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function Ie(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Pe(t,we,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,d=c?String(s??"").trim():"",f=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:d,status:d?f??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Se(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Ne(o,t){let r=t.q.trim().toLowerCase();return o.filter(n=>!r||(n.name??"").toLowerCase().includes(r)||n.chatId.toLowerCase().includes(r)||(n.ownerId??"").toLowerCase().includes(r)).filter(n=>!t.missingOnly||(n.memberBots??[]).some(a=>!a.inChat))}function Re(o,t){if(t.size===0)return!0;let r=o?.memberBots??[];for(let n of t)if(!r.some(a=>a.larkAppId===n&&a.inChat))return!1;return!0}function xe(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Ae(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:z("groups.roleProfileBootstrapDone",{name:n})}}function Ge(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(d=>({larkAppId:d.larkAppId,botName:d.botName,inChat:c.has(d.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(d=>d.chatId!==t)]}}var e=K(ie(),1);function Be(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Me(o){let t={};for(let r of ae(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function Oe(o){let t=o.chat,r=t.avatar??ne(t.chatId),[n,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:Me(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function te(o){return(0,e.jsxs)("p",{className:"hint-warn",children:[(0,e.jsx)("strong",{children:o.title}),(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:String(o.reason??"unknown")})]})}function Te(o){return(0,e.jsx)(e.Fragment,{children:Se(o.bots,o.excludeIds).map(t=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"bot",value:t.larkAppId}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]})]},t.larkAppId))})}function De(o){let t=o.summary;return t.rows.length?(0,e.jsxs)("div",{className:t.failed?"hint-warn":"hint-ok",children:[(0,e.jsxs)("strong",{children:["\u6DFB\u52A0\u7ED3\u679C\uFF1A\u6210\u529F ",t.okCount,"/",t.rows.length,t.failed?`\uFF0C\u5931\u8D25 ${t.failed}`:""]}),(0,e.jsx)("ul",{children:t.rows.map((r,n)=>{let a=String(r?.id??"?");return(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a}),": ",r?.ok?"OK":`failed (${String(r?.error??"unknown")})`]},`${a}-${n}`)})})]}):(0,e.jsx)("p",{className:"hint-warn",children:"\u6CA1\u6709\u8FD4\u56DE\u6DFB\u52A0\u7ED3\u679C\u3002"})}function Fe(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let f of t.memberBots??[])f?.inChat&&a.set(f.larkAppId,r.groupRoleContentByBot.get(Y(f.larkAppId,t.chatId))??null);if(!fe(a))return null;let s=he(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let d=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(d,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function je(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function Ue(o,t){switch(o){case"in":return t("groups.botStatusIn");case"out":return t("groups.botStatusOut");case"error":return t("groups.botStatusError");default:return t("groups.botStatusUnknown")}}function He(o){let t=new Map((o.chat.memberBots??[]).map(r=>[r.larkAppId,r]));return(0,e.jsx)("div",{className:"groups-bot-strip","aria-label":o.tr("groups.botCoverage"),children:o.bots.map(r=>{let n=t.get(r.larkAppId),a=je(n),c=Ue(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var _e=(0,i.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(ue,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(Oe,{chat:r}),(0,e.jsxs)(de,{children:[(0,e.jsxs)("div",{className:"groups-row-head",children:[(0,e.jsx)("b",{children:r.name??r.chatId}),(0,e.jsxs)("span",{className:"groups-row-meta",children:[(0,e.jsx)("span",{className:"groups-row-tag",children:(0,e.jsx)("code",{children:r.chatId})}),r.ownerId?(0,e.jsxs)("span",{className:"groups-row-tag groups-row-owner-tag",children:[(0,e.jsx)("span",{children:n("groups.owner")}),(0,e.jsx)("code",{children:r.ownerId})]}):null]})]}),(0,e.jsx)(Fe,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(He,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(pe,{children:[(0,e.jsx)(X,{className:"add-bots",onClick:()=>t.onAddBots(r),children:n("groups.addBots")}),(0,e.jsx)("button",{className:"save-profile",type:"button",onClick:()=>t.onSaveProfile(r),children:n("groups.saveAsProfile")}),(0,e.jsx)("button",{className:"manage-chat",type:"button",onClick:()=>t.onManage(r),children:n("groups.manage")})]})]})]})});function We(o){let{tr:t}=o,[r,n]=(0,i.useState)(!1),[a,c]=(0,i.useState)(null),[s,d]=(0,i.useState)(null),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)("");async function w(u){u.preventDefault();let v=new FormData(u.currentTarget),g=String(v.get("name")??"").trim(),y=String(v.get("bindWorkingDir")??"").trim(),C=String(v.get("roleProfileId")??"").trim(),x=v.getAll("bot");if(x.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let P=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:g||void 0,larkAppIds:x,bindWorkingDir:y||void 0,roleProfileId:C||void 0})}),S=await P.json().catch(()=>({ok:!1,error:`HTTP ${P.status}`}));S.ok&&S.chatId?(d(S),o.onCreated(S,x,g)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:S.error??`HTTP ${P.status}`}),n(!1))}catch(P){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:P}),n(!1)}}if(s){let u=String(s.chatId),v=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(u)}`,g=s.invalidBotIds??[],y=s.invalidUserIds??[],C=Array.isArray(s.oncallBindings)?s.oncallBindings:[],x=C.filter(R=>R?.ok).length,P=C.filter(R=>!R?.ok),S=Ae(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:u})," ",(0,e.jsx)("button",{type:"button","data-copy":u,onClick:()=>{navigator.clipboard.writeText(u),I(!0),o.setTimer(()=>I(!1),800)},children:t(f?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),(0,e.jsx)(Je,{resp:s}),C.length>0?P.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",x,"/",C.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",x,"/",C.length,"\u3002",P.map((R,A)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(R?.larkAppId??"?")}),": ",String(R?.error??"unknown")]},`${R?.larkAppId??"?"}-${A}`))]}):null,S?(0,e.jsx)("p",{className:S.kind==="ok"?"hint-ok":"hint-warn",children:S.text}):null,g.length||y.length?(0,e.jsxs)("ul",{children:[g.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:g.join(", ")})]}):null,y.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:y.join(", ")})]}):null]}):null,(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-close",onClick:o.onClose,children:t("sessions.dismiss")}),(0,e.jsx)("a",{className:"btn-link primary",href:v,target:"_blank",rel:"noopener",children:t("groups.openGroup")})]})]})}return(0,e.jsxs)("article",{className:"g-create-dialog",children:[(0,e.jsxs)("header",{className:"g-create-head",children:[(0,e.jsx)("h3",{children:t("groups.createTitle")}),(0,e.jsx)("p",{children:t("groups.createHelp")})]}),(0,e.jsxs)("form",{id:"g-createform",className:"g-create-form",onSubmit:u=>{w(u)},children:[(0,e.jsxs)("fieldset",{className:"g-modal-field g-create-bots",children:[(0,e.jsx)("legend",{children:t("groups.botPicker")}),(0,e.jsx)("div",{className:"g-bot-picker",children:(0,e.jsx)(Te,{bots:o.bots})})]}),(0,e.jsxs)("div",{className:"g-create-fields",children:[(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.name")}),(0,e.jsx)("input",{type:"text",name:"name",placeholder:t("groups.namePlaceholder"),maxLength:60})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field",children:[(0,e.jsx)("legend",{children:t("groups.bindDir")}),(0,e.jsx)("input",{type:"text",name:"bindWorkingDir",placeholder:"e.g. ~/projects/botmux"}),(0,e.jsx)("small",{children:t("groups.bindDirHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-profile-field",children:[(0,e.jsx)("legend",{children:t("groups.roleProfile")}),(0,e.jsx)("input",{type:"hidden",name:"roleProfileId",value:p}),(0,e.jsx)(ge,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:p||t("groups.roleProfileNone"),value:p,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(u=>({value:u.profileId,label:u.profileId}))],onChange:h}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]})]}),(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(te,{...a}):null}),(0,e.jsxs)("div",{className:"actions g-create-actions",children:[(0,e.jsx)("button",{type:"button",id:"g-create-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:r,children:r?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("i",{className:"button-spinner","aria-hidden":"true"}),t("groups.createSubmitting")]}):t("groups.createSubmit")})]})]})]})}function Je(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,d=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8 @ \u901A\u77E5\u5931\u8D25\uFF08",d,"\uFF09\uFF0C\u65B0\u7FA4\u53EF\u80FD\u4E0D\u4F1A\u4E3B\u52A8\u51FA\u73B0\u5728\u4F60\u4FA7\u8FB9\u680F\uFF0C\u5EFA\u8BAE\u4ECE\u4E0B\u9762\u6309\u94AE\u8DF3\u8FDB\u53BB\u3002"]})]}):null]}):n?(0,e.jsxs)("p",{className:"hint-warn",children:["\u98DE\u4E66\u62D2\u7EDD\u4E86\u81EA\u52A8\u9080\u8BF7\uFF08\u4F60\u7684 open_id \u5728\u521B\u5EFA\u8005 bot \u7684 scope \u4E0B\u4E0D\u53EF\u7528\uFF09\u3002",(0,e.jsx)("strong",{children:"\u4F60\u76EE\u524D\u4E0D\u662F\u65B0\u7FA4\u6210\u5458"}),"\uFF0C\u9700\u8981\u8BA9\u7FA4\u91CC\u7684\u67D0\u4E2A\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u6765\u3002"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u6CA1\u5728 dashboard \u7F13\u5B58\u91CC\u627E\u5230 ownerOpenId\uFF0C",(0,e.jsx)("strong",{children:"\u6CA1\u6709\u81EA\u52A8\u9080\u8BF7\u4F60"}),"\u3002\u70B9\u5F00\u4E0B\u9762\u94FE\u63A5\u524D\uFF0C\u5148\u8BA9\u7FA4\u91CC\u4EFB\u4E00\u673A\u5668\u4EBA\u624B\u52A8\u628A\u4F60\u52A0\u8FDB\u53BB\u3002"]})}function ze(o){let{chat:t,tr:r}=o,[n,a]=(0,i.useState)(!1),[c,s]=(0,i.useState)(null),[d,f]=(0,i.useState)(null),I=(0,i.useMemo)(()=>new Set((t.memberBots??[]).filter(h=>h.inChat).map(h=>h.larkAppId)),[t]);async function p(h){h.preventDefault();let u=new FormData(h.currentTarget).getAll("bot");if(u.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),f(null);return}a(!0),s(null),f(null);try{let g=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:u})})).json();if(g.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(g.result){let y=xe(g.result);try{await o.onReloadGroups({force:!0}),f({result:y})}catch(C){f({result:y,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${C}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(g)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:h=>{p(h)},children:[(0,e.jsx)(Te,{bots:o.bots,excludeIds:I}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(te,{...c}):null,d?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(De,{summary:d.result}),d.refreshError?(0,e.jsx)(te,{title:"\u5237\u65B0\u5931\u8D25",reason:d.refreshError}):null]}):null]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-cancel",onClick:o.onClose,children:r("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:n,children:n?"Adding...":r("groups.addBots")})]})]})]})}function Ve(o){let{tr:t}=o,[r,n]=(0,i.useState)([]),[a,c]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[f,I]=(0,i.useState)(null),p=(0,i.useMemo)(()=>[...a].sort((m,T)=>m.profileId.localeCompare(T.profileId)),[a]),h=p.length>0,w=r.filter(m=>m.status==="empty").length,u=r.filter(m=>m.status==="error").length,v=!s&&!f&&r.length>0&&u===0,[g,y]=(0,i.useState)("new"),[C,x]=(0,i.useState)(o.suggestedProfileId),[P,S]=(0,i.useState)(""),[R,A]=(0,i.useState)(!1),[_,G]=(0,i.useState)(null),B=g==="overwrite"?P:C.trim(),D=t(g==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=f||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?w?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:w}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,i.useEffect)(()=>{let m=!0;return d(!0),I(null),G(null),(async()=>{try{let[T,L]=await Promise.all([Ie(o.chat),V().catch(()=>[])]);if(!m)return;let M=[...L].sort((O,U)=>O.profileId.localeCompare(U.profileId));n(T),c(L),S(O=>M.some(U=>U.profileId===O)?O:M[0]?.profileId??"")}catch(T){if(!m)return;n([]),c([]),S(""),I(T instanceof Error?T.message:String(T))}finally{m&&d(!1)}})(),()=>{m=!1}},[o.chat]);async function $(m){if(m.preventDefault(),!!v){if(!Q(B)){G({text:t("groups.saveProfileInvalid"),className:"error"});return}A(!0),G({text:t("groups.saveProfileSaving")});try{let L=(await Promise.all(r.map(async M=>(await fetch(`/api/role-profiles/${encodeURIComponent(B)}/${encodeURIComponent(M.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:M.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(L!==r.length){G({text:t("groups.saveProfileFailed",{saved:L,total:r.length}),className:"error"}),A(!1);return}G({text:t("groups.saveProfileDone",{name:B,count:L}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(T){G({text:String(T),className:"error"}),A(!1)}}}function N(m){m==="overwrite"&&!h||(y(m),G(null))}return(0,e.jsxs)("article",{className:"g-save-profile-dialog",children:[(0,e.jsxs)("header",{children:[(0,e.jsx)("h3",{children:t("groups.saveProfileTitle")}),(0,e.jsx)("p",{children:t("groups.saveProfileIntro",{name:o.chat.name??o.chat.chatId,count:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:m=>{$(m)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Z,{label:t("common.loading")})}):f?(0,e.jsx)("div",{className:"g-save-profile-empty",children:f}):r.length?r.map(m=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${m.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:m.botName??m.larkAppId}),(0,e.jsx)("code",{children:m.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${m.status==="error"?"error":"ok"}`,children:t(m.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},m.larkAppId)):(0,e.jsx)("div",{className:"g-save-profile-empty",children:t("groups.saveProfileNoRoles")})})]}),(0,e.jsxs)("div",{className:"form-row",children:[(0,e.jsx)("span",{children:t("groups.saveProfileMode")}),(0,e.jsxs)("div",{className:"g-save-profile-switch",role:"tablist","aria-label":t("groups.saveProfileMode"),children:[(0,e.jsx)("button",{type:"button",className:g==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":g==="new",onClick:()=>N("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:g==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":g==="overwrite",disabled:!h,onClick:()=>N("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:g!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:C,maxLength:64,autoComplete:"off",onChange:m=>{x(m.currentTarget.value),G(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:g!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),h?(0,e.jsx)("div",{className:"g-save-profile-picker",children:p.map(m=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${m.profileId===P?"selected":""}`,"data-profile-id":m.profileId,"aria-pressed":m.profileId===P,onClick:()=>{S(m.profileId),y("overwrite"),G(null)},children:[(0,e.jsx)("span",{children:m.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:m.entryCount??0})})]},m.profileId))}):(0,e.jsx)("div",{className:"g-save-profile-summary warn",children:t("groups.saveProfileExistingEmpty")}),(0,e.jsx)("small",{children:t("groups.saveProfileOverwriteHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-target",children:[(0,e.jsx)("span",{children:t("groups.saveProfileTarget")}),(0,e.jsx)("code",{"data-save-profile-target":!0,children:B||"-"}),(0,e.jsx)("small",{"data-save-profile-target-mode":!0,children:t(g==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${v?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${_?.className??""}`,"data-save-profile-status":!0,children:_?.text??""}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",id:"g-save-profile-cancel",onClick:o.onClose,children:t("groups.cancel")}),(0,e.jsx)("button",{type:"submit",className:"primary",disabled:!v||R||g==="overwrite"&&!P,children:R?t("groups.saveProfileSaving"):D})]})]})]})}function qe(o){let{member:t,tr:r}=o,n=(0,i.useRef)(null),[a,c]=(0,i.useState)(!!t.oncallChat),[s,d]=(0,i.useState)(t.oncallChat?.workingDir??""),[f,I]=(0,i.useState)(!1),[p,h]=(0,i.useState)(null);async function w(){h(null);let u=s.trim();if(a&&!u){h({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}I(!0);try{let v=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,g=a?await fetch(v,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(v,{method:"DELETE"}),y=await g.json().catch(()=>({}));if(g.ok&&y.ok){h({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${y.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else h({text:`\u2717 ${y.error??g.status}`,className:"hint-warn-inline"})}catch(v){h({text:`\u2717 ${v?.message??v}`,className:"hint-warn-inline"})}finally{I(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>d(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:f,onClick:()=>{w()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${p?.className??""}`,"data-status":!0,children:p?.text??""})]})]})}function Ke(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(p=>p.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,i.useState)(()=>new Set);function d(p,h){s(w=>{let u=new Set(w);return h?u.add(p):u.delete(p),u})}async function f(){let p=[...c];if(p.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${p.length} \u4E2A\u673A\u5668\u4EBA\u9000\u51FA\u7FA4\u804A\uFF1F\u8BE5 bot \u5728\u6B64\u7FA4\u7684\u4F1A\u8BDD\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))try{let w=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:p})})).json(),u=(w.result??[]).map(v=>{if(!v.ok)return`${v.larkAppId}: \u5931\u8D25 (${v.error??"unknown"})`;let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`\uFF08\u5173\u95ED ${C} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${C} \u4E2A\uFF0C${y} \u4E2A\u5931\u8D25\uFF09`;return`${v.larkAppId}: OK${x}`}).join(`
|
|
2
2
|
`);alert(u||`Unexpected: ${JSON.stringify(w)}`),await o.onReloadGroups({force:!0})}catch(h){alert("Network error: "+h)}finally{o.onClose()}}async function I(){if(n.length===0||!confirm(`\u786E\u5B9A\u89E3\u6563\u7FA4\u804A\u300C${t.name??t.chatId}\u300D\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\uFF0C\u672C\u7FA4\u6240\u6709\u673A\u5668\u4EBA\u4F1A\u8BDD\u4E5F\u4F1A\u4E00\u5E76\u5173\u95ED\u3002`))return;let p=[...n].sort((w,u)=>(u.larkAppId===a?1:0)-(w.larkAppId===a?1:0)),h=[];for(let w of p)try{let u=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:w.larkAppId})}),v=await u.json();if(v.ok){let g=v.closedSessions??[],y=g.filter(P=>!P.ok).length,C=g.length-y,x=g.length===0?"":y===0?`
|
|
3
3
|
\u5173\u95ED\u4E86 ${C} \u4E2A\u4F1A\u8BDD\u3002`:`
|
|
4
4
|
\u5173\u95ED\u4E86 ${C} \u4E2A\u4F1A\u8BDD\uFF0C${y} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25\u3002`;alert(`\u5DF2\u89E3\u6563\uFF08\u7531 ${w.botName??w.larkAppId} \u6267\u884C\uFF09${x}`),await o.onReloadGroups({force:!0}),o.onClose();return}h.push(`${w.botName??w.larkAppId}: ${v.error??u.status}`)}catch(u){h.push(`${w.botName??w.larkAppId}: ${u}`)}alert(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A
|