botmux 3.12.1 → 3.13.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/.runtime-build-id +1 -1
- package/dist/bot-registry.d.ts +7 -0
- package/dist/bot-registry.d.ts.map +1 -1
- package/dist/bot-registry.js +46 -13
- package/dist/bot-registry.js.map +1 -1
- package/dist/core/config-dir.d.ts +167 -0
- package/dist/core/config-dir.d.ts.map +1 -0
- package/dist/core/config-dir.js +152 -0
- package/dist/core/config-dir.js.map +1 -0
- package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
- package/dist/core/dashboard-ipc-server.js +48 -0
- package/dist/core/dashboard-ipc-server.js.map +1 -1
- package/dist/core/per-bot-env.d.ts.map +1 -1
- package/dist/core/per-bot-env.js +9 -0
- package/dist/core/per-bot-env.js.map +1 -1
- package/dist/core/session-discovery.d.ts.map +1 -1
- package/dist/core/session-discovery.js +19 -2
- package/dist/core/session-discovery.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +44 -3
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/trigger-session.d.ts.map +1 -1
- package/dist/core/trigger-session.js +499 -63
- package/dist/core/trigger-session.js.map +1 -1
- package/dist/core/types.d.ts +26 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/worker-pool.d.ts +64 -0
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/core/worker-pool.js +301 -10
- package/dist/core/worker-pool.js.map +1 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +13 -6
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/auth.d.ts +8 -0
- package/dist/dashboard/auth.d.ts.map +1 -1
- package/dist/dashboard/auth.js +16 -11
- package/dist/dashboard/auth.js.map +1 -1
- package/dist/dashboard/web/bot-multi-select.d.ts +33 -0
- package/dist/dashboard/web/bot-multi-select.d.ts.map +1 -0
- package/dist/dashboard/web/bot-multi-select.js +34 -0
- package/dist/dashboard/web/bot-multi-select.js.map +1 -0
- package/dist/dashboard/web/groups-page.d.ts +13 -0
- package/dist/dashboard/web/groups-page.d.ts.map +1 -1
- package/dist/dashboard/web/groups-page.js +25 -7
- package/dist/dashboard/web/groups-page.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +8 -4
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/web/sessions-page.d.ts.map +1 -1
- package/dist/dashboard/web/sessions-page.js +15 -23
- package/dist/dashboard/web/sessions-page.js.map +1 -1
- package/dist/dashboard/web/sessions.d.ts +13 -0
- package/dist/dashboard/web/sessions.d.ts.map +1 -1
- package/dist/dashboard/web/sessions.js +25 -0
- package/dist/dashboard/web/sessions.js.map +1 -1
- package/dist/dashboard-web/app.js +1 -1
- package/dist/dashboard-web/chunks/{bot-defaults-page-HL655CNR.js → bot-defaults-page-NQJFJ45Z.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-BFUTTYVK.js → chunk-5QJB24I2.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-ELL53D62.js → chunk-6JTZJRQJ.js} +2 -2
- package/dist/dashboard-web/chunks/{chunk-5ZL7NLR5.js → chunk-CU4SUKK3.js} +1 -1
- package/dist/dashboard-web/chunks/{chunk-5PAYQ3KT.js → chunk-KEEYQ3WF.js} +1 -1
- package/dist/dashboard-web/chunks/chunk-WLIVBPJC.js +1 -0
- package/dist/dashboard-web/chunks/{connectors-page-3QQACF23.js → connectors-page-HADHZXXZ.js} +1 -1
- package/dist/dashboard-web/chunks/groups-page-5TYF46RS.js +8 -0
- package/dist/dashboard-web/chunks/{insights-page-ZZ3JEJ6L.js → insights-page-EVGGJI5L.js} +1 -1
- package/dist/dashboard-web/chunks/{monitor-room-ROJ5GZ4N.js → monitor-room-HRGR2ENP.js} +1 -1
- package/dist/dashboard-web/chunks/{monitoring-page-IATV7KJF.js → monitoring-page-LBU7TTTW.js} +1 -1
- package/dist/dashboard-web/chunks/{office-page-TYO5OIIT.js → office-page-DF6RRBMN.js} +1 -1
- package/dist/dashboard-web/chunks/{overview-page-VJUULZF2.js → overview-page-ZB6QH2EX.js} +1 -1
- package/dist/dashboard-web/chunks/{roles-page-7RJJKZGK.js → roles-page-ZBZGHIIF.js} +1 -1
- package/dist/dashboard-web/chunks/{schedules-page-JTEJ5IXW.js → schedules-page-NQVQC3QY.js} +1 -1
- package/dist/dashboard-web/chunks/sessions-page-DXBCDWCS.js +8 -0
- package/dist/dashboard-web/chunks/{settings-page-7CTTFBRS.js → settings-page-E7NN4NVQ.js} +1 -1
- package/dist/dashboard-web/chunks/{skills-page-57NZECJ3.js → skills-page-2QAVB2SA.js} +1 -1
- package/dist/dashboard-web/chunks/{team-federation-page-6YYIMJG3.js → team-federation-page-VGWL53AE.js} +1 -1
- package/dist/dashboard-web/chunks/{v3-page-ZGKBSBK3.js → v3-page-AY35LKCX.js} +1 -1
- package/dist/dashboard-web/chunks/{whiteboards-page-AACJF6DB.js → whiteboards-page-BNWUU4KG.js} +1 -1
- package/dist/dashboard-web/style.css +61 -53
- package/dist/features/codex-notifier/internal-turn.d.ts +1 -2
- package/dist/features/codex-notifier/internal-turn.d.ts.map +1 -1
- package/dist/features/codex-notifier/internal-turn.js +1 -13
- package/dist/features/codex-notifier/internal-turn.js.map +1 -1
- package/dist/i18n/en.js +2 -2
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.js +2 -2
- package/dist/i18n/zh.js.map +1 -1
- package/dist/platform/secure-host-file.d.ts +63 -0
- package/dist/platform/secure-host-file.d.ts.map +1 -1
- package/dist/platform/secure-host-file.js +90 -25
- package/dist/platform/secure-host-file.js.map +1 -1
- package/dist/services/async-trigger-store.d.ts +24 -4
- package/dist/services/async-trigger-store.d.ts.map +1 -1
- package/dist/services/async-trigger-store.js +81 -19
- package/dist/services/async-trigger-store.js.map +1 -1
- package/dist/services/codex-session-meta.d.ts +4 -0
- package/dist/services/codex-session-meta.d.ts.map +1 -0
- package/dist/services/codex-session-meta.js +15 -0
- package/dist/services/codex-session-meta.js.map +1 -0
- package/dist/services/idempotency-store.d.ts +18 -3
- package/dist/services/idempotency-store.d.ts.map +1 -1
- package/dist/services/idempotency-store.js +30 -12
- package/dist/services/idempotency-store.js.map +1 -1
- package/dist/services/traex-transcript.d.ts +7 -5
- package/dist/services/traex-transcript.d.ts.map +1 -1
- package/dist/services/traex-transcript.js +139 -33
- package/dist/services/traex-transcript.js.map +1 -1
- package/dist/services/trigger-types.d.ts +14 -1
- package/dist/services/trigger-types.d.ts.map +1 -1
- package/dist/services/trigger-types.js +35 -0
- package/dist/services/trigger-types.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/child-env.d.ts +1 -1
- package/dist/utils/child-env.d.ts.map +1 -1
- package/dist/utils/child-env.js +18 -0
- package/dist/utils/child-env.js.map +1 -1
- package/dist/worker.js +35 -2
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/dashboard-web/chunks/chunk-6ALR252E.js +0 -1
- package/dist/dashboard-web/chunks/groups-page-SDZMJ7UV.js +0 -8
- package/dist/dashboard-web/chunks/sessions-page-KD7HDT3U.js +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{q as T}from"./chunk-5CJMHTT4.js";import{u as t}from"./chunk-ELL53D62.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:"text",inputMode:"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),[R,M]=(0,r.useState)(""),[A,_]=(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]),j=(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)||j(F.id)}catch(u){w({kind:"job",job:{id:"",status:"failed",message:q(u)}})}finally{I(!1)}},[y,d.webSession,c,S,j,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:R,ownerIdInput:A,onOwnerInputChange:M,onOwnerIdInputChange:_,onSubmitOwner:V,onRetry:$,onClose:v}),[d,v,c,A,R,$,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{q as T}from"./chunk-5CJMHTT4.js";import{u as t}from"./chunk-6JTZJRQJ.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:"text",inputMode:"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),[R,M]=(0,r.useState)(""),[A,_]=(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]),j=(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)||j(F.id)}catch(u){w({kind:"job",job:{id:"",status:"failed",message:q(u)}})}finally{I(!1)}},[y,d.webSession,c,S,j,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:R,ownerIdInput:A,onOwnerInputChange:M,onOwnerIdInputChange:_,onSubmitOwner:V,onRetry:$,onClose:v}),[d,v,c,A,R,$,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 +1 @@
|
|
|
1
|
-
import{a as n,t as s,u as i}from"./chunk-
|
|
1
|
+
import{a as n,t as s,u as i}from"./chunk-6JTZJRQJ.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,v as b,T as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as p,d as g}from"./chunk-5THX4DI2.js";import{c as s}from"./chunk-7SZRL6FY.js";var c=s(p(),1),a=s(g(),1);function k(t){let l=(0,c.useRef)(null),u=(0,c.useRef)(null),r=t.groups.find(e=>e.groupId===t.selectedId)?.name,o=t.newName.trim()?`\u65B0\u5EFA\u6807\u7B7E\uFF1A${t.newName.trim()}`:r||"\u4E0D\u9009\u62E9\u6807\u7B7E";(0,c.useEffect)(()=>{let e=m=>{let f=l.current;f?.open&&(m.target instanceof Node&&f.contains(m.target)||(f.open=!1))},i=m=>{m.key==="Escape"&&l.current?.open&&(l.current.open=!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",i),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",i)}},[]),(0,c.useEffect)(()=>{t.disabled&&l.current?.open&&(l.current.open=!1)},[t.disabled]);let d=(e,i)=>{t.onChange(e,i),l.current?.removeAttribute("open"),queueMicrotask(()=>u.current?.focus())};return(0,a.jsxs)("details",{ref:l,className:`feed-group-picker${t.disabled?" is-disabled":""}`,children:[(0,a.jsx)("summary",{ref:u,"aria-label":`\u98DE\u4E66\u6807\u7B7E\uFF0C\u5F53\u524D\uFF1A${o}`,"aria-disabled":t.disabled||void 0,tabIndex:t.disabled?-1:void 0,onClick:e=>{t.disabled&&e.preventDefault()},children:(0,a.jsx)("span",{children:o})}),(0,a.jsxs)("div",{className:"feed-group-picker-pop",children:[(0,a.jsxs)("label",{className:"feed-group-picker-new",children:[(0,a.jsx)("span",{children:"\u65B0\u5EFA\u6807\u7B7E"}),(0,a.jsx)("input",{type:"text",maxLength:60,value:t.newName,placeholder:"\u8F93\u5165\u65B0\u6807\u7B7E\u540D\u79F0",onChange:e=>t.onChange("",e.currentTarget.value.trimStart()),onKeyDown:e=>{e.key==="Enter"&&e.preventDefault()}})]}),(0,a.jsx)("button",{type:"button","aria-current":!t.selectedId&&!t.newName.trim()?"true":void 0,onClick:()=>d("",""),children:"\u4E0D\u9009\u62E9\u6807\u7B7E"}),t.groups.map(e=>(0,a.jsx)("button",{type:"button","aria-current":t.selectedId===e.groupId&&!t.newName.trim()?"true":void 0,onClick:()=>d(e.groupId,""),children:e.name},e.groupId))]})]})}var b=s(p(),1),n=s(g(),1);function y(t){let[l,u]=(0,b.useState)(""),r=l.trim().toLowerCase(),o=(0,b.useMemo)(()=>r?t.bots.filter(e=>(e.botName??e.larkAppId).toLowerCase().includes(r)||e.larkAppId.toLowerCase().includes(r)):t.bots,[t.bots,r]),d=t.selected.size;return t.bots.length?(0,n.jsxs)("div",{className:"bot-multi-select",children:[(0,n.jsx)("input",{className:"bot-multi-select-search",type:"search",placeholder:t.searchPlaceholder,"aria-label":t.searchPlaceholder,value:l,onChange:e=>u(e.currentTarget.value)}),o.length?(0,n.jsx)("div",{className:"bot-multi-select-list",role:"group",children:o.map(e=>(0,n.jsxs)("label",{className:"bot-multi-select-row",children:[(0,n.jsx)("input",{type:"checkbox",value:e.larkAppId,checked:t.selected.has(e.larkAppId),onChange:i=>t.onToggle(e.larkAppId,i.currentTarget.checked)}),(0,n.jsxs)("span",{className:"bot-multi-select-main",children:[(0,n.jsx)("strong",{children:e.botName??e.larkAppId}),(0,n.jsxs)("small",{children:["(",e.larkAppId,")"]})]})]},e.larkAppId))}):(0,n.jsx)("p",{className:"bot-multi-select-empty",children:t.noMatchLabel}),d?(0,n.jsx)("small",{className:"bot-multi-select-count",children:t.selectedCountLabel(d)}):null]}):(0,n.jsx)("p",{className:"bot-multi-select-empty",children:t.emptyLabel})}export{k as a,y as b};
|
package/dist/dashboard-web/chunks/{connectors-page-3QQACF23.js → connectors-page-HADHZXXZ.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as q,b as V}from"./chunk-EVK77ASG.js";import{a as ue}from"./chunk-ZJVTGU5X.js";import{c as _}from"./chunk-5PAYQ3KT.js";import{a as le,c as ie,g as Se,l as T,q as de}from"./chunk-5CJMHTT4.js";import"./chunk-ELL53D62.js";import{a as re}from"./chunk-SYC6D5XU.js";import{a as Pe,d as ce}from"./chunk-5THX4DI2.js";import{c as j}from"./chunk-7SZRL6FY.js";var i=j(Pe(),1);var p=j(Pe(),1);var n=j(ce(),1),Ge=50,Ne={total:0,ok:0,error:0,successRate:0};function We(o,e=Date.now()){if(o==="all")return;let s=o==="24h"?24:o==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function _e(o,e=0){let s=new URLSearchParams({limit:String(Ge),offset:String(e)});o.connectorId&&s.set("connectorId",o.connectorId),o.status&&s.set("status",o.status);let d=We(o.timeWindow);return d&&s.set("since",d),o.query.trim()&&s.set("q",o.query.trim()),s}function Fe(o){if(!o)return"\u2014";let e=new Date(o);return Number.isFinite(e.getTime())?e.toLocaleString():o}function ge(o){return o===void 0||!Number.isFinite(o)?"\u2014":o<1e3?`${Math.round(o)} ms`:o<6e4?`${(o/1e3).toFixed(o<1e4?1:0)} s`:`${(o/6e4).toFixed(1)} min`}function Ue(o){return o===void 0?"\u2014":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/1024/1024).toFixed(1)} MB`}function Le(o){return o.value===void 0||o.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):typeof o.value=="object"&&!Array.isArray(o.value)&&Object.keys(o.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${o.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(o.value,null,2)})})}function Je(o){let e=[["kind",o.value?.kind],["mode",o.value?.mode],["botId",o.value?.botId],["chatId",o.value?.chatId],["sessionId",o.value?.sessionId],["rootMessageId",o.value?.rootMessageId],["workflowId",o.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,d])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(d)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ie(o){return(0,n.jsx)(de,{id:o.id,className:"webhook-log-filter-menu",ariaLabel:o.label,style:{width:"100%",minWidth:0},value:o.value,label:le(o.options,o.value),options:o.options,onChange:o.onChange})}function me(o){return(0,n.jsxs)("article",{className:`card webhook-log-metric${o.tone?` ${o.tone}`:""}`,children:[(0,n.jsx)("span",{children:o.label}),(0,n.jsx)("strong",{children:o.value}),(0,n.jsx)("small",{children:o.hint||"\xA0"})]})}function Ee(o={}){let e=_(),s=(0,p.useRef)(!1),d=(0,p.useRef)([]),[f,N]=(0,p.useState)([]),[y,I]=(0,p.useState)([]),[k,R]=(0,p.useState)(Ne),[L,$]=(0,p.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[u,r]=(0,p.useState)(null),[E,U]=(0,p.useState)(!0),[w,J]=(0,p.useState)(!1),[A,X]=(0,p.useState)(!1),[Y,Z]=(0,p.useState)(0),[B,x]=(0,p.useState)(""),[K,ee]=(0,p.useState)(!1),M=(0,p.useMemo)(()=>new Map(f.map(c=>[c.id,c.name])),[f]),g=(0,p.useMemo)(()=>y.find(c=>c.triggerId===u)??y[0]??null,[y,u]),te=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...f.map(c=>({value:c.id,label:c.name}))],[f,e]),G=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),fe=(0,p.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]),H=(0,p.useCallback)(async(c=!1,v=!1)=>{v?J(!0):U(!0),x("");let Q=c?d.current.length:0,oe=_e(L,Q),h=new URLSearchParams(oe);h.delete("limit"),h.delete("offset");try{let[S,ne]=await Promise.all([q(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):q(`/api/trigger-logs/summary?${h}`)]);if(!s.current)return;if(S.status!==200)throw new Error(String(S.body?.error||S.status));let P=Array.isArray(S.body?.logs)?S.body.logs:[],ae=c?[...d.current,...P]:P;d.current=ae,I(ae),Z(Number(S.body?.total??P.length)),X(S.body?.hasMore===!0),c||(R(ne?.status===200?ne.body?.summary??Ne:Ne),r(se=>P.some(ve=>ve.triggerId===se)?se:P[0]?.triggerId??null))}catch(S){s.current&&x(S?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(U(!1),J(!1))}},[L,e]);(0,p.useEffect)(()=>(s.current=!0,q("/api/connectors").then(c=>{s.current&&c.status===200&&N(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,p.useEffect)(()=>{let c=setTimeout(()=>{H(!1)},L.query?260:0);return()=>clearTimeout(c)},[L,H]),(0,p.useEffect)(()=>{let c=setInterval(()=>{H(!1,!0)},15e3);return()=>clearInterval(c)},[H]);async function ye(){!g||!await ue(JSON.stringify(g,null,2),e("webhookLogs.copyJson"))||(ee(!0),setTimeout(()=>s.current&&ee(!1),1200))}let ke=g?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):g?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),z=(0,n.jsxs)(n.Fragment,{children:[o.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${w?" 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)(me,{label:e("webhookLogs.total"),value:k.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(me,{label:e("webhookLogs.successRate"),value:`${k.successRate.toFixed(k.successRate%1?1:0)}%`,tone:"ok",hint:`${k.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(me,{label:e("webhookLogs.failures"),value:k.error,tone:k.error?"error":void 0,hint:k.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(me,{label:e("webhookLogs.p95"),value:ge(k.p95DurationMs),hint:`${e("webhookLogs.average")} ${ge(k.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:L.query,onChange:c=>{let v=c.currentTarget.value;$(Q=>({...Q,query:v}))}}),(0,n.jsx)(Ie,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:L.connectorId,options:te,onChange:c=>$(v=>({...v,connectorId:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-status",label:e("webhookLogs.status"),value:L.status,options:G,onChange:c=>$(v=>({...v,status:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:L.timeWindow,options:fe,onChange:c=>$(v=>({...v,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:w,onClick:()=>{H(!1,!0)},children:e("webhookLogs.refresh")})]}),B?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",B]}):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:Y})})]})}),E&&!y.length?(0,n.jsx)(ie,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!y.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:y.map(c=>{let v=g?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":v,className:`webhook-log-row${v?" 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:M.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:Fe(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:ge(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{H(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:g?(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 ${g.status}`,children:g.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:M.get(g.connectorId||"")||g.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Fe(g.createdAt)," \xB7 ",g.request?.method||"POST"," ",g.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{ye()},children:e(K?"webhookLogs.copied":"webhookLogs.copyJson")})]}),g.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:g.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:g.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:g.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ge(g.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:g.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Ue(g.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.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:g.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:g.target?.chatId||g.target?.sessionId||g.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(Le,{value:g.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)(Le,{value:g.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")})]}),g.request?.payloadStored?(0,n.jsx)(Le,{value:g.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:ke})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Je,{value:g.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return o.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:z}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:z})}var t=j(ce(),1);function Xe(o,e){return o.map(s=>s.id===e.id?e:s)}var Re={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function ut(o,e){return{promptEnvelope:{sourceName:o.promptEnvelope?.sourceName||o.name,instruction:e}}}function Ke(o,e,s){let d=e.trim();if(o!=="template")return{ok:!0,value:o==="custom"?{mode:o,text:d}:{mode:o}};try{let f=JSON.parse(s);return!f||typeof f!="object"||Array.isArray(f)?{ok:!1,error:"connectors.errTopicExtractors"}:{ok:!0,value:{mode:o,text:d,extractors:f}}}catch{return{ok:!1,error:"connectors.errTopicExtractors"}}}function je(o){return[{value:"turn",label:o("connectors.kindTurn")},{value:"workflow",label:o("connectors.kindWorkflowRetiring"),disabled:!0}]}function be(o){return`${location.origin}/webhook/${encodeURIComponent(o)}`}function pe(o){return(0,t.jsx)(de,{id:o.id,className:"connector-form-menu",ariaLabel:o.label,value:o.value,label:le(o.options,o.value),options:o.options,onChange:o.onChange})}function De(o){let e=(0,i.useRef)(null),[s,d]=(0,i.useState)(!1),[f,N]=(0,i.useState)(""),y=Array.isArray(o.value)?o.value:o.value?[o.value]:[],I=(0,i.useMemo)(()=>new Set(y),[y]),k=f.trim().toLocaleLowerCase(),R=(0,i.useMemo)(()=>k?o.groups.filter(u=>`${u.name} ${u.chatId}`.toLocaleLowerCase().includes(k)):o.groups,[k,o.groups]),L=o.multiple?y.length===0?o.allLabel||o.placeholder:o.selectedCountLabel(y.length):o.groups.find(u=>u.chatId===y[0])?.name||y[0]||o.placeholder;(0,i.useEffect)(()=>{if(!s)return;let u=r=>{e.current?.contains(r.target)||d(!1)};return document.addEventListener("pointerdown",u),()=>document.removeEventListener("pointerdown",u)},[s]);function $(u){if(!o.multiple){o.onChange(u),d(!1),N("");return}o.onChange(I.has(u)?y.filter(r=>r!==u):[...y,u])}return(0,t.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,t.jsxs)("button",{id:o.id,type:"button",className:"connector-group-picker-trigger","aria-label":o.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>d(u=>!u),children:[(0,t.jsx)("span",{className:y.length||o.multiple&&o.allLabel?"":"muted",children:L}),(0,t.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,t.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,t.jsxs)("label",{className:"connector-group-search",htmlFor:`${o.id}-search`,children:[(0,t.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,t.jsx)("input",{id:`${o.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:f,placeholder:o.searchPlaceholder,onChange:u=>N(u.currentTarget.value),onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),d(!1))}})]}),(0,t.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":o.label,"aria-multiselectable":o.multiple||void 0,children:[o.multiple&&o.allLabel&&!k?(0,t.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${y.length===0?" selected":""}`,role:"option","aria-selected":y.length===0,onClick:()=>o.onChange([]),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:o.allLabel}),(0,t.jsx)("small",{children:o.placeholder})]})]}):null,R.map(u=>{let r=I.has(u.chatId);return(0,t.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(u.chatId),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:u.name||u.chatId}),u.name?(0,t.jsx)("small",{children:u.chatId}):null]})]},u.chatId)}),R.length?null:(0,t.jsx)("p",{className:"connector-group-empty",children:o.emptyLabel})]})]}):null]})}function he(o,e){return o.filter(s=>s.bots.includes(e))}function ze(o,e){let s=o.target.chatId||"",d=s&&he(e,o.target.botId).some(f=>f.chatId===s);return{name:o.name,botId:o.target.botId,kind:o.target.kind,workflowId:o.target.workflowId||"",mode:o.target.mode,chatId:d?s:"",manualChat:!!(s&&!d),manualChatId:d?"":s,allowChats:o.target.allowChats||[],deduplicate:!!o.lifecycleExtractors?.dedupKey,dedup:o.lifecycleExtractors?.dedupKey||"",instruction:o.promptEnvelope?.instruction||"",topicMessageMode:o.topicMessage?.mode||"default",topicMessageText:o.topicMessage?.text||"",topicMessageExtractors:JSON.stringify(o.topicMessage?.extractors||{},null,2),suppressFinalOutput:o.suppressFinalOutput===!0,verify:o.verify?.type||"token",secret:"",storePayload:o.loggingPolicy?.storePayload!==!1}}function Qe(o){let e=_(),s=o.active==="webhooks",d=o.active==="logs";return(0,t.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,t.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,t.jsx)("a",{href:"#/connectors/logs",className:`itab${d?" on":""}`,role:"tab","aria-selected":d,children:e("connectors.tabLogs")})]})}function Oe(o){let e=_(),s=(0,i.useRef)(!1),d=(0,i.useRef)(null),f=(0,i.useRef)(null),[N,y]=(0,i.useState)([]),[I,k]=(0,i.useState)([]),[R,L]=(0,i.useState)([]),[$,u]=(0,i.useState)(!0),[r,E]=(0,i.useState)(Re),[U,w]=(0,i.useState)(null),[J,A]=(0,i.useState)(null),[X,Y]=(0,i.useState)(!1),[Z,B]=(0,i.useState)(!1),[x,K]=(0,i.useState)(null),[ee,M]=(0,i.useState)(null),[g,te]=(0,i.useState)(null),G=(0,i.useMemo)(()=>he(I,r.botId),[I,r.botId]),fe=(0,i.useMemo)(()=>N.length?N.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[N,e]),H=(0,i.useMemo)(()=>je(e),[e]),ye=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),ke=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),z=(0,i.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{E(b=>{let F=b.botId&&a.some(O=>O.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",C=he(l,F),m=b.chatId&&C.some(O=>O.chatId===b.chatId)?b.chatId:C[0]?.chatId??"",D=new Set(C.map(O=>O.chatId));return{...b,botId:F,chatId:m,allowChats:b.allowChats.filter(O=>D.has(O))}})},[]),v=(0,i.useCallback)(async()=>{u(!0);try{let[a,l,b]=await Promise.all([q("/api/bots"),q("/api/connectors"),q("/api/groups")]);if(!s.current)return;let F=(a.body?.bots||[]).map(m=>({larkAppId:m.larkAppId,botName:m.botName||m.larkAppId})),C=(b.body?.chats||[]).map(m=>({chatId:m.chatId,name:m.name||"",bots:(m.memberBots||[]).filter(D=>D.inChat).map(D=>D.larkAppId)}));y(F),k(C),L(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(F,C)}finally{s.current&&u(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,v(),()=>{s.current=!1,d.current&&clearTimeout(d.current)}),[v]),(0,i.useEffect)(()=>{let a=new Set(G.map(l=>l.chatId));E(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:G[0]?.chatId??"",allowChats:l.allowChats.filter(b=>a.has(b))}))},[G]),(0,i.useEffect)(()=>{let a=f.current;if(a)if(Z){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Z]),(0,i.useEffect)(()=>()=>{let a=f.current;a?.open&&a.close()},[]);function Q(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 h(a){E(l=>({...l,...a}))}function S(){w(null),A(null),K(null),E(a=>{let l=a.botId||N[0]?.larkAppId||"";return{...Re,botId:l,chatId:he(I,l)[0]?.chatId||""}}),B(!0)}function ne(a){w(null),A(null),M(null),K(a),E(ze(a,I)),B(!0)}function P(){X||(B(!1),w(null),A(null),K(null))}async function ae(){w(null),A(null);let a=r.name.trim(),l=r.botId;if(!a){w({text:e("connectors.errName"),error:!0});return}if(!l){w({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){w({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if((r.topicMessageMode==="custom"||r.topicMessageMode==="template")&&!b){w({text:e("connectors.errTopicMessage"),error:!0});return}let F=Ke(r.topicMessageMode,b,r.topicMessageExtractors);if(!F.ok){w({text:e(F.error),error:!0});return}let C={name:a,enabled:x?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:F.value,suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let m=r.manualChat?r.manualChatId.trim():r.chatId;if(!m){w({text:e("connectors.errChat"),error:!0});return}C.target.chatId=m}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let m=r.dedup.trim();if(r.deduplicate&&!m){w({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:m}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),Y(!0),w({text:e(x?"connectors.saving":"connectors.creating")});try{let m=await V(x?"PUT":"POST",x?`/api/connectors/${encodeURIComponent(x.id)}`:"/api/connectors",C);if(!s.current)return;if((m.status===201||m.status===200)&&m.body?.ok){if(x){let we=x.id,W=m.body.connector;L(Ce=>Xe(Ce,W));let Te=m.body.secret??C.secret;if(Te){let Ce=m.body.webhookUrl||be(W.id),qe=(W.verify?.type??"token")==="token",xe=W.target.mode==="dynamic",Be=xe?W.target.allowChats?.[0]||"<chatId>":"";w(null),A({name:a,mode:W.target.mode,chatId:W.target.chatId,url:Ce,secret:Te,isToken:qe,isDynamic:xe,exampleChat:Be,rotated:!0}),await v();return}M({id:we,text:e("connectors.updated")}),B(!1),K(null);return}let D=m.body.webhookUrl||be(m.body.connector.id),O=(m.body.connector?.verify?.type??"token")==="token",Me=r.mode==="dynamic",He=Me?C.target.allowChats?.[0]||"<chatId>":"";w(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:D,secret:m.body.secret,isToken:O,isDynamic:Me,exampleChat:He}),E(we=>({...we,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await v()}else{let D=m.body?.error||m.status;w({text:e("connectors.createFailed",{error:String(D)}),error:!0})}}finally{s.current&&Y(!1)}}async function se(a){M({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await V("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)M(null),await v();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function ve(a){let l=a.loggingPolicy?.storePayload!==!1;M({id:a.id,text:e("connectors.saving")});let b=await V("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)M(null),await v();else{let F=b.body?.error||b.status;M({id:a.id,text:e("connectors.saveFailed",{error:String(F)}),error:!0})}}async function $e(a){if(!confirm(e("connectors.delConfirm")))return;M({id:a.id,text:e("connectors.deleting")});let l=await V("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)M(null),await v();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function Ae(a){ue(be(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(te(a.id),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{s.current&&te(null)},1200))})}return(0,t.jsxs)("section",{className:"page connectors-page",children:[(0,t.jsxs)("div",{className:"page-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,t.jsx)("h1",{children:e("nav.connectors")})]}),(0,t.jsx)("div",{className:"page-heading-actions",children:o.tab==="webhooks"?(0,t.jsx)(Se,{className:"page-primary-action connector-create-trigger",onClick:S,children:e("connectors.createTitle")}):(0,t.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,t.jsx)(Qe,{active:o.tab}),o.tab==="webhooks"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dialog",{ref:f,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),P()},onClose:P,onClick:a=>{a.target===a.currentTarget&&P()},children:(0,t.jsxs)("article",{className:"connector-modal-card",children:[(0,t.jsxs)("header",{className:"connector-modal-header",children:[(0,t.jsx)("h3",{children:e(x?"connectors.editTitle":"connectors.createTitle")}),(0,t.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:X,onClick:P,children:(0,t.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,t.jsx)("div",{className:"connector-modal-body",children:J?(0,t.jsx)(Ve,{created:J,groupName:z}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cn-form",children:[(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,t.jsx)(T,{children:e("connectors.fName")}),(0,t.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>h({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fBot")}),(0,t.jsx)(pe,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:fe,onChange:a=>h({botId:a})})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fKind")}),(0,t.jsx)(pe,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:H,onChange:a=>h({kind:a})})]}),r.kind==="workflow"?(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,t.jsx)(T,{children:e("connectors.fWf")}),(0,t.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>h({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fMode")}),(0,t.jsx)(pe,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:ye,onChange:a=>h({mode:a})})]}),r.mode==="fixed"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsx)(T,{children:e("connectors.fFixedChat")}),(0,t.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,t.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>h({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,t.jsx)(De,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:G,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({chatId:a})}),(0,t.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>h({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsxs)(T,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)(De,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:G,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=>h({allowChats:a})})]}):null,r.mode==="dynamic"?(0,t.jsx)("div",{className:"cn-field-wide",children:(0,t.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,t.jsx)(T,{children:e("connectors.newGroupStrategy")}),(0,t.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>h({deduplicate:!1}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,t.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>h({deduplicate:!0}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,t.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,t.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,t.jsx)(T,{help:(0,t.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,t.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>h({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,t.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,t.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,t.jsxs)(T,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>h({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,t.jsx)(T,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,t.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","template","none"].map(a=>{let l=a==="default"?"Default":a==="custom"?"Custom":a==="template"?"Template":"None";return(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>h({topicMessageMode:a}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e(`connectors.topicMessage${l}`)}),(0,t.jsx)("small",{children:e(`connectors.topicMessage${l}Hint`)})]})]},a)})}),r.topicMessageMode==="custom"||r.topicMessageMode==="template"?(0,t.jsxs)("div",{className:"connector-topic-message-input",children:[(0,t.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>h({topicMessageText:a.currentTarget.value}),"aria-label":e(r.topicMessageMode==="template"?"connectors.topicMessageTemplate":"connectors.topicMessageCustom"),placeholder:e(r.topicMessageMode==="template"?"connectors.topicMessageTemplatePh":"connectors.topicMessageCustomPh")}),(0,t.jsxs)("small",{children:[e(r.topicMessageMode==="template"?"connectors.topicMessageTemplateHelp":"connectors.topicMessageCustomHelp"),(0,t.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]}),r.topicMessageMode==="template"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("textarea",{id:"cn-topic-message-extractors",className:"connector-topic-message-extractors",rows:8,value:r.topicMessageExtractors,onChange:a=>h({topicMessageExtractors:a.currentTarget.value}),placeholder:e("connectors.topicMessageExtractorsPh"),"aria-label":e("connectors.topicMessageExtractors")}),(0,t.jsx)("small",{children:e("connectors.topicMessageExtractorsHelp")})]}):null]}):(0,t.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,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,t.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>h({storePayload:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.storePayload")}),(0,t.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,t.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>h({suppressFinalOutput:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,t.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fVerify")}),(0,t.jsx)(pe,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:ke,onChange:a=>h({verify:a})})]}),(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,t.jsx)(T,{children:e("connectors.fSecret")}),(0,t.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>h({secret:a.currentTarget.value}),placeholder:e(x?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),U?(0,t.jsx)("p",{className:`connector-create-message${U.error?" err":""}`,children:U.text}):null]})}),(0,t.jsx)("footer",{className:"connector-modal-actions",children:J?(0,t.jsx)("button",{type:"button",className:"primary",onClick:P,children:e("connectors.close")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",disabled:X,onClick:P,children:e("connectors.cancel")}),(0,t.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:X,onClick:()=>{ae()},children:e(x?"connectors.btnSave":"connectors.btnCreate")})]})})]})}),(0,t.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,t.jsx)("div",{className:"card connector-list-card",children:$?(0,t.jsx)(ie,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,t.jsx)(Ye,{connectors:R,bots:N,copiedId:g,editMsg:ee,groupName:z,modeLabel:Q,kindLabel:oe,onCopy:Ae,onEdit:ne,onToggle:a=>{se(a)},onTogglePayloadLogging:a=>{ve(a)},onDelete:a=>{$e(a)}})})})]}):(0,t.jsx)(Ee,{embedded:!0})]})}function Ve(o){let e=_(),s=o.created,d=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,f=s.exampleChat!=="<chatId>"?`\uFF08${o.groupName(s.exampleChat)}\uFF09`:"";return(0,t.jsx)("div",{className:"connector-created-wrap",children:(0,t.jsxs)("div",{className:"card connector-created-card",children:[(0,t.jsxs)("p",{className:"connector-created-title ok",children:[e(s.rotated?"connectors.rotatedPrefix":"connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,t.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:o.groupName(s.chatId)})]}):null]}),(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsx)("code",{children:s.url})]}),s.secret?(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,t.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:f})}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ye(o){let e=_();return o.connectors.length?(0,t.jsx)(t.Fragment,{children:o.connectors.map(s=>{let d=o.bots.find(L=>L.larkAppId===s.target.botId),f=be(s.id),N=(s.verify?.type??"token")==="token",y=e(N?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:o.groupName(s.target.chatId)}):"",k=o.editMsg?.id===s.id?o.editMsg:null,R=o.copiedId===s.id;return(0,t.jsxs)("div",{className:"card connector-item-card",children:[(0,t.jsxs)("div",{className:"connector-item-head",children:[(0,t.jsxs)("div",{className:"connector-item-main",children:[(0,t.jsxs)("div",{className:"connector-item-title",children:[(0,t.jsx)("b",{children:s.name}),(0,t.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,t.jsxs)("div",{className:"connector-item-meta",children:[(0,t.jsx)("span",{children:d?.botName||s.target.botId}),(0,t.jsx)("span",{children:o.kindLabel(s.target.kind)}),(0,t.jsx)("span",{children:o.modeLabel(s.target.mode)}),I?(0,t.jsx)("span",{children:I}):null,(0,t.jsx)("span",{children:y}),(0,t.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,t.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>o.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,t.jsxs)("div",{className:"connector-url-row",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsxs)("code",{children:[f,N?"/<token>":""]})]}),N?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,t.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,t.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,t.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"||s.topicMessage?.mode==="template"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),k?(0,t.jsx)("div",{className:k.error?"err connector-item-note":"muted connector-item-note",children:k.text}):null,(0,t.jsxs)("div",{className:"connector-item-actions",children:[(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onEdit(s),children:e("connectors.btnEdit")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,t.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function gt(o){return re(o,(0,t.jsx)(Oe,{tab:"webhooks"}))}function mt(o){return re(o,(0,t.jsx)(Oe,{tab:"logs"}))}export{ut as buildConnectorInstructionUpdateBody,je as buildConnectorKindOptions,Ke as buildConnectorTopicMessageConfig,mt as renderConnectorsLogsPage,gt as renderConnectorsPage,Xe as replaceConnectorById};
|
|
1
|
+
import{a as q,b as V}from"./chunk-EVK77ASG.js";import{a as ue}from"./chunk-ZJVTGU5X.js";import{c as _}from"./chunk-KEEYQ3WF.js";import{a as le,c as ie,g as Se,l as T,q as de}from"./chunk-5CJMHTT4.js";import"./chunk-6JTZJRQJ.js";import{a as re}from"./chunk-SYC6D5XU.js";import{a as Pe,d as ce}from"./chunk-5THX4DI2.js";import{c as j}from"./chunk-7SZRL6FY.js";var i=j(Pe(),1);var p=j(Pe(),1);var n=j(ce(),1),Ge=50,Ne={total:0,ok:0,error:0,successRate:0};function We(o,e=Date.now()){if(o==="all")return;let s=o==="24h"?24:o==="7d"?168:720;return new Date(e-s*60*60*1e3).toISOString()}function _e(o,e=0){let s=new URLSearchParams({limit:String(Ge),offset:String(e)});o.connectorId&&s.set("connectorId",o.connectorId),o.status&&s.set("status",o.status);let d=We(o.timeWindow);return d&&s.set("since",d),o.query.trim()&&s.set("q",o.query.trim()),s}function Fe(o){if(!o)return"\u2014";let e=new Date(o);return Number.isFinite(e.getTime())?e.toLocaleString():o}function ge(o){return o===void 0||!Number.isFinite(o)?"\u2014":o<1e3?`${Math.round(o)} ms`:o<6e4?`${(o/1e3).toFixed(o<1e4?1:0)} s`:`${(o/6e4).toFixed(1)} min`}function Ue(o){return o===void 0?"\u2014":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/1024/1024).toFixed(1)} MB`}function Le(o){return o.value===void 0||o.value===null?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):typeof o.value=="object"&&!Array.isArray(o.value)&&Object.keys(o.value).length===0?(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:o.empty}):(0,n.jsx)("pre",{className:`webhook-log-json${o.fullHeight?" full-height":""}`,children:(0,n.jsx)("code",{children:JSON.stringify(o.value,null,2)})})}function Je(o){let e=[["kind",o.value?.kind],["mode",o.value?.mode],["botId",o.value?.botId],["chatId",o.value?.chatId],["sessionId",o.value?.sessionId],["rootMessageId",o.value?.rootMessageId],["workflowId",o.value?.workflowId]].filter(([,s])=>s!=null&&s!=="");return e.length?(0,n.jsx)("dl",{className:"webhook-log-target-facts",children:e.map(([s,d])=>(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:s}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:String(d)})})]},s))}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:"\u2014"})}function Ie(o){return(0,n.jsx)(de,{id:o.id,className:"webhook-log-filter-menu",ariaLabel:o.label,style:{width:"100%",minWidth:0},value:o.value,label:le(o.options,o.value),options:o.options,onChange:o.onChange})}function me(o){return(0,n.jsxs)("article",{className:`card webhook-log-metric${o.tone?` ${o.tone}`:""}`,children:[(0,n.jsx)("span",{children:o.label}),(0,n.jsx)("strong",{children:o.value}),(0,n.jsx)("small",{children:o.hint||"\xA0"})]})}function Ee(o={}){let e=_(),s=(0,p.useRef)(!1),d=(0,p.useRef)([]),[f,N]=(0,p.useState)([]),[y,I]=(0,p.useState)([]),[k,R]=(0,p.useState)(Ne),[L,$]=(0,p.useState)({connectorId:"",status:"",timeWindow:"7d",query:""}),[u,r]=(0,p.useState)(null),[E,U]=(0,p.useState)(!0),[w,J]=(0,p.useState)(!1),[A,X]=(0,p.useState)(!1),[Y,Z]=(0,p.useState)(0),[B,x]=(0,p.useState)(""),[K,ee]=(0,p.useState)(!1),M=(0,p.useMemo)(()=>new Map(f.map(c=>[c.id,c.name])),[f]),g=(0,p.useMemo)(()=>y.find(c=>c.triggerId===u)??y[0]??null,[y,u]),te=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allConnectors")},...f.map(c=>({value:c.id,label:c.name}))],[f,e]),G=(0,p.useMemo)(()=>[{value:"",label:e("webhookLogs.allStatuses")},{value:"ok",label:e("webhookLogs.success")},{value:"error",label:e("webhookLogs.failed")}],[e]),fe=(0,p.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]),H=(0,p.useCallback)(async(c=!1,v=!1)=>{v?J(!0):U(!0),x("");let Q=c?d.current.length:0,oe=_e(L,Q),h=new URLSearchParams(oe);h.delete("limit"),h.delete("offset");try{let[S,ne]=await Promise.all([q(`/api/trigger-logs?${oe}`),c?Promise.resolve(null):q(`/api/trigger-logs/summary?${h}`)]);if(!s.current)return;if(S.status!==200)throw new Error(String(S.body?.error||S.status));let P=Array.isArray(S.body?.logs)?S.body.logs:[],ae=c?[...d.current,...P]:P;d.current=ae,I(ae),Z(Number(S.body?.total??P.length)),X(S.body?.hasMore===!0),c||(R(ne?.status===200?ne.body?.summary??Ne:Ne),r(se=>P.some(ve=>ve.triggerId===se)?se:P[0]?.triggerId??null))}catch(S){s.current&&x(S?.message||e("webhookLogs.loadFailed"))}finally{s.current&&(U(!1),J(!1))}},[L,e]);(0,p.useEffect)(()=>(s.current=!0,q("/api/connectors").then(c=>{s.current&&c.status===200&&N(Array.isArray(c.body?.connectors)?c.body.connectors:[])}),()=>{s.current=!1}),[]),(0,p.useEffect)(()=>{let c=setTimeout(()=>{H(!1)},L.query?260:0);return()=>clearTimeout(c)},[L,H]),(0,p.useEffect)(()=>{let c=setInterval(()=>{H(!1,!0)},15e3);return()=>clearInterval(c)},[H]);async function ye(){!g||!await ue(JSON.stringify(g,null,2),e("webhookLogs.copyJson"))||(ee(!0),setTimeout(()=>s.current&&ee(!1),1200))}let ke=g?.request?.payloadOmittedReason==="disabled"?e("webhookLogs.payloadDisabled"):g?.request?.payloadOmittedReason==="too_large"?e("webhookLogs.payloadTooLarge"):e("webhookLogs.payloadUnavailable"),z=(0,n.jsxs)(n.Fragment,{children:[o.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${w?" 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)(me,{label:e("webhookLogs.total"),value:k.total,hint:e("webhookLogs.filteredRange")}),(0,n.jsx)(me,{label:e("webhookLogs.successRate"),value:`${k.successRate.toFixed(k.successRate%1?1:0)}%`,tone:"ok",hint:`${k.ok} ${e("webhookLogs.calls")}`}),(0,n.jsx)(me,{label:e("webhookLogs.failures"),value:k.error,tone:k.error?"error":void 0,hint:k.error?e("webhookLogs.needsReview"):e("webhookLogs.noFailures")}),(0,n.jsx)(me,{label:e("webhookLogs.p95"),value:ge(k.p95DurationMs),hint:`${e("webhookLogs.average")} ${ge(k.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:L.query,onChange:c=>{let v=c.currentTarget.value;$(Q=>({...Q,query:v}))}}),(0,n.jsx)(Ie,{id:"webhook-log-connector",label:e("webhookLogs.connector"),value:L.connectorId,options:te,onChange:c=>$(v=>({...v,connectorId:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-status",label:e("webhookLogs.status"),value:L.status,options:G,onChange:c=>$(v=>({...v,status:c}))}),(0,n.jsx)(Ie,{id:"webhook-log-window",label:e("webhookLogs.timeRange"),value:L.timeWindow,options:fe,onChange:c=>$(v=>({...v,timeWindow:c}))}),(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-refresh",disabled:w,onClick:()=>{H(!1,!0)},children:e("webhookLogs.refresh")})]}),B?(0,n.jsxs)("p",{className:"err webhook-log-error",children:[e("webhookLogs.loadFailed"),": ",B]}):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:Y})})]})}),E&&!y.length?(0,n.jsx)(ie,{label:e("webhookLogs.loading"),compact:!0}):null,!E&&!y.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:y.map(c=>{let v=g?.triggerId===c.triggerId;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":v,className:`webhook-log-row${v?" 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:M.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:Fe(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:ge(c.response?.durationMs)})]})]},`${c.triggerId}-${c.createdAt}`)})}),A?(0,n.jsx)("button",{type:"button",className:"ghost webhook-log-more",disabled:E,onClick:()=>{H(!0)},children:e("webhookLogs.loadMore")}):null]}),(0,n.jsx)("article",{className:"card webhook-log-detail-panel",children:g?(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 ${g.status}`,children:g.status==="ok"?e("webhookLogs.success"):e("webhookLogs.failed")}),(0,n.jsx)("h2",{children:M.get(g.connectorId||"")||g.connectorId||e("webhookLogs.unknownConnector")}),(0,n.jsxs)("p",{children:[Fe(g.createdAt)," \xB7 ",g.request?.method||"POST"," ",g.request?.path||"/webhook/\u2026"]})]}),(0,n.jsx)("button",{type:"button",className:"ghost",onClick:()=>{ye()},children:e(K?"webhookLogs.copied":"webhookLogs.copyJson")})]}),g.error?(0,n.jsxs)("div",{className:"webhook-log-failure",children:[(0,n.jsx)("strong",{children:g.errorCode||e("webhookLogs.failureReason")}),(0,n.jsx)("span",{children:g.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:g.response?.httpStatus??"\u2014"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.duration")}),(0,n.jsx)("dd",{children:ge(g.response?.durationMs)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.action")}),(0,n.jsx)("dd",{children:g.action})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:e("webhookLogs.bodySize")}),(0,n.jsx)("dd",{children:Ue(g.request?.bodyBytes)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Trigger ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.triggerId})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("dt",{children:"Request ID"}),(0,n.jsx)("dd",{children:(0,n.jsx)("code",{children:g.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:g.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:g.target?.chatId||g.target?.sessionId||g.response?.chatId||"\u2014"})})]})]})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.queryParams")}),(0,n.jsx)(Le,{value:g.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)(Le,{value:g.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")})]}),g.request?.payloadStored?(0,n.jsx)(Le,{value:g.request.payload,empty:e("webhookLogs.none")}):(0,n.jsx)("p",{className:"webhook-log-detail-empty",children:ke})]}),(0,n.jsxs)("section",{className:"webhook-log-detail-section",children:[(0,n.jsx)("h3",{children:e("webhookLogs.routeTarget")}),(0,n.jsx)(Je,{value:g.target})]})]}):(0,n.jsx)("div",{className:"webhook-log-empty",children:(0,n.jsx)("strong",{children:e("webhookLogs.selectRecord")})})})]})]});return o.embedded?(0,n.jsx)("section",{className:"webhook-logs-content webhook-logs-panel",children:z}):(0,n.jsx)("section",{className:"page webhook-logs-content webhook-logs-page",children:z})}var t=j(ce(),1);function Xe(o,e){return o.map(s=>s.id===e.id?e:s)}var Re={name:"",botId:"",kind:"turn",workflowId:"",mode:"dynamic",chatId:"",manualChat:!1,manualChatId:"",allowChats:[],deduplicate:!1,dedup:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,verify:"token",secret:"",storePayload:!0};function ut(o,e){return{promptEnvelope:{sourceName:o.promptEnvelope?.sourceName||o.name,instruction:e}}}function Ke(o,e,s){let d=e.trim();if(o!=="template")return{ok:!0,value:o==="custom"?{mode:o,text:d}:{mode:o}};try{let f=JSON.parse(s);return!f||typeof f!="object"||Array.isArray(f)?{ok:!1,error:"connectors.errTopicExtractors"}:{ok:!0,value:{mode:o,text:d,extractors:f}}}catch{return{ok:!1,error:"connectors.errTopicExtractors"}}}function je(o){return[{value:"turn",label:o("connectors.kindTurn")},{value:"workflow",label:o("connectors.kindWorkflowRetiring"),disabled:!0}]}function be(o){return`${location.origin}/webhook/${encodeURIComponent(o)}`}function pe(o){return(0,t.jsx)(de,{id:o.id,className:"connector-form-menu",ariaLabel:o.label,value:o.value,label:le(o.options,o.value),options:o.options,onChange:o.onChange})}function De(o){let e=(0,i.useRef)(null),[s,d]=(0,i.useState)(!1),[f,N]=(0,i.useState)(""),y=Array.isArray(o.value)?o.value:o.value?[o.value]:[],I=(0,i.useMemo)(()=>new Set(y),[y]),k=f.trim().toLocaleLowerCase(),R=(0,i.useMemo)(()=>k?o.groups.filter(u=>`${u.name} ${u.chatId}`.toLocaleLowerCase().includes(k)):o.groups,[k,o.groups]),L=o.multiple?y.length===0?o.allLabel||o.placeholder:o.selectedCountLabel(y.length):o.groups.find(u=>u.chatId===y[0])?.name||y[0]||o.placeholder;(0,i.useEffect)(()=>{if(!s)return;let u=r=>{e.current?.contains(r.target)||d(!1)};return document.addEventListener("pointerdown",u),()=>document.removeEventListener("pointerdown",u)},[s]);function $(u){if(!o.multiple){o.onChange(u),d(!1),N("");return}o.onChange(I.has(u)?y.filter(r=>r!==u):[...y,u])}return(0,t.jsxs)("div",{ref:e,className:`connector-group-picker${s?" open":""}`,children:[(0,t.jsxs)("button",{id:o.id,type:"button",className:"connector-group-picker-trigger","aria-label":o.label,"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>d(u=>!u),children:[(0,t.jsx)("span",{className:y.length||o.multiple&&o.allLabel?"":"muted",children:L}),(0,t.jsx)("span",{className:"connector-group-picker-chevron","aria-hidden":"true"})]}),s?(0,t.jsxs)("div",{className:"connector-group-picker-popover",children:[(0,t.jsxs)("label",{className:"connector-group-search",htmlFor:`${o.id}-search`,children:[(0,t.jsx)("span",{className:"connector-group-search-icon","aria-hidden":"true"}),(0,t.jsx)("input",{id:`${o.id}-search`,type:"search",autoComplete:"off",autoFocus:!0,value:f,placeholder:o.searchPlaceholder,onChange:u=>N(u.currentTarget.value),onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),d(!1))}})]}),(0,t.jsxs)("div",{className:"connector-group-options",role:"listbox","aria-label":o.label,"aria-multiselectable":o.multiple||void 0,children:[o.multiple&&o.allLabel&&!k?(0,t.jsxs)("button",{type:"button",className:`connector-group-option connector-group-option-all${y.length===0?" selected":""}`,role:"option","aria-selected":y.length===0,onClick:()=>o.onChange([]),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:o.allLabel}),(0,t.jsx)("small",{children:o.placeholder})]})]}):null,R.map(u=>{let r=I.has(u.chatId);return(0,t.jsxs)("button",{type:"button",className:`connector-group-option${r?" selected":""}`,role:"option","aria-selected":r,onClick:()=>$(u.chatId),children:[(0,t.jsx)("span",{className:"connector-group-check","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:u.name||u.chatId}),u.name?(0,t.jsx)("small",{children:u.chatId}):null]})]},u.chatId)}),R.length?null:(0,t.jsx)("p",{className:"connector-group-empty",children:o.emptyLabel})]})]}):null]})}function he(o,e){return o.filter(s=>s.bots.includes(e))}function ze(o,e){let s=o.target.chatId||"",d=s&&he(e,o.target.botId).some(f=>f.chatId===s);return{name:o.name,botId:o.target.botId,kind:o.target.kind,workflowId:o.target.workflowId||"",mode:o.target.mode,chatId:d?s:"",manualChat:!!(s&&!d),manualChatId:d?"":s,allowChats:o.target.allowChats||[],deduplicate:!!o.lifecycleExtractors?.dedupKey,dedup:o.lifecycleExtractors?.dedupKey||"",instruction:o.promptEnvelope?.instruction||"",topicMessageMode:o.topicMessage?.mode||"default",topicMessageText:o.topicMessage?.text||"",topicMessageExtractors:JSON.stringify(o.topicMessage?.extractors||{},null,2),suppressFinalOutput:o.suppressFinalOutput===!0,verify:o.verify?.type||"token",secret:"",storePayload:o.loggingPolicy?.storePayload!==!1}}function Qe(o){let e=_(),s=o.active==="webhooks",d=o.active==="logs";return(0,t.jsxs)("nav",{className:"connectors-subnav-slot connectors-subnav insight-tabs",role:"tablist","aria-label":e("nav.connectors"),children:[(0,t.jsx)("a",{href:"#/connectors",className:`itab${s?" on":""}`,role:"tab","aria-selected":s,children:e("connectors.tabWebhooks")}),(0,t.jsx)("a",{href:"#/connectors/logs",className:`itab${d?" on":""}`,role:"tab","aria-selected":d,children:e("connectors.tabLogs")})]})}function Oe(o){let e=_(),s=(0,i.useRef)(!1),d=(0,i.useRef)(null),f=(0,i.useRef)(null),[N,y]=(0,i.useState)([]),[I,k]=(0,i.useState)([]),[R,L]=(0,i.useState)([]),[$,u]=(0,i.useState)(!0),[r,E]=(0,i.useState)(Re),[U,w]=(0,i.useState)(null),[J,A]=(0,i.useState)(null),[X,Y]=(0,i.useState)(!1),[Z,B]=(0,i.useState)(!1),[x,K]=(0,i.useState)(null),[ee,M]=(0,i.useState)(null),[g,te]=(0,i.useState)(null),G=(0,i.useMemo)(()=>he(I,r.botId),[I,r.botId]),fe=(0,i.useMemo)(()=>N.length?N.map(a=>({value:a.larkAppId,label:a.botName})):[{value:"",label:e("connectors.noOnlineBots")}],[N,e]),H=(0,i.useMemo)(()=>je(e),[e]),ye=(0,i.useMemo)(()=>[{value:"dynamic",label:e("connectors.modeDynamic")},{value:"fixed",label:e("connectors.modeFixed")},{value:"new-group",label:e("connectors.modeNewGroup")}],[e]),ke=(0,i.useMemo)(()=>[{value:"token",label:e("connectors.verifyToken")},{value:"hmac-sha256",label:e("connectors.verifyHmac")}],[e]),z=(0,i.useCallback)(a=>I.find(b=>b.chatId===a)?.name||a,[I]),c=(0,i.useCallback)((a,l)=>{E(b=>{let F=b.botId&&a.some(O=>O.larkAppId===b.botId)?b.botId:a[0]?.larkAppId??"",C=he(l,F),m=b.chatId&&C.some(O=>O.chatId===b.chatId)?b.chatId:C[0]?.chatId??"",D=new Set(C.map(O=>O.chatId));return{...b,botId:F,chatId:m,allowChats:b.allowChats.filter(O=>D.has(O))}})},[]),v=(0,i.useCallback)(async()=>{u(!0);try{let[a,l,b]=await Promise.all([q("/api/bots"),q("/api/connectors"),q("/api/groups")]);if(!s.current)return;let F=(a.body?.bots||[]).map(m=>({larkAppId:m.larkAppId,botName:m.botName||m.larkAppId})),C=(b.body?.chats||[]).map(m=>({chatId:m.chatId,name:m.name||"",bots:(m.memberBots||[]).filter(D=>D.inChat).map(D=>D.larkAppId)}));y(F),k(C),L(Array.isArray(l.body?.connectors)?l.body.connectors:[]),c(F,C)}finally{s.current&&u(!1)}},[c]);(0,i.useEffect)(()=>(s.current=!0,v(),()=>{s.current=!1,d.current&&clearTimeout(d.current)}),[v]),(0,i.useEffect)(()=>{let a=new Set(G.map(l=>l.chatId));E(l=>({...l,chatId:l.chatId&&a.has(l.chatId)?l.chatId:G[0]?.chatId??"",allowChats:l.allowChats.filter(b=>a.has(b))}))},[G]),(0,i.useEffect)(()=>{let a=f.current;if(a)if(Z){if(!a.open)try{a.showModal()}catch{}let l=a.querySelector(".connector-modal-body");l&&(l.scrollTop=0)}else a.open&&a.close()},[Z]),(0,i.useEffect)(()=>()=>{let a=f.current;a?.open&&a.close()},[]);function Q(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 h(a){E(l=>({...l,...a}))}function S(){w(null),A(null),K(null),E(a=>{let l=a.botId||N[0]?.larkAppId||"";return{...Re,botId:l,chatId:he(I,l)[0]?.chatId||""}}),B(!0)}function ne(a){w(null),A(null),M(null),K(a),E(ze(a,I)),B(!0)}function P(){X||(B(!1),w(null),A(null),K(null))}async function ae(){w(null),A(null);let a=r.name.trim(),l=r.botId;if(!a){w({text:e("connectors.errName"),error:!0});return}if(!l){w({text:e("connectors.errBot"),error:!0});return}if(r.kind==="workflow"){w({text:e("connectors.errLegacyWorkflowRetired"),error:!0});return}let b=r.topicMessageText.trim();if((r.topicMessageMode==="custom"||r.topicMessageMode==="template")&&!b){w({text:e("connectors.errTopicMessage"),error:!0});return}let F=Ke(r.topicMessageMode,b,r.topicMessageExtractors);if(!F.ok){w({text:e(F.error),error:!0});return}let C={name:a,enabled:x?.enabled??!0,target:{kind:r.kind,mode:r.mode,botId:l},promptEnvelope:{sourceName:a,instruction:r.instruction.trim()},topicMessage:F.value,suppressFinalOutput:r.suppressFinalOutput,verify:{type:r.verify},loggingPolicy:{storePayload:r.storePayload,storeHeaders:!0,retentionDays:14}};if(r.mode==="fixed"){let m=r.manualChat?r.manualChatId.trim():r.chatId;if(!m){w({text:e("connectors.errChat"),error:!0});return}C.target.chatId=m}else r.mode==="dynamic"&&(C.target.allowChats=r.allowChats);if(r.mode==="new-group"){let m=r.dedup.trim();if(r.deduplicate&&!m){w({text:e("connectors.errDedup"),error:!0});return}C.lifecycleExtractors=r.deduplicate?{dedupKey:m}:null}else C.lifecycleExtractors=null;r.secret.trim()&&(C.secret=r.secret.trim()),Y(!0),w({text:e(x?"connectors.saving":"connectors.creating")});try{let m=await V(x?"PUT":"POST",x?`/api/connectors/${encodeURIComponent(x.id)}`:"/api/connectors",C);if(!s.current)return;if((m.status===201||m.status===200)&&m.body?.ok){if(x){let we=x.id,W=m.body.connector;L(Ce=>Xe(Ce,W));let Te=m.body.secret??C.secret;if(Te){let Ce=m.body.webhookUrl||be(W.id),qe=(W.verify?.type??"token")==="token",xe=W.target.mode==="dynamic",Be=xe?W.target.allowChats?.[0]||"<chatId>":"";w(null),A({name:a,mode:W.target.mode,chatId:W.target.chatId,url:Ce,secret:Te,isToken:qe,isDynamic:xe,exampleChat:Be,rotated:!0}),await v();return}M({id:we,text:e("connectors.updated")}),B(!1),K(null);return}let D=m.body.webhookUrl||be(m.body.connector.id),O=(m.body.connector?.verify?.type??"token")==="token",Me=r.mode==="dynamic",He=Me?C.target.allowChats?.[0]||"<chatId>":"";w(null),A({name:a,mode:r.mode,chatId:C.target.chatId,url:D,secret:m.body.secret,isToken:O,isDynamic:Me,exampleChat:He}),E(we=>({...we,name:"",workflowId:"",manualChatId:"",dedup:"",secret:"",instruction:"",topicMessageMode:"default",topicMessageText:"",topicMessageExtractors:"{}",suppressFinalOutput:!1,allowChats:[],storePayload:!0})),await v()}else{let D=m.body?.error||m.status;w({text:e("connectors.createFailed",{error:String(D)}),error:!0})}}finally{s.current&&Y(!1)}}async function se(a){M({id:a.id,text:e(a.enabled?"connectors.disabling":"connectors.enabling")});let l=await V("PATCH",`/api/connectors/${encodeURIComponent(a.id)}`,{enabled:!a.enabled});if(s.current)if(l.status===200&&l.body?.ok)M(null),await v();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.toggleFailed",{error:String(b)}),error:!0})}}async function ve(a){let l=a.loggingPolicy?.storePayload!==!1;M({id:a.id,text:e("connectors.saving")});let b=await V("PUT",`/api/connectors/${encodeURIComponent(a.id)}`,{loggingPolicy:{storePayload:!l,storeHeaders:a.loggingPolicy?.storeHeaders!==!1,retentionDays:a.loggingPolicy?.retentionDays??14}});if(s.current)if(b.status===200&&b.body?.ok)M(null),await v();else{let F=b.body?.error||b.status;M({id:a.id,text:e("connectors.saveFailed",{error:String(F)}),error:!0})}}async function $e(a){if(!confirm(e("connectors.delConfirm")))return;M({id:a.id,text:e("connectors.deleting")});let l=await V("DELETE",`/api/connectors/${encodeURIComponent(a.id)}`);if(s.current)if(l.status===200&&l.body?.ok)M(null),await v();else{let b=l.body?.error||l.status;M({id:a.id,text:e("connectors.deleteFailed",{error:String(b)}),error:!0})}}function Ae(a){ue(be(a.id),e("connectors.copy")).then(l=>{!l||!s.current||(te(a.id),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{s.current&&te(null)},1200))})}return(0,t.jsxs)("section",{className:"page connectors-page",children:[(0,t.jsxs)("div",{className:"page-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"eyebrow",children:e("nav.connectors")}),(0,t.jsx)("h1",{children:e("nav.connectors")})]}),(0,t.jsx)("div",{className:"page-heading-actions",children:o.tab==="webhooks"?(0,t.jsx)(Se,{className:"page-primary-action connector-create-trigger",onClick:S,children:e("connectors.createTitle")}):(0,t.jsx)("a",{className:"button page-primary-action",href:"#/connectors",children:e("webhookLogs.manage")})})]}),(0,t.jsx)(Qe,{active:o.tab}),o.tab==="webhooks"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dialog",{ref:f,className:"connector-create-modal",onCancel:a=>{a.preventDefault(),P()},onClose:P,onClick:a=>{a.target===a.currentTarget&&P()},children:(0,t.jsxs)("article",{className:"connector-modal-card",children:[(0,t.jsxs)("header",{className:"connector-modal-header",children:[(0,t.jsx)("h3",{children:e(x?"connectors.editTitle":"connectors.createTitle")}),(0,t.jsx)("button",{type:"button",className:"connector-modal-close","aria-label":e("connectors.close"),title:e("connectors.close"),disabled:X,onClick:P,children:(0,t.jsx)("span",{"aria-hidden":"true",children:"\xD7"})})]}),(0,t.jsx)("div",{className:"connector-modal-body",children:J?(0,t.jsx)(Ve,{created:J,groupName:z}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"cn-form",children:[(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-name",children:[(0,t.jsx)(T,{children:e("connectors.fName")}),(0,t.jsx)("input",{id:"cn-name",value:r.name,onChange:a=>h({name:a.currentTarget.value}),placeholder:e("connectors.fNamePh")})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fBot")}),(0,t.jsx)(pe,{id:"cn-bot",label:e("connectors.fBot"),value:r.botId,options:fe,onChange:a=>h({botId:a})})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fKind")}),(0,t.jsx)(pe,{id:"cn-kind",label:e("connectors.fKind"),value:r.kind,options:H,onChange:a=>h({kind:a})})]}),r.kind==="workflow"?(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-wf",children:[(0,t.jsx)(T,{children:e("connectors.fWf")}),(0,t.jsx)("input",{id:"cn-wf",value:r.workflowId,onChange:a=>h({workflowId:a.currentTarget.value}),placeholder:"workflowId"})]}):null,(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fMode")}),(0,t.jsx)(pe,{id:"cn-mode",label:e("connectors.fMode"),value:r.mode,options:ye,onChange:a=>h({mode:a})})]}),r.mode==="fixed"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsx)(T,{children:e("connectors.fFixedChat")}),(0,t.jsxs)("div",{className:"connector-chat-control",children:[r.manualChat?(0,t.jsx)("input",{id:"cn-chat",value:r.manualChatId,onChange:a=>h({manualChatId:a.currentTarget.value}),placeholder:e("connectors.fChatManualPh")}):(0,t.jsx)(De,{id:"cn-chat-sel",label:e("connectors.fFixedChat"),groups:G,value:r.chatId,placeholder:e("connectors.groupPickerPlaceholder"),searchPlaceholder:e("connectors.groupSearchPlaceholder"),emptyLabel:e("connectors.groupNoMatches"),selectedCountLabel:a=>e("connectors.groupSelectedCount",{count:a}),onChange:a=>h({chatId:a})}),(0,t.jsx)("button",{type:"button",className:"ghost connector-inline-link",onClick:()=>h({manualChat:!r.manualChat}),children:r.manualChat?e("connectors.chatListLink"):e("connectors.chatManualLink")})]})]}):r.mode==="dynamic"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide",children:[(0,t.jsxs)(T,{help:e("connectors.allowHint"),children:[e("connectors.fAllow"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)(De,{id:"cn-allow-chats",label:e("connectors.fAllow"),groups:G,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=>h({allowChats:a})})]}):null,r.mode==="dynamic"?(0,t.jsx)("div",{className:"cn-field-wide",children:(0,t.jsx)("div",{className:"muted connector-form-hint",dangerouslySetInnerHTML:{__html:e("connectors.dynamicHint")}})}):null,r.mode==="new-group"?(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-new-group-config",children:[(0,t.jsx)(T,{children:e("connectors.newGroupStrategy")}),(0,t.jsxs)("div",{className:"connector-strategy-options",role:"radiogroup","aria-label":e("connectors.newGroupStrategy"),children:[(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":!r.deduplicate,className:`connector-strategy-option${r.deduplicate?"":" selected"}`,onClick:()=>h({deduplicate:!1}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupFresh")}),(0,t.jsx)("small",{children:e("connectors.newGroupFreshHint")})]})]}),(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.deduplicate,className:`connector-strategy-option${r.deduplicate?" selected":""}`,onClick:()=>h({deduplicate:!0}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e("connectors.newGroupReuse")}),(0,t.jsx)("small",{children:e("connectors.newGroupReuseHint")})]})]})]}),r.deduplicate?(0,t.jsxs)("label",{className:"connector-dedup-field",htmlFor:"cn-dedup",children:[(0,t.jsx)(T,{help:(0,t.jsx)("span",{dangerouslySetInnerHTML:{__html:e("connectors.dedupHint")}}),children:e("connectors.fDedup")}),(0,t.jsx)("input",{id:"cn-dedup",value:r.dedup,onChange:a=>h({dedup:a.currentTarget.value}),placeholder:e("connectors.fDedupPh")})]}):null,(0,t.jsx)("p",{className:"connector-new-group-note",children:e("connectors.newGroupNotice")})]}):null,(0,t.jsxs)("label",{className:"cn-field cn-field-wide",htmlFor:"cn-instruction",children:[(0,t.jsxs)(T,{help:e("connectors.fInstructionPh"),children:[e("connectors.fInstruction"),(0,t.jsx)("span",{className:"muted cn-optional",children:e("connectors.optional")})]}),(0,t.jsx)("textarea",{id:"cn-instruction",rows:3,value:r.instruction,onChange:a=>h({instruction:a.currentTarget.value}),placeholder:e("connectors.fInstructionPh")})]}),(0,t.jsxs)("div",{className:"cn-field cn-field-wide connector-topic-message-config",children:[(0,t.jsx)(T,{help:e("connectors.topicMessageHint"),children:e("connectors.topicMessage")}),(0,t.jsx)("div",{className:"connector-topic-message-options",role:"radiogroup","aria-label":e("connectors.topicMessage"),children:["default","custom","template","none"].map(a=>{let l=a==="default"?"Default":a==="custom"?"Custom":a==="template"?"Template":"None";return(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":r.topicMessageMode===a,className:`connector-topic-message-option${r.topicMessageMode===a?" selected":""}`,onClick:()=>h({topicMessageMode:a}),children:[(0,t.jsx)("span",{className:"connector-strategy-radio","aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e(`connectors.topicMessage${l}`)}),(0,t.jsx)("small",{children:e(`connectors.topicMessage${l}Hint`)})]})]},a)})}),r.topicMessageMode==="custom"||r.topicMessageMode==="template"?(0,t.jsxs)("div",{className:"connector-topic-message-input",children:[(0,t.jsx)("input",{id:"cn-topic-message",type:"text",maxLength:200,value:r.topicMessageText,onChange:a=>h({topicMessageText:a.currentTarget.value}),"aria-label":e(r.topicMessageMode==="template"?"connectors.topicMessageTemplate":"connectors.topicMessageCustom"),placeholder:e(r.topicMessageMode==="template"?"connectors.topicMessageTemplatePh":"connectors.topicMessageCustomPh")}),(0,t.jsxs)("small",{children:[e(r.topicMessageMode==="template"?"connectors.topicMessageTemplateHelp":"connectors.topicMessageCustomHelp"),(0,t.jsxs)("span",{children:[Array.from(r.topicMessageText).length,"/200"]})]}),r.topicMessageMode==="template"?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("textarea",{id:"cn-topic-message-extractors",className:"connector-topic-message-extractors",rows:8,value:r.topicMessageExtractors,onChange:a=>h({topicMessageExtractors:a.currentTarget.value}),placeholder:e("connectors.topicMessageExtractorsPh"),"aria-label":e("connectors.topicMessageExtractors")}),(0,t.jsx)("small",{children:e("connectors.topicMessageExtractorsHelp")})]}):null]}):(0,t.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,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-store-payload",children:[(0,t.jsx)("input",{id:"cn-store-payload",type:"checkbox",checked:r.storePayload,onChange:a=>h({storePayload:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.storePayload")}),(0,t.jsx)("small",{children:e("connectors.storePayloadHint")})]})]}),(0,t.jsxs)("label",{className:"connector-log-policy cn-field-wide",htmlFor:"cn-suppress-final",children:[(0,t.jsx)("input",{id:"cn-suppress-final",type:"checkbox",checked:r.suppressFinalOutput,onChange:a=>h({suppressFinalOutput:a.currentTarget.checked})}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e("connectors.suppressFinalOutput")}),(0,t.jsx)("small",{children:e("connectors.suppressFinalOutputHint")})]})]}),(0,t.jsxs)("div",{className:"cn-field",children:[(0,t.jsx)(T,{children:e("connectors.fVerify")}),(0,t.jsx)(pe,{id:"cn-verify",label:e("connectors.fVerify"),value:r.verify,options:ke,onChange:a=>h({verify:a})})]}),(0,t.jsxs)("label",{className:"cn-field",htmlFor:"cn-secret",children:[(0,t.jsx)(T,{children:e("connectors.fSecret")}),(0,t.jsx)("input",{id:"cn-secret",value:r.secret,onChange:a=>h({secret:a.currentTarget.value}),placeholder:e(x?"connectors.fSecretEditPh":"connectors.fSecretPh")})]})]}),U?(0,t.jsx)("p",{className:`connector-create-message${U.error?" err":""}`,children:U.text}):null]})}),(0,t.jsx)("footer",{className:"connector-modal-actions",children:J?(0,t.jsx)("button",{type:"button",className:"primary",onClick:P,children:e("connectors.close")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",disabled:X,onClick:P,children:e("connectors.cancel")}),(0,t.jsx)("button",{id:"cn-create",type:"button",className:"primary",disabled:X,onClick:()=>{ae()},children:e(x?"connectors.btnSave":"connectors.btnCreate")})]})})]})}),(0,t.jsx)("section",{className:"overview-block connector-section connector-list-section",children:(0,t.jsx)("div",{className:"card connector-list-card",children:$?(0,t.jsx)(ie,{className:"connector-list-loading",label:e("connectors.loading"),compact:!0}):(0,t.jsx)(Ye,{connectors:R,bots:N,copiedId:g,editMsg:ee,groupName:z,modeLabel:Q,kindLabel:oe,onCopy:Ae,onEdit:ne,onToggle:a=>{se(a)},onTogglePayloadLogging:a=>{ve(a)},onDelete:a=>{$e(a)}})})})]}):(0,t.jsx)(Ee,{embedded:!0})]})}function Ve(o){let e=_(),s=o.created,d=s.isDynamic?`${s.url}?chatId=${s.exampleChat}`:s.url,f=s.exampleChat!=="<chatId>"?`\uFF08${o.groupName(s.exampleChat)}\uFF09`:"";return(0,t.jsx)("div",{className:"connector-created-wrap",children:(0,t.jsxs)("div",{className:"card connector-created-card",children:[(0,t.jsxs)("p",{className:"connector-created-title ok",children:[e(s.rotated?"connectors.rotatedPrefix":"connectors.createdPrefix",{name:s.name}),s.mode==="fixed"&&s.chatId?(0,t.jsxs)("span",{className:"muted",children:[" \xB7 ",e("connectors.createdDest",{name:o.groupName(s.chatId)})]}):null]}),(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsx)("code",{children:s.url})]}),s.secret?(0,t.jsxs)("p",{className:"connector-created-line",children:[(0,t.jsxs)("span",{className:"muted",children:[s.isToken?e("connectors.tokenLabel"):e("connectors.signLabel"),e("connectors.secretOnce")]}),(0,t.jsx)("code",{children:s.secret})]}):null,s.isToken&&s.isDynamic?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageDynamicLede",{gn:f})}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageDynamicNote")}})]}):s.isToken?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"muted connector-created-help",children:e("connectors.usageTokenLede")}),(0,t.jsx)("pre",{children:(0,t.jsx)("code",{children:`curl -X POST '${d}' -H 'content-type: application/json' -d '{}'`})}),(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageTokenNote")}})]}):(0,t.jsx)("p",{className:"muted connector-created-help",dangerouslySetInnerHTML:{__html:e("connectors.usageHmac")+(s.isDynamic?e("connectors.usageHmacDynamic"):"")}})]})})}function Ye(o){let e=_();return o.connectors.length?(0,t.jsx)(t.Fragment,{children:o.connectors.map(s=>{let d=o.bots.find(L=>L.larkAppId===s.target.botId),f=be(s.id),N=(s.verify?.type??"token")==="token",y=e(N?"connectors.badgeToken":"connectors.badgeSign"),I=s.target.mode==="fixed"&&s.target.chatId?e("connectors.dest",{name:o.groupName(s.target.chatId)}):"",k=o.editMsg?.id===s.id?o.editMsg:null,R=o.copiedId===s.id;return(0,t.jsxs)("div",{className:"card connector-item-card",children:[(0,t.jsxs)("div",{className:"connector-item-head",children:[(0,t.jsxs)("div",{className:"connector-item-main",children:[(0,t.jsxs)("div",{className:"connector-item-title",children:[(0,t.jsx)("b",{children:s.name}),(0,t.jsx)("span",{className:s.enabled?"connector-status-pill ok":"connector-status-pill muted",children:s.enabled?e("connectors.enabled"):e("connectors.disabled")})]}),(0,t.jsxs)("div",{className:"connector-item-meta",children:[(0,t.jsx)("span",{children:d?.botName||s.target.botId}),(0,t.jsx)("span",{children:o.kindLabel(s.target.kind)}),(0,t.jsx)("span",{children:o.modeLabel(s.target.mode)}),I?(0,t.jsx)("span",{children:I}):null,(0,t.jsx)("span",{children:y}),(0,t.jsx)("span",{children:s.loggingPolicy?.storePayload!==!1?e("connectors.payloadLogged",{days:s.loggingPolicy?.retentionDays??14}):e("connectors.metadataOnly")})]})]}),(0,t.jsx)("button",{className:`ghost connector-copy-button${R?" copied":""}`,type:"button",onClick:()=>o.onCopy(s),children:e(R?"connectors.copied":"connectors.copy")})]}),(0,t.jsxs)("div",{className:"connector-url-row",children:[(0,t.jsx)("span",{className:"muted",children:e("connectors.webhookUrl")}),(0,t.jsxs)("code",{children:[f,N?"/<token>":""]})]}),N?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.tokenHint")}}):null,s.target.kind==="workflow"?(0,t.jsx)("div",{className:"muted connector-item-note",children:e("connectors.legacyWorkflowNote")}):null,s.target.mode==="dynamic"?(0,t.jsx)("div",{className:"muted connector-item-note",dangerouslySetInnerHTML:{__html:e("connectors.dynamicReqHint")}}):null,s.promptEnvelope?.instruction?(0,t.jsxs)("div",{className:"muted connector-item-note",children:[e("connectors.instructionPrefix"),s.promptEnvelope.instruction]}):null,(0,t.jsx)("div",{className:"muted connector-item-note",children:s.topicMessage?.mode==="none"?e("connectors.topicMessageListNone"):s.topicMessage?.mode==="custom"||s.topicMessage?.mode==="template"?e("connectors.topicMessageListCustom",{text:s.topicMessage.text||""}):e("connectors.topicMessageListDefault")}),k?(0,t.jsx)("div",{className:k.error?"err connector-item-note":"muted connector-item-note",children:k.text}):null,(0,t.jsxs)("div",{className:"connector-item-actions",children:[(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onEdit(s),children:e("connectors.btnEdit")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onTogglePayloadLogging(s),children:s.loggingPolicy?.storePayload!==!1?e("connectors.btnDisablePayloadLog"):e("connectors.btnEnablePayloadLog")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onToggle(s),children:s.enabled?e("connectors.btnDisable"):e("connectors.btnEnable")}),(0,t.jsx)("button",{className:"ghost",type:"button",onClick:()=>o.onDelete(s),children:e("connectors.btnDel")})]})]},s.id)})}):(0,t.jsx)("p",{className:"muted connector-list-empty",children:e("connectors.empty")})}function gt(o){return re(o,(0,t.jsx)(Oe,{tab:"webhooks"}))}function mt(o){return re(o,(0,t.jsx)(Oe,{tab:"logs"}))}export{ut as buildConnectorInstructionUpdateBody,je as buildConnectorKindOptions,Ke as buildConnectorTopicMessageConfig,mt as renderConnectorsLogsPage,gt as renderConnectorsPage,Xe as replaceConnectorById};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{a as be,b as ye,c as we,d as ke}from"./chunk-R3FXBFQH.js";import{a as he,b as ve}from"./chunk-WLIVBPJC.js";import{a as me}from"./chunk-ZJVTGU5X.js";import{c as fe}from"./chunk-KEEYQ3WF.js";import{c as Y,g as Q,h as le,m as ce,n as ue,o as de,p as pe,q as ge}from"./chunk-5CJMHTT4.js";import{A as ae,c as q,d as V,u as K,x as ne}from"./chunk-6JTZJRQJ.js";import{a as se}from"./chunk-SYC6D5XU.js";import{a as Oe,d as ie}from"./chunk-5THX4DI2.js";import{c as X}from"./chunk-7SZRL6FY.js";var l=X(Oe(),1);var De=/^[A-Za-z0-9._-]{1,64}$/,Se=6,Pe=30;function ee(o,t){return we(o,t)}function Ie(o,t,r=Pe){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):Pe,a=o.length,u=Math.max(1,Math.ceil(a/n)),i=Number.isFinite(t)?Math.floor(t):1,f=Math.min(u,Math.max(1,i)),b=(f-1)*n,C=Math.min(a,b+n);return{rows:o.slice(b,C),page:f,totalPages:u,from:a===0?0:b+1,to:C,total:a}}async function Ce(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,u=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:u},async()=>{for(;a<o.length;){let i=a++;n[i]=await r(o[i])}})),n}function te(o){return De.test(o)&&o!=="."&&o!==".."}function oe(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return te(t)?t:"profile"}async function Z(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Ne(o){let t=await Z(),r=await Ce(t,Se,async i=>{try{let b=await(await fetch(`/api/role-profiles/${encodeURIComponent(i.profileId)}`)).json().catch(()=>({}));return[i.profileId,Array.isArray(b.entries)?b.entries:[]]}catch{return[i.profileId,[]]}}),n=new Set,a=[];for(let i of o.chats??[])for(let f of i.memberBots??[]){if(!f?.inChat||!f?.hasRole||!f?.larkAppId)continue;let b=ee(f.larkAppId,i.chatId);n.has(b)||(n.add(b),a.push({chatId:i.chatId,larkAppId:f.larkAppId}))}let u=await ke(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:u,loaded:!0}}async function Ge(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ce(t,Se,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),u=a?.hasEffectiveRole??a?.hasRole,i="effectiveContent"in a?a.effectiveContent:a.content,f=u?String(i??"").trim():"",b=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:f,status:f?b??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Re(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Ae(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 xe(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 Be(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Te(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:K("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:K("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:K("groups.roleProfileBootstrapDone",{name:n})}}function Ee(o,t,r,n,a){let u=new Set(n);a&&u.add(a);let i={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(f=>({larkAppId:f.larkAppId,botName:f.botName,inChat:u.has(f.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[i,...o.chats.filter(f=>f.chatId!==t)]}}var e=X(ie(),1);function Le(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function Fe(o){let t={};for(let r of ne(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function Ue(o){let t=o.chat,r=t.avatar??ae(t.chatId),[n,a]=(0,l.useState)(!1);(0,l.useEffect)(()=>{a(!1)},[r]);let u=t.name??t.chatId,i=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${i?" orb-has-img":""}`,style:Fe(u),"aria-hidden":"true",children:i?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function re(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 $e(o){let t=Re(o.bots,o.excludeIds),r=o.tr;return(0,e.jsx)(ve,{bots:t,selected:o.selected,onToggle:o.onToggle,searchPlaceholder:r("botPicker.searchPlaceholder"),noMatchLabel:r("botPicker.noMatch"),emptyLabel:r("botPicker.empty"),selectedCountLabel:n=>r("botPicker.selectedCount",{n:String(n)})})}function je(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 He(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let b of t.memberBots??[])b?.inChat&&a.set(b.larkAppId,r.groupRoleContentByBot.get(ee(b.larkAppId,t.chatId))??null);if(!be(a))return null;let i=ye(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!i)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let f=i.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${i.kind}`,children:n(f,{name:i.profileId,matched:i.matched,total:i.total,chat:i.chatMatched})})}function _e(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function We(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 Je(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=_e(n),u=We(a,o.tr),i=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${i}: ${u}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:i}),(0,e.jsx)("span",{className:"groups-bot-state",children:u})]},r.larkAppId)})})}var qe=(0,l.memo)(function(t){let{chat:r,tr:n}=t,u=(r.memberBots??[]).filter(i=>i.inChat).length;return(0,e.jsxs)(ue,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(Ue,{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)(He,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:u,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(Je,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(pe,{children:[(0,e.jsx)(Q,{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 ze(o){let{tr:t}=o,[r,n]=(0,l.useState)(!1),[a,u]=(0,l.useState)(null),[i,f]=(0,l.useState)(null),[b,C]=(0,l.useState)(!1),[m,S]=(0,l.useState)(new Set),[P,d]=(0,l.useState)(""),[w,v]=(0,l.useState)([]),[k,N]=(0,l.useState)(""),[L,x]=(0,l.useState)(""),[O,j]=(0,l.useState)(""),[$,W]=(0,l.useState)(!0),[A,B]=(0,l.useState)(""),[F,J]=(0,l.useState)(!1),[D,I]=(0,l.useState)(""),[p,G]=(0,l.useState)("");(0,l.useEffect)(()=>{let h=!0;return fetch("/api/feed-groups").then(async y=>{let s=await y.json().catch(()=>({}));if(!y.ok||!s.ok)throw new Error(s.message??s.error??`HTTP ${y.status}`);h&&(v(Array.isArray(s.groups)?s.groups:[]),N(typeof s.larkAppId=="string"?s.larkAppId:""))}).catch(y=>{h&&B(y instanceof Error?y.message:String(y))}).finally(()=>{h&&W(!1)}),()=>{h=!1}},[]),(0,l.useEffect)(()=>{if(!D)return;let h=!0,y=window.setInterval(()=>{fetch("/api/feed-groups").then(async s=>{let c=await s.json().catch(()=>({}));!s.ok||!c.ok||!h||(v(Array.isArray(c.groups)?c.groups:[]),N(typeof c.larkAppId=="string"?c.larkAppId:""),B(""),I(""),G(""))}).catch(()=>{})},1e3);return()=>{h=!1,window.clearInterval(y)}},[D]);async function U(){let h=k?`?larkAppId=${encodeURIComponent(k)}`:"",y=await fetch(`/api/feed-groups/auth-url${h}`),s=await y.json().catch(()=>({}));if(!y.ok||!s.authUrl){u({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:s.error??`HTTP ${y.status}`});return}I(String(s.authUrl)),G("")}async function H(h){J(!0);try{let y=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:h.trim()})}),s=await y.json().catch(()=>({}));if(!y.ok||!s.ok)throw new Error(s.message??s.error??`HTTP ${y.status}`);let c=await fetch("/api/feed-groups"),g=await c.json().catch(()=>({}));if(!c.ok||!g.ok)throw new Error(g.message??g.error??`HTTP ${c.status}`);v(Array.isArray(g.groups)?g.groups:[]),N(typeof g.larkAppId=="string"?g.larkAppId:""),B(""),I(""),G("")}catch(y){u({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:y instanceof Error?y.message:String(y)})}finally{J(!1)}}async function _(h){h.preventDefault();let y=new FormData(h.currentTarget),s=String(y.get("name")??"").trim(),c=String(y.get("bindWorkingDir")??"").trim(),g=String(y.get("roleProfileId")??"").trim(),R=[...m];if(R.length===0){u({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),u(null);try{let T=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:s||void 0,larkAppIds:R,bindWorkingDir:c||void 0,roleProfileId:g||void 0,feedGroupId:L||void 0,newFeedGroupName:O||void 0,feedGroupAppId:L||O?k:void 0})}),E=await T.json().catch(()=>({ok:!1,error:`HTTP ${T.status}`}));E.ok&&E.chatId?(f(E),o.onCreated(E,R,s)):(u({title:"\u521B\u5EFA\u5931\u8D25",reason:E.error??`HTTP ${T.status}`}),n(!1))}catch(T){u({title:"\u7F51\u7EDC\u9519\u8BEF",reason:T}),n(!1)}}if(i){let h=String(i.chatId),y=typeof i.shareLink=="string"&&i.shareLink?i.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(h)}`,s=i.invalidBotIds??[],c=i.invalidUserIds??[],g=Array.isArray(i.oncallBindings)?i.oncallBindings:[],R=g.filter(M=>M?.ok).length,T=g.filter(M=>!M?.ok),E=Te(typeof i.roleProfileId=="string"?i.roleProfileId:"",i.roleProfileBootstrapMessageId,i.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:h})," ",(0,e.jsx)("button",{type:"button","data-copy":h,onClick:()=>{me(h,t("sessions.copy")).then(M=>{M&&(C(!0),o.setTimer(()=>C(!1),800))})},children:t(b?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(i.creator??"?")})]}),i.feedGroupId?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u52A0\u5165\u98DE\u4E66\u6807\u7B7E",i.feedGroupName?`\u300C${String(i.feedGroupName)}\u300D`:"","\u3002"]}):null,i.feedGroupError?(0,e.jsxs)("p",{className:"hint-warn",children:["\u7FA4\u804A\u5DF2\u521B\u5EFA\uFF0C\u4F46\u6807\u7B7E\u8BBE\u7F6E\u5931\u8D25\uFF1A",String(i.feedGroupError)]}):null,(0,e.jsx)(Ve,{resp:i}),g.length>0?T.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(i.bindResolvedPath??"")}),"\uFF08",R,"/",g.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",R,"/",g.length,"\u3002",T.map((M,z)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(M?.larkAppId??"?")}),": ",String(M?.error??"unknown")]},`${M?.larkAppId??"?"}-${z}`))]}):null,E?(0,e.jsx)("p",{className:E.kind==="ok"?"hint-ok":"hint-warn",children:E.text}):null,s.length||c.length?(0,e.jsxs)("ul",{children:[s.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:s.join(", ")})]}):null,c.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:c.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:y,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:h=>{_(h)},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)($e,{bots:o.bots,tr:t,selected:m,onToggle:(h,y)=>S(s=>{let c=new Set(s);return y?c.add(h):c.delete(h),c})})})]}),(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(h=>({value:h.profileId,label:h.profileId}))],onChange:d}),(0,e.jsx)("small",{children:t("groups.roleProfileHelp")})]}),(0,e.jsxs)("fieldset",{className:"g-modal-field g-feed-group-field",children:[(0,e.jsx)("legend",{children:"\u98DE\u4E66\u6807\u7B7E\uFF08\u53EF\u9009\uFF09"}),(0,e.jsx)("input",{type:"hidden",name:"feedGroupId",value:L}),(0,e.jsx)(he,{groups:w,selectedId:L,newName:O,disabled:$||!!A,onChange:(h,y)=>{x(h),j(y)}}),(0,e.jsx)("small",{children:"\u5C55\u5F00\u540E\u53EF\u5728\u7B2C\u4E00\u884C\u8F93\u5165\u65B0\u6807\u7B7E\u540D\u79F0\uFF0C\u6216\u9009\u62E9\u4E0B\u65B9\u5DF2\u6709\u6807\u7B7E\u3002"}),$?(0,e.jsx)("small",{children:"\u6B63\u5728\u8BFB\u53D6\u98DE\u4E66\u6807\u7B7E\u2026"}):null,A?(0,e.jsxs)("div",{className:"hint-warn-inline",children:[(0,e.jsx)("small",{children:A})," ",(0,e.jsx)("button",{type:"button",disabled:F,onClick:()=>{U()},children:F?"\u6B63\u5728\u5B8C\u6210\u6388\u6743\u2026":"\u7ACB\u5373\u6388\u6743"}),(0,e.jsx)("small",{children:" \u6388\u6743\u540E\u4F1A\u5F39\u7A97\u63D0\u793A\u4F60\u7C98\u8D34\u56DE\u8C03\u5730\u5740\u3002"})]}):null,!$&&!A&&w.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),D?(0,e.jsx)("div",{className:"feed-group-auth-overlay",children:(0,e.jsxs)("section",{className:"feed-group-auth-card",role:"dialog","aria-modal":"true","aria-labelledby":"feed-group-auth-title",children:[(0,e.jsx)("h3",{id:"feed-group-auth-title",children:"\u6388\u6743\u98DE\u4E66\u6807\u7B7E"}),(0,e.jsxs)("p",{children:["\u70B9\u51FB\u4E0B\u9762\u7684\u6309\u94AE\uFF0C\u5728\u98DE\u4E66\u9875\u9762\u786E\u8BA4\u6388\u6743\u3002\u5982\u679C BotMux \u4E0E\u6D4F\u89C8\u5668\u5728\u540C\u4E00\u53F0\u7535\u8111\uFF0C\u786E\u8BA4\u540E\u4F1A\u81EA\u52A8\u5B8C\u6210\u6388\u6743\u3002\u5982\u679C BotMux \u8FD0\u884C\u5728\u8FDC\u7A0B\u865A\u62DF\u673A\u4E0A\uFF0C\u6D4F\u89C8\u5668\u4F1A\u56E0\u65E0\u6CD5\u8BBF\u95EE\u672C\u673A\u5730\u5740 ",(0,e.jsx)("code",{children:"127.0.0.1:9768"})," \u800C\u663E\u793A\u201C\u65E0\u6CD5\u8BBF\u95EE\u201D\uFF1B\u6B64\u65F6\u8BF7\u590D\u5236\u5730\u5740\u680F\u4E2D\u7684\u5B8C\u6574\u94FE\u63A5\u5E76\u7C98\u8D34\u5230\u4E0B\u65B9\u3002"]}),(0,e.jsx)("button",{type:"button",className:"primary feed-group-auth-open",onClick:()=>window.open(D,"_blank","noopener"),children:"\u8DF3\u8F6C\u98DE\u4E66\u6388\u6743"}),(0,e.jsxs)("label",{children:[(0,e.jsx)("span",{children:"\u8BF7\u628A\u70B9\u51FB\u6388\u6743\u540E\u7684\u5B8C\u6574\u94FE\u63A5\u7C98\u8D34\u5728\u8FD9\u91CC"}),(0,e.jsx)("input",{type:"url",value:p,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:h=>G(h.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{I(""),G("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!p.trim()||F,onClick:()=>{H(p)},children:F?"\u6B63\u5728\u5B8C\u6210\u6388\u6743\u2026":"\u5B8C\u6210\u6388\u6743"})]})]})}):null,(0,e.jsx)("div",{className:"g-create-status","data-create-status":!0,"aria-live":"polite",children:a?(0,e.jsx)(re,{...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 Ve(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,u=t.transferError,i=t.notifyMessageId,f=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,u?(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",u,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,i?(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:i}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,f?(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",f,"\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 Ke(o){let{chat:t,tr:r}=o,[n,a]=(0,l.useState)(!1),[u,i]=(0,l.useState)(null),[f,b]=(0,l.useState)(null),[C,m]=(0,l.useState)(new Set),S=(0,l.useMemo)(()=>new Set((t.memberBots??[]).filter(d=>d.inChat).map(d=>d.larkAppId)),[t]);async function P(d){d.preventDefault();let w=[...C];if(w.length===0){i({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),b(null);return}a(!0),i(null),b(null);try{let k=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:w})})).json();if(k.error==="no_proxy_bot")i({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(k.result){let N=Be(k.result);try{await o.onReloadGroups({force:!0}),b({result:N})}catch(L){b({result:N,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${L}`})}}else i({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(k)})}catch(v){i({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:d=>{P(d)},children:[(0,e.jsx)($e,{bots:o.bots,excludeIds:S,tr:r,selected:C,onToggle:(d,w)=>m(v=>{let k=new Set(v);return w?k.add(d):k.delete(d),k})}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[u?(0,e.jsx)(re,{...u}):null,f?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(je,{summary:f.result}),f.refreshError?(0,e.jsx)(re,{title:"\u5237\u65B0\u5931\u8D25",reason:f.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 Ze(o){let{tr:t}=o,[r,n]=(0,l.useState)([]),[a,u]=(0,l.useState)([]),[i,f]=(0,l.useState)(!0),[b,C]=(0,l.useState)(null),m=(0,l.useMemo)(()=>[...a].sort((p,G)=>p.profileId.localeCompare(G.profileId)),[a]),S=m.length>0,P=r.filter(p=>p.status==="empty").length,d=r.filter(p=>p.status==="error").length,w=!i&&!b&&r.length>0&&d===0,[v,k]=(0,l.useState)("new"),[N,L]=(0,l.useState)(o.suggestedProfileId),[x,O]=(0,l.useState)(""),[j,$]=(0,l.useState)(!1),[W,A]=(0,l.useState)(null),B=v==="overwrite"?x:N.trim(),F=t(v==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),J=b||(i?t("groups.saveProfilePreparing"):d?t("groups.saveProfileFailedLoadSummary",{count:d}):r.length?P?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:P}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,l.useEffect)(()=>{let p=!0;return f(!0),C(null),A(null),(async()=>{try{let[G,U]=await Promise.all([Ge(o.chat),Z().catch(()=>[])]);if(!p)return;let H=[...U].sort((_,h)=>_.profileId.localeCompare(h.profileId));n(G),u(U),O(_=>H.some(h=>h.profileId===_)?_:H[0]?.profileId??"")}catch(G){if(!p)return;n([]),u([]),O(""),C(G instanceof Error?G.message:String(G))}finally{p&&f(!1)}})(),()=>{p=!1}},[o.chat]);async function D(p){if(p.preventDefault(),!!w){if(!te(B)){A({text:t("groups.saveProfileInvalid"),className:"error"});return}$(!0),A({text:t("groups.saveProfileSaving")});try{let U=(await Promise.all(r.map(async H=>(await fetch(`/api/role-profiles/${encodeURIComponent(B)}/${encodeURIComponent(H.larkAppId)}`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({content:H.content,allowEmpty:!0})})).ok))).filter(Boolean).length;if(U!==r.length){A({text:t("groups.saveProfileFailed",{saved:U,total:r.length}),className:"error"}),$(!1);return}A({text:t("groups.saveProfileDone",{name:B,count:U}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(G){A({text:String(G),className:"error"}),$(!1)}}}function I(p){p==="overwrite"&&!S||(k(p),A(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:i?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:p=>{D(p)},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:i?"-":r.length})]}),d?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:d})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:i?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Y,{label:t("common.loading")})}):b?(0,e.jsx)("div",{className:"g-save-profile-empty",children:b}):r.length?r.map(p=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${p.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:p.botName??p.larkAppId}),(0,e.jsx)("code",{children:p.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${p.status==="error"?"error":"ok"}`,children:t(p.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},p.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:v==="new"?"active":"","data-save-profile-mode":"new","aria-pressed":v==="new",onClick:()=>I("new"),children:t("groups.saveProfileNew")}),(0,e.jsx)("button",{type:"button",className:v==="overwrite"?"active":"","data-save-profile-mode":"overwrite","aria-pressed":v==="overwrite",disabled:!S,onClick:()=>I("overwrite"),children:t("groups.saveProfileOverwrite")})]})]}),(0,e.jsxs)("label",{className:"form-row","data-profile-mode-row":"new",hidden:v!=="new",children:[(0,e.jsx)("span",{children:t("groups.saveProfileIdLabel")}),(0,e.jsx)("input",{type:"text",name:"profileId",value:N,maxLength:64,autoComplete:"off",onChange:p=>{L(p.currentTarget.value),A(null)}}),(0,e.jsx)("small",{children:t("groups.saveProfileInvalid")})]}),(0,e.jsxs)("div",{className:"form-row","data-profile-mode-row":"overwrite",hidden:v!=="overwrite",children:[(0,e.jsx)("span",{children:t("groups.saveProfileExistingLabel")}),S?(0,e.jsx)("div",{className:"g-save-profile-picker",children:m.map(p=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${p.profileId===x?"selected":""}`,"data-profile-id":p.profileId,"aria-pressed":p.profileId===x,onClick:()=>{O(p.profileId),k("overwrite"),A(null)},children:[(0,e.jsx)("span",{children:p.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:p.entryCount??0})})]},p.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(v==="overwrite"?"groups.saveProfileTargetOverwrite":"groups.saveProfileTargetNew")})]}),(0,e.jsx)("div",{className:`g-save-profile-summary ${w?"":"warn"}`,children:J}),(0,e.jsx)("div",{className:`g-save-profile-status ${W?.className??""}`,"data-save-profile-status":!0,children:W?.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:!w||j||v==="overwrite"&&!x,children:j?t("groups.saveProfileSaving"):F})]})]})]})}function Xe(o){let{member:t,tr:r}=o,n=(0,l.useRef)(null),[a,u]=(0,l.useState)(!!t.oncallChat),[i,f]=(0,l.useState)(t.oncallChat?.workingDir??""),[b,C]=(0,l.useState)(!1),[m,S]=(0,l.useState)(null);async function P(){S(null);let d=i.trim();if(a&&!d){S({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}C(!0);try{let w=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,v=a?await fetch(w,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:d})}):await fetch(w,{method:"DELETE"}),k=await v.json().catch(()=>({}));if(v.ok&&k.ok){S({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${k.resolvedPath??d}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else S({text:`\u2717 ${k.error??v.status}`,className:"hint-warn-inline"})}catch(w){S({text:`\u2717 ${w?.message??w}`,className:"hint-warn-inline"})}finally{C(!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:d=>{u(d.currentTarget.checked),d.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:i,disabled:!a,onChange:d=>f(d.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:b,onClick:()=>{P()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${m?.className??""}`,"data-status":!0,children:m?.text??""})]})]})}function Ye(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(m=>m.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[u,i]=(0,l.useState)(()=>new Set);function f(m,S){i(P=>{let d=new Set(P);return S?d.add(m):d.delete(m),d})}async function b(){let m=[...u];if(m.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${m.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 P=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:m})})).json(),d=(P.result??[]).map(w=>{if(!w.ok)return`${w.larkAppId}: \u5931\u8D25 (${w.error??"unknown"})`;let v=w.closedSessions??[],k=v.filter(x=>!x.ok).length,N=v.length-k,L=v.length===0?"":k===0?`\uFF08\u5173\u95ED ${N} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${N} \u4E2A\uFF0C${k} \u4E2A\u5931\u8D25\uFF09`;return`${w.larkAppId}: OK${L}`}).join(`
|
|
2
|
+
`);alert(d||`Unexpected: ${JSON.stringify(P)}`),await o.onReloadGroups({force:!0})}catch(S){alert("Network error: "+S)}finally{o.onClose()}}async function C(){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 m=[...n].sort((P,d)=>(d.larkAppId===a?1:0)-(P.larkAppId===a?1:0)),S=[];for(let P of m)try{let d=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:P.larkAppId})}),w=await d.json();if(w.ok){let v=w.closedSessions??[],k=v.filter(x=>!x.ok).length,N=v.length-k,L=v.length===0?"":k===0?`
|
|
3
|
+
\u5173\u95ED\u4E86 ${N} \u4E2A\u4F1A\u8BDD\u3002`:`
|
|
4
|
+
\u5173\u95ED\u4E86 ${N} \u4E2A\u4F1A\u8BDD\uFF0C${k} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25\u3002`;alert(`\u5DF2\u89E3\u6563\uFF08\u7531 ${P.botName??P.larkAppId} \u6267\u884C\uFF09${L}`),await o.onReloadGroups({force:!0}),o.onClose();return}S.push(`${P.botName??P.larkAppId}: ${w.error??d.status}`)}catch(d){S.push(`${P.botName??P.larkAppId}: ${d}`)}alert(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A
|
|
5
|
+
${S.join(`
|
|
6
|
+
`)}
|
|
7
|
+
|
|
8
|
+
\u5EFA\u8BAE\u6539\u7528\u300C\u9000\u51FA\u7FA4\u804A\u300D\u3002`)}return(0,e.jsxs)("article",{className:"g-manage-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:r("groups.manageTitle",{name:t.name??t.chatId})})}),(0,e.jsxs)("div",{className:"g-manage-meta",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{children:"chatId"}),(0,e.jsx)("code",{children:t.chatId})]}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{children:r("groups.owner")}),(0,e.jsx)("code",{children:t.ownerId??r("common.unknown")})]})]}),(0,e.jsxs)("fieldset",{children:[(0,e.jsx)("legend",{children:r("groups.oncall")}),(0,e.jsx)("p",{children:(0,e.jsx)("small",{children:r("groups.oncallHelp")})}),n.length===0?(0,e.jsx)("p",{className:"empty",children:"\u6CA1\u6709\u673A\u5668\u4EBA\u5728\u7FA4\u91CC"}):n.map(m=>(0,e.jsx)(Xe,{chat:t,member:m,tr:r,onSaved:async()=>{await o.onReloadGroups({force:!0})}},m.larkAppId))]}),(0,e.jsxs)("fieldset",{children:[(0,e.jsx)("legend",{children:r("groups.leaveTitle")}),n.length===0?(0,e.jsx)("p",{className:"empty",children:"\u6CA1\u6709\u673A\u5668\u4EBA\u5728\u7FA4\u91CC"}):(0,e.jsx)("div",{className:"g-leave-picker",children:n.map(m=>(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox",name:"leave-bot",value:m.larkAppId,checked:u.has(m.larkAppId),onChange:S=>f(m.larkAppId,S.currentTarget.checked)}),(0,e.jsxs)("span",{className:"checkbox-row-main",children:[(0,e.jsx)("strong",{children:m.botName??m.larkAppId}),m.larkAppId===a?(0,e.jsx)("small",{children:"\xB7 \u7FA4\u4E3B"}):null]})]},m.larkAppId))})]}),(0,e.jsx)("p",{className:"g-manage-danger-hint",children:r("groups.dangerHint")}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:o.onClose,children:r("sessions.dismiss")}),(0,e.jsx)("button",{id:"g-leave-btn",type:"button",disabled:n.length===0,onClick:()=>{b()},children:r("groups.leaveSelected")}),(0,e.jsx)("button",{id:"g-disband-btn",type:"button",className:"contrast",disabled:n.length===0,onClick:()=>{C()},children:r("groups.disband")})]})]})}function Qe(o){let t=(0,l.useRef)(null);(0,l.useEffect)(()=>{let a=t.current;if(!a)return;let u=()=>o.onClose();return a.addEventListener("close",u),()=>a.removeEventListener("close",u)},[o.onClose]),(0,l.useEffect)(()=>{let a=t.current;a&&(o.dialog&&!a.open&&a.showModal(),!o.dialog&&a.open&&a.close())},[o.dialog]);let r=null;o.dialog?.type==="create"?r=(0,e.jsx)(ze,{bots:o.snapshot.bots,roleProfiles:o.dialog.roleProfiles,tr:o.tr,onClose:o.onClose,onCreated:o.onCreated,setTimer:o.setTimer}):o.dialog?.type==="add-bots"?r=(0,e.jsx)(Ke,{chat:o.dialog.chat,bots:o.snapshot.bots,tr:o.tr,onClose:o.onClose,onReloadGroups:o.onReloadGroups}):o.dialog?.type==="save-profile"?r=(0,e.jsx)(Ze,{chat:o.dialog.chat,suggestedProfileId:o.dialog.suggestedProfileId,tr:o.tr,onClose:o.onClose,onRefreshRoleContext:o.onRefreshRoleContext,setTimer:o.setTimer}):o.dialog?.type==="manage"&&(r=(0,e.jsx)(Ye,{chat:o.dialog.chat,tr:o.tr,onClose:o.onClose,onReloadGroups:o.onReloadGroups}));let n=o.dialog?.type==="create"?"groups-create-modal":void 0;return(0,e.jsx)("dialog",{id:"g-drawer",className:n,ref:t,onMouseDown:a=>{a.target===a.currentTarget&&a.currentTarget.close()},children:r})}function et(){let o=fe(),t=(0,l.useRef)(!1),r=(0,l.useRef)(q),n=(0,l.useRef)(new Set),a=(0,l.useRef)(new Map),u=(0,l.useRef)(0),[i,f]=(0,l.useState)(q),[b,C]=(0,l.useState)(()=>Le()),[m,S]=(0,l.useState)({q:"",missingOnly:!1}),[P,d]=(0,l.useState)(!0),[w,v]=(0,l.useState)(null),[k,N]=(0,l.useState)(!1),[L,x]=(0,l.useState)(null),[O,j]=(0,l.useState)(1),$=(0,l.useCallback)(s=>{f(c=>{let g=typeof s=="function"?s(c):s;return r.current=g,g})},[]),W=(0,l.useCallback)((s,c)=>{let g=window.setTimeout(()=>{n.current.delete(g),t.current&&s()},c);return n.current.add(g),g},[]),A=(0,l.useCallback)(s=>new Promise(c=>{let g=window.setTimeout(()=>{n.current.delete(g),a.current.delete(g),c()},s);n.current.add(g),a.current.set(g,c)}),[]),B=(0,l.useCallback)(async s=>{let c=++u.current;try{let g=await Ne(s??r.current);t.current&&c===u.current&&C(g)}catch{t.current&&c===u.current&&C({...Le(),loaded:!0})}},[]),F=(0,l.useCallback)(async s=>{let c=await V({force:s?.force});return t.current&&($(c),v(null),B(c)),c},[B,$]),J=(0,l.useCallback)(async(s,c)=>{let g=[600,1200,1200,1200,1200,1200];for(let R of g){if(await A(R),!t.current)return;let T;try{T=await V({force:!0})}catch{continue}if(!t.current)return;let E=(T.chats??[]).find(M=>M.chatId===s);if(E&&xe(E,c)){$(T),B(T);return}}},[A,B,$]);(0,l.useEffect)(()=>(t.current=!0,(async()=>{d(!0);try{await F()}catch(s){t.current&&($(q),v(s instanceof Error?s.message:String(s)),B(q))}finally{t.current&&d(!1)}})(),()=>{t.current=!1,u.current+=1;for(let s of n.current)window.clearTimeout(s);n.current.clear();for(let s of a.current.values())s();a.current.clear()}),[F]);let D=(0,l.useMemo)(()=>Ae(i.chats,m),[i.chats,m]),I=(0,l.useMemo)(()=>Ie(D,O),[D,O]);(0,l.useEffect)(()=>{O!==I.page&&j(I.page)},[O,I.page]);async function p(){N(!0);try{await F({force:!0})}catch(s){v(s instanceof Error?s.message:String(s))}finally{t.current&&N(!1)}}async function G(){if(r.current.bots.length===0){alert(o("groups.noBotsOnline"));return}let s=[];try{s=await Z()}catch{}t.current&&x({type:"create",roleProfiles:s})}function U(s,c,g){let R=String(s.chatId),T=Array.isArray(s.invalidBotIds)?s.invalidBotIds:[],E=c.filter(Me=>!T.includes(Me)),M=new Set(E);typeof s.creator=="string"&&s.creator&&M.add(s.creator);let z=Ee(r.current,R,g||R,E,s.creator);$(z),B(z),J(R,M).catch(()=>{})}let H=(0,l.useCallback)(s=>{let c=new Set((s.memberBots??[]).filter(R=>R.inChat).map(R=>R.larkAppId));if(!r.current.bots.filter(R=>!c.has(R.larkAppId)).length){alert("All configured bots are already in this chat.");return}x({type:"add-bots",chat:s})},[]),_=(0,l.useCallback)(s=>{let c=oe(s.name??""),g=c==="profile"?oe(s.chatId):c;x({type:"save-profile",chat:s,suggestedProfileId:g})},[]),h=(0,l.useCallback)(s=>{x({type:"manage",chat:s})},[]);function y(s){let c=document.getElementById("g-body");c&&(c.scrollTop=0),j(s)}return(0,e.jsxs)("section",{className:"page groups-page",children:[(0,e.jsxs)("div",{className:"page-heading",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"eyebrow",children:o("nav.groups")}),(0,e.jsx)("h1",{children:o("groups.title")})]}),(0,e.jsx)("div",{className:"page-heading-actions",children:(0,e.jsx)(Q,{id:"g-create",className:"page-primary-action",onClick:()=>{G()},children:o("groups.create")})})]}),(0,e.jsxs)("form",{id:"g-filters",className:"filters dashboard-toolbar groups-toolbar",onSubmit:s=>s.preventDefault(),children:[(0,e.jsx)("input",{type:"search",name:"q",placeholder:o("groups.search"),value:m.q,onChange:s=>{let c=s.currentTarget.value;j(1),S(g=>({...g,q:c}))}}),(0,e.jsxs)("label",{className:"filter-toggle",children:[(0,e.jsx)("input",{type:"checkbox",name:"missing",checked:m.missingOnly,onChange:s=>{let c=s.currentTarget.checked;j(1),S(g=>({...g,missingOnly:c}))}}),(0,e.jsx)("span",{className:"filter-toggle-label",children:o("groups.missingOnly")}),(0,e.jsx)("span",{className:"filter-toggle-switch","aria-hidden":"true"})]}),(0,e.jsx)("span",{className:"groups-toolbar-spacer","aria-hidden":"true"}),(0,e.jsxs)("span",{className:"groups-toolbar-count",children:[o("groups.matrixTitle")," ",P?"-/-":`${D.length}/${i.chats.length}`]}),(0,e.jsx)(le,{id:"g-refresh",label:o("groups.refresh"),busy:k,disabled:k,onClick:()=>{p()}})]}),w?(0,e.jsxs)("p",{className:"hint-warn",children:["\u52A0\u8F7D\u7FA4\u7EC4\u5931\u8D25\uFF1A",w]}):null,(0,e.jsx)("section",{className:"overview-block groups-matrix-section",children:P?(0,e.jsx)("div",{id:"g-loading",children:(0,e.jsx)(Y,{label:o("common.loading")})}):(0,e.jsxs)("div",{className:"groups-list-wrap",id:"g-table-wrap",children:[D.length===0?(0,e.jsx)("div",{className:"empty groups-list-empty",id:"g-body",children:o("groups.empty")}):(0,e.jsx)(ce,{id:"g-body",className:"groups-list",children:I.rows.map(s=>(0,e.jsx)(qe,{chat:s,bots:i.bots,roleContext:b,tr:o,onAddBots:H,onSaveProfile:_,onManage:h},s.chatId))}),D.length>0&&I.totalPages>1?(0,e.jsxs)("nav",{className:"groups-pagination","aria-label":o("groups.paginationLabel"),children:[(0,e.jsx)("span",{className:"groups-pagination-status","aria-live":"polite",children:o("groups.pageStatus",{page:I.page,pages:I.totalPages,from:I.from,to:I.to,total:I.total})}),(0,e.jsxs)("div",{className:"groups-pagination-actions",children:[(0,e.jsx)("button",{type:"button",disabled:I.page<=1,onClick:()=>y(I.page-1),children:o("groups.prevPage")}),(0,e.jsx)("button",{type:"button",disabled:I.page>=I.totalPages,onClick:()=>y(I.page+1),children:o("groups.nextPage")})]})]}):null]})}),(0,e.jsx)(Qe,{dialog:L,snapshot:i,tr:o,onClose:()=>x(null),onCreated:U,onReloadGroups:F,onRefreshRoleContext:()=>B(),setTimer:W})]})}function ft(o){return se(o,(0,e.jsx)(et,{}))}export{Ke as AddBotsDialog,ft as renderGroupsPage};
|