botmux 3.14.0 → 3.15.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.
Files changed (121) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/tmux-pipe-backend.d.ts +30 -0
  3. package/dist/adapters/backend/tmux-pipe-backend.d.ts.map +1 -1
  4. package/dist/adapters/backend/tmux-pipe-backend.js +60 -0
  5. package/dist/adapters/backend/tmux-pipe-backend.js.map +1 -1
  6. package/dist/adapters/backend/types.d.ts +7 -0
  7. package/dist/adapters/backend/types.d.ts.map +1 -1
  8. package/dist/adapters/backend/types.js.map +1 -1
  9. package/dist/adapters/cli/cursor.d.ts.map +1 -1
  10. package/dist/adapters/cli/cursor.js +13 -1
  11. package/dist/adapters/cli/cursor.js.map +1 -1
  12. package/dist/adapters/cli/dsh.d.ts.map +1 -1
  13. package/dist/adapters/cli/dsh.js +5 -1
  14. package/dist/adapters/cli/dsh.js.map +1 -1
  15. package/dist/adapters/cli/pi.d.ts +14 -1
  16. package/dist/adapters/cli/pi.d.ts.map +1 -1
  17. package/dist/adapters/cli/pi.js +21 -1
  18. package/dist/adapters/cli/pi.js.map +1 -1
  19. package/dist/adapters/cli/shared-hints.d.ts.map +1 -1
  20. package/dist/adapters/cli/shared-hints.js +29 -24
  21. package/dist/adapters/cli/shared-hints.js.map +1 -1
  22. package/dist/adapters/cli/types.d.ts +4 -0
  23. package/dist/adapters/cli/types.d.ts.map +1 -1
  24. package/dist/bot-registry.d.ts +22 -0
  25. package/dist/bot-registry.d.ts.map +1 -1
  26. package/dist/bot-registry.js +24 -0
  27. package/dist/bot-registry.js.map +1 -1
  28. package/dist/cli.d.ts.map +1 -1
  29. package/dist/cli.js +8 -3
  30. package/dist/cli.js.map +1 -1
  31. package/dist/core/command-discovery.d.ts.map +1 -1
  32. package/dist/core/command-discovery.js +4 -1
  33. package/dist/core/command-discovery.js.map +1 -1
  34. package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
  35. package/dist/core/dashboard-ipc-server.js +42 -1
  36. package/dist/core/dashboard-ipc-server.js.map +1 -1
  37. package/dist/core/skills/frontmatter.d.ts.map +1 -1
  38. package/dist/core/skills/frontmatter.js +6 -1
  39. package/dist/core/skills/frontmatter.js.map +1 -1
  40. package/dist/core/worker-pool.d.ts.map +1 -1
  41. package/dist/core/worker-pool.js +21 -8
  42. package/dist/core/worker-pool.js.map +1 -1
  43. package/dist/daemon.d.ts.map +1 -1
  44. package/dist/daemon.js +4 -10
  45. package/dist/daemon.js.map +1 -1
  46. package/dist/dashboard/bot-payload.d.ts +4 -0
  47. package/dist/dashboard/bot-payload.d.ts.map +1 -1
  48. package/dist/dashboard/bot-payload.js +1 -0
  49. package/dist/dashboard/bot-payload.js.map +1 -1
  50. package/dist/dashboard/web/bot-defaults-page.d.ts +7 -0
  51. package/dist/dashboard/web/bot-defaults-page.d.ts.map +1 -1
  52. package/dist/dashboard/web/bot-defaults-page.js +96 -1
  53. package/dist/dashboard/web/bot-defaults-page.js.map +1 -1
  54. package/dist/dashboard/web/bot-defaults.d.ts +2 -0
  55. package/dist/dashboard/web/bot-defaults.d.ts.map +1 -1
  56. package/dist/dashboard/web/bot-defaults.js.map +1 -1
  57. package/dist/dashboard/web/i18n.d.ts.map +1 -1
  58. package/dist/dashboard/web/i18n.js +8 -0
  59. package/dist/dashboard/web/i18n.js.map +1 -1
  60. package/dist/dashboard/web/skills-page.d.ts.map +1 -1
  61. package/dist/dashboard/web/skills-page.js +4 -2
  62. package/dist/dashboard/web/skills-page.js.map +1 -1
  63. package/dist/dashboard-web/app.js +1 -1
  64. package/dist/dashboard-web/chunks/bot-defaults-page-65SMZ4QY.js +10 -0
  65. package/dist/dashboard-web/chunks/{chunk-2WQDS65D.js → chunk-IKN6WURK.js} +1 -1
  66. package/dist/dashboard-web/chunks/{chunk-Q2MT4VWH.js → chunk-VMWNR3SV.js} +4 -4
  67. package/dist/dashboard-web/chunks/{chunk-6O7KXFD2.js → chunk-Z7B3E3US.js} +1 -1
  68. package/dist/dashboard-web/chunks/{chunk-U3ZFSO7E.js → chunk-Z7DO42GJ.js} +1 -1
  69. package/dist/dashboard-web/chunks/{connectors-page-2KZO5KSJ.js → connectors-page-CPH6VVFY.js} +1 -1
  70. package/dist/dashboard-web/chunks/{feedback-page-CLVTOLLO.js → feedback-page-J2FKQ3LK.js} +1 -1
  71. package/dist/dashboard-web/chunks/{groups-page-HLASRTSY.js → groups-page-VDOOLS4M.js} +1 -1
  72. package/dist/dashboard-web/chunks/{insights-page-4RPU2CRU.js → insights-page-A2LWTKJD.js} +1 -1
  73. package/dist/dashboard-web/chunks/{monitor-room-OTKQ2CXK.js → monitor-room-2YR752E3.js} +1 -1
  74. package/dist/dashboard-web/chunks/{monitoring-page-IJPUB6JT.js → monitoring-page-BGYSKZGM.js} +1 -1
  75. package/dist/dashboard-web/chunks/{office-page-QSR3J44Y.js → office-page-ZZHTEAE4.js} +1 -1
  76. package/dist/dashboard-web/chunks/{overview-page-6OK63V4V.js → overview-page-7NYPKQSB.js} +1 -1
  77. package/dist/dashboard-web/chunks/{roles-page-6NWJMOB5.js → roles-page-YUC4YLJG.js} +1 -1
  78. package/dist/dashboard-web/chunks/{schedules-page-6I3LNXD4.js → schedules-page-2L2NKTDJ.js} +1 -1
  79. package/dist/dashboard-web/chunks/{sessions-page-B2TXGJDO.js → sessions-page-DYZZMKFL.js} +1 -1
  80. package/dist/dashboard-web/chunks/{settings-page-6KJADSC6.js → settings-page-LIULUSMH.js} +1 -1
  81. package/dist/dashboard-web/chunks/{skills-page-M2Q6L5CB.js → skills-page-DQPBBI3T.js} +2 -2
  82. package/dist/dashboard-web/chunks/{team-federation-page-7I7FDE3B.js → team-federation-page-LQKLDV4K.js} +1 -1
  83. package/dist/dashboard-web/chunks/{v3-page-HQXRL65L.js → v3-page-RVKQIMAP.js} +1 -1
  84. package/dist/dashboard-web/chunks/{whiteboards-page-LQKC4TAZ.js → whiteboards-page-S5K55HRZ.js} +1 -1
  85. package/dist/dashboard.js +11 -1
  86. package/dist/dashboard.js.map +1 -1
  87. package/dist/dsh-runner.js +8 -1
  88. package/dist/dsh-runner.js.map +1 -1
  89. package/dist/i18n/en.d.ts.map +1 -1
  90. package/dist/i18n/en.js +15 -26
  91. package/dist/i18n/en.js.map +1 -1
  92. package/dist/i18n/zh.d.ts.map +1 -1
  93. package/dist/i18n/zh.js +15 -26
  94. package/dist/i18n/zh.js.map +1 -1
  95. package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
  96. package/dist/im/lark/event-dispatcher.js +5 -19
  97. package/dist/im/lark/event-dispatcher.js.map +1 -1
  98. package/dist/services/bridge-fallback-gate.d.ts +15 -7
  99. package/dist/services/bridge-fallback-gate.d.ts.map +1 -1
  100. package/dist/services/bridge-fallback-gate.js +43 -16
  101. package/dist/services/bridge-fallback-gate.js.map +1 -1
  102. package/dist/services/peer-cross-ref-store.d.ts +8 -0
  103. package/dist/services/peer-cross-ref-store.d.ts.map +1 -0
  104. package/dist/services/peer-cross-ref-store.js +95 -0
  105. package/dist/services/peer-cross-ref-store.js.map +1 -0
  106. package/dist/services/pi-transcript.d.ts.map +1 -1
  107. package/dist/services/pi-transcript.js +10 -6
  108. package/dist/services/pi-transcript.js.map +1 -1
  109. package/dist/services/structured-bridge-clis.d.ts +13 -4
  110. package/dist/services/structured-bridge-clis.d.ts.map +1 -1
  111. package/dist/services/structured-bridge-clis.js +13 -3
  112. package/dist/services/structured-bridge-clis.js.map +1 -1
  113. package/dist/types.d.ts +1 -0
  114. package/dist/types.d.ts.map +1 -1
  115. package/dist/utils/bot-routing.d.ts +1 -1
  116. package/dist/utils/bot-routing.d.ts.map +1 -1
  117. package/dist/utils/bot-routing.js.map +1 -1
  118. package/dist/worker.js +233 -11
  119. package/dist/worker.js.map +1 -1
  120. package/package.json +5 -1
  121. package/dist/dashboard-web/chunks/bot-defaults-page-4RENHE7J.js +0 -10
@@ -1 +1 @@
1
- import{q as T}from"./chunk-5CJMHTT4.js";import{s as t}from"./chunk-Q2MT4VWH.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{s as t}from"./chunk-VMWNR3SV.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{C as i,G as c,b as r}from"./chunk-Q2MT4VWH.js";var l={chats:[],bots:[]};async function A(){try{l=await r()}catch{}}var p=new Set(["working","analyzing","active","starting"]);function m(d){let s=new Map,e=t=>{let a=s.get(t);return a||(a={botName:t,larkAppId:t,cliId:"unknown",online:!1,sessions:[],active:[],busy:[],attention:[],lastActiveAt:0},s.set(t,a)),a};for(let t of l.bots??[]){let a=e(t.larkAppId??t.botName??"-");a.online=!0,t.botName&&(a.botName=t.botName),t.botAvatarUrl&&(a.botAvatarUrl=t.botAvatarUrl),t.cliId&&(a.cliId=t.cliId),t.brand&&(a.brand=t.brand)}let b=[...d].sort((t,a)=>+(t.status==="closed")-+(a.status==="closed"));for(let t of b){let a=t.larkAppId??t.botName??"-";if(t.status==="closed"&&!s.has(a))continue;let o=e(a);t.botName&&(o.botName===o.larkAppId||!o.botName)&&(o.botName=t.botName),o.sessions.push(t),t.cliId&&o.cliId==="unknown"&&(o.cliId=t.cliId),o.lastActiveAt=Math.max(o.lastActiveAt,Number(t.lastMessageAt??0)),t.status!=="closed"&&(o.active.push(t),p.has(t.status)&&o.busy.push(t),c(t)&&o.attention.push(t))}for(let t of s.values())if(t.botName===t.larkAppId){let a=i(t.larkAppId);a&&(t.botName=a)}return[...s.values()].sort((t,a)=>{let o=n=>n.attention.length?0:n.busy.length?1:n.online||n.active.length?2:3;return o(t)!==o(a)?o(t)-o(a):a.lastActiveAt-t.lastActiveAt})}export{A as a,m as b};
1
+ import{C as i,G as c,b as r}from"./chunk-VMWNR3SV.js";var l={chats:[],bots:[]};async function A(){try{l=await r()}catch{}}var p=new Set(["working","analyzing","active","starting"]);function m(d){let s=new Map,e=t=>{let a=s.get(t);return a||(a={botName:t,larkAppId:t,cliId:"unknown",online:!1,sessions:[],active:[],busy:[],attention:[],lastActiveAt:0},s.set(t,a)),a};for(let t of l.bots??[]){let a=e(t.larkAppId??t.botName??"-");a.online=!0,t.botName&&(a.botName=t.botName),t.botAvatarUrl&&(a.botAvatarUrl=t.botAvatarUrl),t.cliId&&(a.cliId=t.cliId),t.brand&&(a.brand=t.brand)}let b=[...d].sort((t,a)=>+(t.status==="closed")-+(a.status==="closed"));for(let t of b){let a=t.larkAppId??t.botName??"-";if(t.status==="closed"&&!s.has(a))continue;let o=e(a);t.botName&&(o.botName===o.larkAppId||!o.botName)&&(o.botName=t.botName),o.sessions.push(t),t.cliId&&o.cliId==="unknown"&&(o.cliId=t.cliId),o.lastActiveAt=Math.max(o.lastActiveAt,Number(t.lastMessageAt??0)),t.status!=="closed"&&(o.active.push(t),p.has(t.status)&&o.busy.push(t),c(t)&&o.attention.push(t))}for(let t of s.values())if(t.botName===t.larkAppId){let a=i(t.larkAppId);a&&(t.botName=a)}return[...s.values()].sort((t,a)=>{let o=n=>n.attention.length?0:n.busy.length?1:n.online||n.active.length?2:3;return o(t)!==o(a)?o(t)-o(a):a.lastActiveAt-t.lastActiveAt})}export{A as a,m as b};
@@ -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-2WQDS65D.js";import{a as le,c as ie,g as Se,l as T,q as de}from"./chunk-5CJMHTT4.js";import"./chunk-G5XGBCM6.js";import"./chunk-Q2MT4VWH.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-IKN6WURK.js";import{a as le,c as ie,g as Se,l as T,q as de}from"./chunk-5CJMHTT4.js";import"./chunk-G5XGBCM6.js";import"./chunk-VMWNR3SV.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 +1 @@
1
- import{s as n}from"./chunk-Q2MT4VWH.js";import{a as v}from"./chunk-SYC6D5XU.js";import{a as F,d as f}from"./chunk-5THX4DI2.js";import{c as m}from"./chunk-7SZRL6FY.js";var r=m(F(),1);var e=m(f(),1);function C(){let s=new Date,o=new Date(s.getTime()-30*864e5);return new URLSearchParams({from:o.toISOString(),to:s.toISOString()})}async function c(s,o){let i=await fetch(`${s}?${o}`);if(!i.ok)throw new Error(await i.text());return i.json()}function E(){let[s,o]=(0,r.useState)(),[i,k]=(0,r.useState)([]),[l,y]=(0,r.useState)([]),[h,S]=(0,r.useState)([]),[u,R]=(0,r.useState)(),[b,p]=(0,r.useState)(""),g=async a=>{try{p("");let t=C(),[I,D,T,d]=await Promise.all([c("/api/feedback/analytics/summary",t),c("/api/feedback/analytics/trend",t),c("/api/feedback/analytics/reasons",t),c("/api/feedback/analytics/deliveries",new URLSearchParams([...t,["limit","25"],...a?[["cursor",a]]:[]]))]);o(I),k(D.items),y(T.items),S(x=>a?[...x,...d.items]:d.items),R(d.nextCursor)}catch(t){p(t instanceof Error?t.message:String(t))}};(0,r.useEffect)(()=>{g()},[]);let N=Math.max(1,...i.map(a=>a.ratings)),P=Math.max(1,...l.map(a=>a.count));return(0,e.jsxs)("div",{className:"page feedback-page",children:[(0,e.jsx)("header",{className:"sect-header",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{children:n("feedback.title")}),(0,e.jsx)("p",{children:n("feedback.subtitle")})]})}),b&&(0,e.jsx)("p",{className:"error-banner",children:b}),(0,e.jsx)("section",{className:"feedback-kpis",children:[["feedback.delivered",s?.delivered],["feedback.rated",s?.ratedDeliveries],["feedback.coverage",s?`${Math.round(s.ratingCoverage*100)}%`:void 0],["feedback.positiveRate",s?`${Math.round(s.positiveRate*100)}%`:void 0],["feedback.deliveryFailures",s?.deliveryFailures],["feedback.outboxFailures",s?.outboxFailures]].map(([a,t])=>(0,e.jsxs)("article",{children:[(0,e.jsx)("span",{children:n(String(a))}),(0,e.jsx)("strong",{children:t??"\u2014"})]},String(a)))}),(0,e.jsxs)("div",{className:"feedback-grid",children:[(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.trend")}),i.map(a=>(0,e.jsxs)("div",{className:"feedback-bar",children:[(0,e.jsx)("span",{children:a.bucket}),(0,e.jsx)("i",{style:{width:`${a.ratings/N*100}%`}}),(0,e.jsxs)("b",{children:[a.positive,"/",a.ratings]})]},a.bucket))]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.reasons")}),l.map(a=>(0,e.jsxs)("div",{className:"feedback-bar negative",children:[(0,e.jsx)("span",{children:a.reasonKey}),(0,e.jsx)("i",{style:{width:`${a.count/P*100}%`}}),(0,e.jsx)("b",{children:a.count})]},a.reasonKey))]})]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.deliveries")}),(0,e.jsx)("div",{className:"feedback-deliveries",children:h.map(a=>(0,e.jsxs)("div",{children:[(0,e.jsx)("code",{children:a.deliveryId}),(0,e.jsx)("span",{children:a.createdAt}),(0,e.jsxs)("span",{children:[a.botAppId??"\u2014"," \xB7 ",a.model??a.cliId??"\u2014"]}),(0,e.jsx)("b",{children:a.semantic??a.status??"unrated"})]},a.deliveryId))}),u&&(0,e.jsx)("button",{className:"btn-link feedback-more",onClick:()=>{g(u)},children:n("feedback.loadMore")})]})]})}function w(s){return v(s,(0,e.jsx)(E,{}))}export{w as renderFeedbackPage};
1
+ import{s as n}from"./chunk-VMWNR3SV.js";import{a as v}from"./chunk-SYC6D5XU.js";import{a as F,d as f}from"./chunk-5THX4DI2.js";import{c as m}from"./chunk-7SZRL6FY.js";var r=m(F(),1);var e=m(f(),1);function C(){let s=new Date,o=new Date(s.getTime()-30*864e5);return new URLSearchParams({from:o.toISOString(),to:s.toISOString()})}async function c(s,o){let i=await fetch(`${s}?${o}`);if(!i.ok)throw new Error(await i.text());return i.json()}function E(){let[s,o]=(0,r.useState)(),[i,k]=(0,r.useState)([]),[l,y]=(0,r.useState)([]),[h,S]=(0,r.useState)([]),[u,R]=(0,r.useState)(),[b,p]=(0,r.useState)(""),g=async a=>{try{p("");let t=C(),[I,D,T,d]=await Promise.all([c("/api/feedback/analytics/summary",t),c("/api/feedback/analytics/trend",t),c("/api/feedback/analytics/reasons",t),c("/api/feedback/analytics/deliveries",new URLSearchParams([...t,["limit","25"],...a?[["cursor",a]]:[]]))]);o(I),k(D.items),y(T.items),S(x=>a?[...x,...d.items]:d.items),R(d.nextCursor)}catch(t){p(t instanceof Error?t.message:String(t))}};(0,r.useEffect)(()=>{g()},[]);let N=Math.max(1,...i.map(a=>a.ratings)),P=Math.max(1,...l.map(a=>a.count));return(0,e.jsxs)("div",{className:"page feedback-page",children:[(0,e.jsx)("header",{className:"sect-header",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("h1",{children:n("feedback.title")}),(0,e.jsx)("p",{children:n("feedback.subtitle")})]})}),b&&(0,e.jsx)("p",{className:"error-banner",children:b}),(0,e.jsx)("section",{className:"feedback-kpis",children:[["feedback.delivered",s?.delivered],["feedback.rated",s?.ratedDeliveries],["feedback.coverage",s?`${Math.round(s.ratingCoverage*100)}%`:void 0],["feedback.positiveRate",s?`${Math.round(s.positiveRate*100)}%`:void 0],["feedback.deliveryFailures",s?.deliveryFailures],["feedback.outboxFailures",s?.outboxFailures]].map(([a,t])=>(0,e.jsxs)("article",{children:[(0,e.jsx)("span",{children:n(String(a))}),(0,e.jsx)("strong",{children:t??"\u2014"})]},String(a)))}),(0,e.jsxs)("div",{className:"feedback-grid",children:[(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.trend")}),i.map(a=>(0,e.jsxs)("div",{className:"feedback-bar",children:[(0,e.jsx)("span",{children:a.bucket}),(0,e.jsx)("i",{style:{width:`${a.ratings/N*100}%`}}),(0,e.jsxs)("b",{children:[a.positive,"/",a.ratings]})]},a.bucket))]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.reasons")}),l.map(a=>(0,e.jsxs)("div",{className:"feedback-bar negative",children:[(0,e.jsx)("span",{children:a.reasonKey}),(0,e.jsx)("i",{style:{width:`${a.count/P*100}%`}}),(0,e.jsx)("b",{children:a.count})]},a.reasonKey))]})]}),(0,e.jsxs)("section",{className:"panel",children:[(0,e.jsx)("h2",{children:n("feedback.deliveries")}),(0,e.jsx)("div",{className:"feedback-deliveries",children:h.map(a=>(0,e.jsxs)("div",{children:[(0,e.jsx)("code",{children:a.deliveryId}),(0,e.jsx)("span",{children:a.createdAt}),(0,e.jsxs)("span",{children:[a.botAppId??"\u2014"," \xB7 ",a.model??a.cliId??"\u2014"]}),(0,e.jsx)("b",{children:a.semantic??a.status??"unrated"})]},a.deliveryId))}),u&&(0,e.jsx)("button",{className:"btn-link feedback-more",onClick:()=>{g(u)},children:n("feedback.loadMore")})]})]})}function w(s){return v(s,(0,e.jsx)(E,{}))}export{w as renderFeedbackPage};
@@ -1,4 +1,4 @@
1
- import{a as we,b as ke,c as Se,d as Pe}from"./chunk-R3FXBFQH.js";import{a as be,b as ye}from"./chunk-WLIVBPJC.js";import{a as ve}from"./chunk-ZJVTGU5X.js";import{c as he}from"./chunk-2WQDS65D.js";import{c as Q,g as ee,h as de,m as te,n as pe,o as ge,p as fe,q as me}from"./chunk-5CJMHTT4.js";import"./chunk-G5XGBCM6.js";import{a as z,b as K,s as Z,v as ie,y as le}from"./chunk-Q2MT4VWH.js";import{a as ce}from"./chunk-SYC6D5XU.js";import{a as Ue,d as ue}from"./chunk-5THX4DI2.js";import{c as Y}from"./chunk-7SZRL6FY.js";var l=Y(Ue(),1);var je=/^[A-Za-z0-9._-]{1,64}$/,Ce=6,Ie=30;function oe(o,t){return Se(o,t)}function Ne(o,t,r=Ie){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):Ie,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,p=Math.min(c,Math.max(1,s)),h=(p-1)*n,R=Math.min(a,h+n);return{rows:o.slice(h,R),page:p,totalPages:c,from:a===0?0:h+1,to:R,total:a}}async function Ge(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function re(o){return je.test(o)&&o!=="."&&o!==".."}function ne(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return re(t)?t:"profile"}async function X(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Re(o){let t=await X(),r=await Ge(t,Ce,async s=>{try{let h=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(h.entries)?h.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let p of s.memberBots??[]){if(!p?.inChat||!p?.hasRole||!p?.larkAppId)continue;let h=oe(p.larkAppId,s.chatId);n.has(h)||(n.add(h),a.push({chatId:s.chatId,larkAppId:p.larkAppId}))}let c=await Pe(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function xe(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ge(t,Ce,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,p=c?String(s??"").trim():"",h=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:p,status:p?h??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ae(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Be(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 Te(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 Ee(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Le(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:Z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:Z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:Z("groups.roleProfileBootstrapDone",{name:n})}}function $e(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(p=>({larkAppId:p.larkAppId,botName:p.botName,inChat:c.has(p.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(p=>p.chatId!==t)]}}var e=Y(ue(),1);function Me(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function He(o){let t={};for(let r of ie(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function _e(o){let t=o.chat,r=t.avatar??le(t.chatId),[n,a]=(0,l.useState)(!1);(0,l.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:He(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function ae(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 De(o){let t=Ae(o.bots,o.excludeIds),r=o.tr;return(0,e.jsx)(ye,{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 We(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 Je(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let h of t.memberBots??[])h?.inChat&&a.set(h.larkAppId,r.groupRoleContentByBot.get(oe(h.larkAppId,t.chatId))??null);if(!we(a))return null;let s=ke(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let p=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(p,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function qe(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function ze(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 Ve(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=qe(n),c=ze(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var Oe=(0,l.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(pe,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(_e,{chat:r}),(0,e.jsxs)(ge,{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)(Je,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(Ve,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(fe,{children:[(0,e.jsx)(ee,{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 Ke(o){let{tr:t}=o,[r,n]=(0,l.useState)(!1),[a,c]=(0,l.useState)(null),[s,p]=(0,l.useState)(null),[h,R]=(0,l.useState)(!1),[g,C]=(0,l.useState)(new Set),[I,u]=(0,l.useState)(""),[k,v]=(0,l.useState)([]),[S,x]=(0,l.useState)(""),[L,B]=(0,l.useState)(""),[O,j]=(0,l.useState)(""),[$,J]=(0,l.useState)(!0),[A,T]=(0,l.useState)(""),[D,q]=(0,l.useState)(!1),[F,M]=(0,l.useState)(""),[d,w]=(0,l.useState)("");(0,l.useEffect)(()=>{let f=!0;return fetch("/api/feed-groups").then(async b=>{let P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);f&&(v(Array.isArray(P.groups)?P.groups:[]),x(typeof P.larkAppId=="string"?P.larkAppId:""))}).catch(b=>{f&&T(b instanceof Error?b.message:String(b))}).finally(()=>{f&&J(!1)}),()=>{f=!1}},[]),(0,l.useEffect)(()=>{if(!F)return;let f=!0,b=window.setInterval(()=>{fetch("/api/feed-groups").then(async P=>{let N=await P.json().catch(()=>({}));!P.ok||!N.ok||!f||(v(Array.isArray(N.groups)?N.groups:[]),x(typeof N.larkAppId=="string"?N.larkAppId:""),T(""),M(""),w(""))}).catch(()=>{})},1e3);return()=>{f=!1,window.clearInterval(b)}},[F]);async function U(){let f=S?`?larkAppId=${encodeURIComponent(S)}`:"",b=await fetch(`/api/feed-groups/auth-url${f}`),P=await b.json().catch(()=>({}));if(!b.ok||!P.authUrl){c({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:P.error??`HTTP ${b.status}`});return}M(String(P.authUrl)),w("")}async function H(f){q(!0);try{let b=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:f.trim()})}),P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);let N=await fetch("/api/feed-groups"),i=await N.json().catch(()=>({}));if(!N.ok||!i.ok)throw new Error(i.message??i.error??`HTTP ${N.status}`);v(Array.isArray(i.groups)?i.groups:[]),x(typeof i.larkAppId=="string"?i.larkAppId:""),T(""),M(""),w("")}catch(b){c({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:b instanceof Error?b.message:String(b)})}finally{q(!1)}}async function _(f){f.preventDefault();let b=new FormData(f.currentTarget),P=String(b.get("name")??"").trim(),N=String(b.get("bindWorkingDir")??"").trim(),i=String(b.get("roleProfileId")??"").trim(),m=[...g];if(m.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let y=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:P||void 0,larkAppIds:m,bindWorkingDir:N||void 0,roleProfileId:i||void 0,feedGroupId:L||void 0,newFeedGroupName:O||void 0,feedGroupAppId:L||O?S:void 0})}),G=await y.json().catch(()=>({ok:!1,error:`HTTP ${y.status}`}));G.ok&&G.chatId?(p(G),o.onCreated(G,m,P)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:G.error??`HTTP ${y.status}`}),n(!1))}catch(y){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:y}),n(!1)}}if(s){let f=String(s.chatId),b=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(f)}`,P=s.invalidBotIds??[],N=s.invalidUserIds??[],i=Array.isArray(s.oncallBindings)?s.oncallBindings:[],m=i.filter(E=>E?.ok).length,y=i.filter(E=>!E?.ok),G=Le(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:f})," ",(0,e.jsx)("button",{type:"button","data-copy":f,onClick:()=>{ve(f,t("sessions.copy")).then(E=>{E&&(R(!0),o.setTimer(()=>R(!1),800))})},children:t(h?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),s.feedGroupId?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u52A0\u5165\u98DE\u4E66\u6807\u7B7E",s.feedGroupName?`\u300C${String(s.feedGroupName)}\u300D`:"","\u3002"]}):null,s.feedGroupError?(0,e.jsxs)("p",{className:"hint-warn",children:["\u7FA4\u804A\u5DF2\u521B\u5EFA\uFF0C\u4F46\u6807\u7B7E\u8BBE\u7F6E\u5931\u8D25\uFF1A",String(s.feedGroupError)]}):null,(0,e.jsx)(Ze,{resp:s}),i.length>0?y.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",m,"/",i.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",m,"/",i.length,"\u3002",y.map((E,W)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(E?.larkAppId??"?")}),": ",String(E?.error??"unknown")]},`${E?.larkAppId??"?"}-${W}`))]}):null,G?(0,e.jsx)("p",{className:G.kind==="ok"?"hint-ok":"hint-warn",children:G.text}):null,P.length||N.length?(0,e.jsxs)("ul",{children:[P.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:P.join(", ")})]}):null,N.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:N.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:b,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:f=>{_(f)},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)(De,{bots:o.bots,tr:t,selected:g,onToggle:(f,b)=>C(P=>{let N=new Set(P);return b?N.add(f):N.delete(f),N})})})]}),(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:I}),(0,e.jsx)(me,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:I||t("groups.roleProfileNone"),value:I,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(f=>({value:f.profileId,label:f.profileId}))],onChange:u}),(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)(be,{groups:k,selectedId:L,newName:O,disabled:$||!!A,onChange:(f,b)=>{B(f),j(b)}}),(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:D,onClick:()=>{U()},children:D?"\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&&k.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),F?(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(F,"_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:d,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:f=>w(f.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{M(""),w("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!d.trim()||D,onClick:()=>{H(d)},children:D?"\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)(ae,{...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 Ze(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,p=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,p?(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",p,"\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 Xe(o){let{chat:t,tr:r}=o,[n,a]=(0,l.useState)(!1),[c,s]=(0,l.useState)(null),[p,h]=(0,l.useState)(null),[R,g]=(0,l.useState)(new Set),C=(0,l.useMemo)(()=>new Set((t.memberBots??[]).filter(u=>u.inChat).map(u=>u.larkAppId)),[t]);async function I(u){u.preventDefault();let k=[...R];if(k.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),h(null);return}a(!0),s(null),h(null);try{let S=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:k})})).json();if(S.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(S.result){let x=Ee(S.result);try{await o.onReloadGroups({force:!0}),h({result:x})}catch(L){h({result:x,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${L}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(S)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:u=>{I(u)},children:[(0,e.jsx)(De,{bots:o.bots,excludeIds:C,tr:r,selected:R,onToggle:(u,k)=>g(v=>{let S=new Set(v);return k?S.add(u):S.delete(u),S})}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(ae,{...c}):null,p?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(We,{summary:p.result}),p.refreshError?(0,e.jsx)(ae,{title:"\u5237\u65B0\u5931\u8D25",reason:p.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 Ye(o){let{tr:t}=o,[r,n]=(0,l.useState)([]),[a,c]=(0,l.useState)([]),[s,p]=(0,l.useState)(!0),[h,R]=(0,l.useState)(null),g=(0,l.useMemo)(()=>[...a].sort((d,w)=>d.profileId.localeCompare(w.profileId)),[a]),C=g.length>0,I=r.filter(d=>d.status==="empty").length,u=r.filter(d=>d.status==="error").length,k=!s&&!h&&r.length>0&&u===0,[v,S]=(0,l.useState)("new"),[x,L]=(0,l.useState)(o.suggestedProfileId),[B,O]=(0,l.useState)(""),[j,$]=(0,l.useState)(!1),[J,A]=(0,l.useState)(null),T=v==="overwrite"?B:x.trim(),D=t(v==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=h||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?I?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:I}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,l.useEffect)(()=>{let d=!0;return p(!0),R(null),A(null),(async()=>{try{let[w,U]=await Promise.all([xe(o.chat),X().catch(()=>[])]);if(!d)return;let H=[...U].sort((_,f)=>_.profileId.localeCompare(f.profileId));n(w),c(U),O(_=>H.some(f=>f.profileId===_)?_:H[0]?.profileId??"")}catch(w){if(!d)return;n([]),c([]),O(""),R(w instanceof Error?w.message:String(w))}finally{d&&p(!1)}})(),()=>{d=!1}},[o.chat]);async function F(d){if(d.preventDefault(),!!k){if(!re(T)){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(T)}/${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:T,count:U}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(w){A({text:String(w),className:"error"}),$(!1)}}}function M(d){d==="overwrite"&&!C||(S(d),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:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:d=>{F(d)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Q,{label:t("common.loading")})}):h?(0,e.jsx)("div",{className:"g-save-profile-empty",children:h}):r.length?r.map(d=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${d.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:d.botName??d.larkAppId}),(0,e.jsx)("code",{children:d.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${d.status==="error"?"error":"ok"}`,children:t(d.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},d.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:()=>M("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:!C,onClick:()=>M("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:x,maxLength:64,autoComplete:"off",onChange:d=>{L(d.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")}),C?(0,e.jsx)("div",{className:"g-save-profile-picker",children:g.map(d=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${d.profileId===B?"selected":""}`,"data-profile-id":d.profileId,"aria-pressed":d.profileId===B,onClick:()=>{O(d.profileId),S("overwrite"),A(null)},children:[(0,e.jsx)("span",{children:d.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:d.entryCount??0})})]},d.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:T||"-"}),(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 ${k?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${J?.className??""}`,"data-save-profile-status":!0,children:J?.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:!k||j||v==="overwrite"&&!B,children:j?t("groups.saveProfileSaving"):D})]})]})]})}function Qe(o){let{member:t,tr:r}=o,n=(0,l.useRef)(null),[a,c]=(0,l.useState)(!!t.oncallChat),[s,p]=(0,l.useState)(t.oncallChat?.workingDir??""),[h,R]=(0,l.useState)(!1),[g,C]=(0,l.useState)(null);async function I(){C(null);let u=s.trim();if(a&&!u){C({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}R(!0);try{let k=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,v=a?await fetch(k,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(k,{method:"DELETE"}),S=await v.json().catch(()=>({}));if(v.ok&&S.ok){C({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${S.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else C({text:`\u2717 ${S.error??v.status}`,className:"hint-warn-inline"})}catch(k){C({text:`\u2717 ${k?.message??k}`,className:"hint-warn-inline"})}finally{R(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>p(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:h,onClick:()=>{I()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${g?.className??""}`,"data-status":!0,children:g?.text??""})]})]})}function et(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(g=>g.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,l.useState)(()=>new Set);function p(g,C){s(I=>{let u=new Set(I);return C?u.add(g):u.delete(g),u})}async function h(){let g=[...c];if(g.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${g.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 I=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:g})})).json(),u=(I.result??[]).map(k=>{if(!k.ok)return`${k.larkAppId}: \u5931\u8D25 (${k.error??"unknown"})`;let v=k.closedSessions??[],S=v.filter(B=>!B.ok).length,x=v.length-S,L=v.length===0?"":S===0?`\uFF08\u5173\u95ED ${x} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${x} \u4E2A\uFF0C${S} \u4E2A\u5931\u8D25\uFF09`;return`${k.larkAppId}: OK${L}`}).join(`
1
+ import{a as we,b as ke,c as Se,d as Pe}from"./chunk-R3FXBFQH.js";import{a as be,b as ye}from"./chunk-WLIVBPJC.js";import{a as ve}from"./chunk-ZJVTGU5X.js";import{c as he}from"./chunk-IKN6WURK.js";import{c as Q,g as ee,h as de,m as te,n as pe,o as ge,p as fe,q as me}from"./chunk-5CJMHTT4.js";import"./chunk-G5XGBCM6.js";import{a as z,b as K,s as Z,v as ie,y as le}from"./chunk-VMWNR3SV.js";import{a as ce}from"./chunk-SYC6D5XU.js";import{a as Ue,d as ue}from"./chunk-5THX4DI2.js";import{c as Y}from"./chunk-7SZRL6FY.js";var l=Y(Ue(),1);var je=/^[A-Za-z0-9._-]{1,64}$/,Ce=6,Ie=30;function oe(o,t){return Se(o,t)}function Ne(o,t,r=Ie){let n=Number.isFinite(r)?Math.max(1,Math.floor(r)):Ie,a=o.length,c=Math.max(1,Math.ceil(a/n)),s=Number.isFinite(t)?Math.floor(t):1,p=Math.min(c,Math.max(1,s)),h=(p-1)*n,R=Math.min(a,h+n);return{rows:o.slice(h,R),page:p,totalPages:c,from:a===0?0:h+1,to:R,total:a}}async function Ge(o,t,r){if(o.length===0)return[];let n=new Array(o.length),a=0,c=Math.min(Math.max(1,t),o.length);return await Promise.all(Array.from({length:c},async()=>{for(;a<o.length;){let s=a++;n[s]=await r(o[s])}})),n}function re(o){return je.test(o)&&o!=="."&&o!==".."}function ne(o){let t=String(o??"").trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);return re(t)?t:"profile"}async function X(){let t=await(await fetch("/api/role-profiles")).json().catch(()=>({}));return Array.isArray(t.profiles)?t.profiles:[]}async function Re(o){let t=await X(),r=await Ge(t,Ce,async s=>{try{let h=await(await fetch(`/api/role-profiles/${encodeURIComponent(s.profileId)}`)).json().catch(()=>({}));return[s.profileId,Array.isArray(h.entries)?h.entries:[]]}catch{return[s.profileId,[]]}}),n=new Set,a=[];for(let s of o.chats??[])for(let p of s.memberBots??[]){if(!p?.inChat||!p?.hasRole||!p?.larkAppId)continue;let h=oe(p.larkAppId,s.chatId);n.has(h)||(n.add(h),a.push({chatId:s.chatId,larkAppId:p.larkAppId}))}let c=await Pe(a);return{profiles:t,entriesById:new Map(r),groupRoleContentByBot:c,loaded:!0}}async function xe(o){let t=(o.memberBots??[]).filter(r=>r?.inChat&&r?.larkAppId);return Ge(t,Ce,async r=>{try{let a=await(await fetch(`/api/roles/${encodeURIComponent(r.larkAppId)}/${encodeURIComponent(o.chatId)}`)).json().catch(()=>({})),c=a?.hasEffectiveRole??a?.hasRole,s="effectiveContent"in a?a.effectiveContent:a.content,p=c?String(s??"").trim():"",h=a?.effectiveSource==="chat"||a?.effectiveSource==="team"?a.effectiveSource:null;return{larkAppId:r.larkAppId,botName:r.botName,content:p,status:p?h??"chat":"empty"}}catch{return{larkAppId:r.larkAppId,botName:r.botName,content:"",status:"error"}}})}function Ae(o,t){return o.filter(r=>!t||!t.has(r.larkAppId))}function Be(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 Te(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 Ee(o){let t=Array.isArray(o)?o:[],r=t.filter(n=>!!n?.ok).length;return{rows:t,okCount:r,failed:t.length-r}}function Le(o,t,r){let n=String(o??"").trim();if(!n)return null;if(r)return{kind:"warn",text:Z("groups.roleProfileBootstrapFailed",{name:n,reason:String(r)})};let a=typeof t=="string"&&t.trim()?t.trim():"";return a?{kind:"ok",text:Z("groups.roleProfileBootstrapSent",{name:n,messageId:a})}:{kind:"ok",text:Z("groups.roleProfileBootstrapDone",{name:n})}}function $e(o,t,r,n,a){let c=new Set(n);a&&c.add(a);let s={chatId:t,name:r,ownerId:a??null,memberBots:o.bots.map(p=>({larkAppId:p.larkAppId,botName:p.botName,inChat:c.has(p.larkAppId),oncallChat:null}))};return{bots:o.bots,chats:[s,...o.chats.filter(p=>p.chatId!==t)]}}var e=Y(ue(),1);function Me(){return{profiles:[],entriesById:new Map,groupRoleContentByBot:new Map,loaded:!1}}function He(o){let t={};for(let r of ie(o).split(";")){if(!r)continue;let n=r.indexOf(":");n<=0||(t[r.slice(0,n)]=r.slice(n+1))}return t}function _e(o){let t=o.chat,r=t.avatar??le(t.chatId),[n,a]=(0,l.useState)(!1);(0,l.useEffect)(()=>{a(!1)},[r]);let c=t.name??t.chatId,s=!!r&&!n;return(0,e.jsx)("span",{className:`orb-avatar orb-square orb-avatar-sm${s?" orb-has-img":""}`,style:He(c),"aria-hidden":"true",children:s?(0,e.jsx)("img",{className:"orb-img",src:r,alt:"",decoding:"async",referrerPolicy:"no-referrer",onError:()=>a(!0)}):null})}function ae(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 De(o){let t=Ae(o.bots,o.excludeIds),r=o.tr;return(0,e.jsx)(ye,{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 We(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 Je(o){let{chat:t,context:r,tr:n}=o;if(!r.profiles.length||!r.loaded)return null;let a=new Map;for(let h of t.memberBots??[])h?.inChat&&a.set(h.larkAppId,r.groupRoleContentByBot.get(oe(h.larkAppId,t.chatId))??null);if(!we(a))return null;let s=ke(t.memberBots??[],r.profiles,r.entriesById,a)[0];if(!s)return(0,e.jsx)("div",{className:"g-profile-status muted",children:n("groups.profileStatusUnmatched")});let p=s.kind==="full"?"groups.profileStatusFullChat":"groups.profileStatusPartial";return(0,e.jsx)("div",{className:`g-profile-status ${s.kind}`,children:n(p,{name:s.profileId,matched:s.matched,total:s.total,chat:s.chatMatched})})}function qe(o){return o?o.error?"error":o.inChat?"in":"out":"unknown"}function ze(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 Ve(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=qe(n),c=ze(a,o.tr),s=r.botName??r.larkAppId;return(0,e.jsxs)("span",{className:`groups-bot-pill groups-bot-${a}`,title:`${s}: ${c}${n?.error?` (${String(n.error)})`:""}`,children:[(0,e.jsx)("i",{"aria-hidden":"true"}),(0,e.jsx)("span",{className:"groups-bot-name",children:s}),(0,e.jsx)("span",{className:"groups-bot-state",children:c})]},r.larkAppId)})})}var Oe=(0,l.memo)(function(t){let{chat:r,tr:n}=t,c=(r.memberBots??[]).filter(s=>s.inChat).length;return(0,e.jsxs)(pe,{kind:"group",className:"groups-list-row","data-chat":r.chatId,children:[(0,e.jsx)(_e,{chat:r}),(0,e.jsxs)(ge,{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)(Je,{chat:r,context:t.roleContext,tr:n})]}),(0,e.jsx)("span",{className:"groups-row-count",children:n("groups.memberSummary",{count:c,total:t.bots.length})}),(0,e.jsxs)("div",{className:"groups-row-lower",children:[(0,e.jsx)(Ve,{chat:r,bots:t.bots,tr:n}),(0,e.jsxs)(fe,{children:[(0,e.jsx)(ee,{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 Ke(o){let{tr:t}=o,[r,n]=(0,l.useState)(!1),[a,c]=(0,l.useState)(null),[s,p]=(0,l.useState)(null),[h,R]=(0,l.useState)(!1),[g,C]=(0,l.useState)(new Set),[I,u]=(0,l.useState)(""),[k,v]=(0,l.useState)([]),[S,x]=(0,l.useState)(""),[L,B]=(0,l.useState)(""),[O,j]=(0,l.useState)(""),[$,J]=(0,l.useState)(!0),[A,T]=(0,l.useState)(""),[D,q]=(0,l.useState)(!1),[F,M]=(0,l.useState)(""),[d,w]=(0,l.useState)("");(0,l.useEffect)(()=>{let f=!0;return fetch("/api/feed-groups").then(async b=>{let P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);f&&(v(Array.isArray(P.groups)?P.groups:[]),x(typeof P.larkAppId=="string"?P.larkAppId:""))}).catch(b=>{f&&T(b instanceof Error?b.message:String(b))}).finally(()=>{f&&J(!1)}),()=>{f=!1}},[]),(0,l.useEffect)(()=>{if(!F)return;let f=!0,b=window.setInterval(()=>{fetch("/api/feed-groups").then(async P=>{let N=await P.json().catch(()=>({}));!P.ok||!N.ok||!f||(v(Array.isArray(N.groups)?N.groups:[]),x(typeof N.larkAppId=="string"?N.larkAppId:""),T(""),M(""),w(""))}).catch(()=>{})},1e3);return()=>{f=!1,window.clearInterval(b)}},[F]);async function U(){let f=S?`?larkAppId=${encodeURIComponent(S)}`:"",b=await fetch(`/api/feed-groups/auth-url${f}`),P=await b.json().catch(()=>({}));if(!b.ok||!P.authUrl){c({title:"\u65E0\u6CD5\u53D1\u8D77\u6807\u7B7E\u6388\u6743",reason:P.error??`HTTP ${b.status}`});return}M(String(P.authUrl)),w("")}async function H(f){q(!0);try{let b=await fetch("/api/feed-groups/oauth-callback",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({callbackUrl:f.trim()})}),P=await b.json().catch(()=>({}));if(!b.ok||!P.ok)throw new Error(P.message??P.error??`HTTP ${b.status}`);let N=await fetch("/api/feed-groups"),i=await N.json().catch(()=>({}));if(!N.ok||!i.ok)throw new Error(i.message??i.error??`HTTP ${N.status}`);v(Array.isArray(i.groups)?i.groups:[]),x(typeof i.larkAppId=="string"?i.larkAppId:""),T(""),M(""),w("")}catch(b){c({title:"\u6807\u7B7E\u6388\u6743\u5931\u8D25",reason:b instanceof Error?b.message:String(b)})}finally{q(!1)}}async function _(f){f.preventDefault();let b=new FormData(f.currentTarget),P=String(b.get("name")??"").trim(),N=String(b.get("bindWorkingDir")??"").trim(),i=String(b.get("roleProfileId")??"").trim(),m=[...g];if(m.length===0){c({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u521B\u5EFA\u7FA4\u804A\u3002"});return}n(!0),c(null);try{let y=await fetch("/api/groups/create",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:P||void 0,larkAppIds:m,bindWorkingDir:N||void 0,roleProfileId:i||void 0,feedGroupId:L||void 0,newFeedGroupName:O||void 0,feedGroupAppId:L||O?S:void 0})}),G=await y.json().catch(()=>({ok:!1,error:`HTTP ${y.status}`}));G.ok&&G.chatId?(p(G),o.onCreated(G,m,P)):(c({title:"\u521B\u5EFA\u5931\u8D25",reason:G.error??`HTTP ${y.status}`}),n(!1))}catch(y){c({title:"\u7F51\u7EDC\u9519\u8BEF",reason:y}),n(!1)}}if(s){let f=String(s.chatId),b=typeof s.shareLink=="string"&&s.shareLink?s.shareLink:`https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(f)}`,P=s.invalidBotIds??[],N=s.invalidUserIds??[],i=Array.isArray(s.oncallBindings)?s.oncallBindings:[],m=i.filter(E=>E?.ok).length,y=i.filter(E=>!E?.ok),G=Le(typeof s.roleProfileId=="string"?s.roleProfileId:"",s.roleProfileBootstrapMessageId,s.roleProfileBootstrapError);return(0,e.jsxs)("article",{className:"g-create-dialog g-create-success",children:[(0,e.jsx)("header",{children:(0,e.jsx)("h3",{children:t("groups.successTitle")})}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"chatId:"})," ",(0,e.jsx)("code",{children:f})," ",(0,e.jsx)("button",{type:"button","data-copy":f,onClick:()=>{ve(f,t("sessions.copy")).then(E=>{E&&(R(!0),o.setTimer(()=>R(!1),800))})},children:t(h?"sessions.copied":"sessions.copy")})]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("b",{children:"\u521B\u5EFA\u8005:"})," ",(0,e.jsx)("code",{children:String(s.creator??"?")})]}),s.feedGroupId?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u52A0\u5165\u98DE\u4E66\u6807\u7B7E",s.feedGroupName?`\u300C${String(s.feedGroupName)}\u300D`:"","\u3002"]}):null,s.feedGroupError?(0,e.jsxs)("p",{className:"hint-warn",children:["\u7FA4\u804A\u5DF2\u521B\u5EFA\uFF0C\u4F46\u6807\u7B7E\u8BBE\u7F6E\u5931\u8D25\uFF1A",String(s.feedGroupError)]}):null,(0,e.jsx)(Ze,{resp:s}),i.length>0?y.length===0?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u7ED1\u5B9A\u76EE\u5F55\uFF1A",(0,e.jsx)("code",{children:String(s.bindResolvedPath??"")}),"\uFF08",m,"/",i.length," bots\uFF09"]}):(0,e.jsxs)("p",{className:"hint-warn",children:["\u76EE\u5F55\u7ED1\u5B9A\u90E8\u5206\u5931\u8D25\uFF1A\u6210\u529F ",m,"/",i.length,"\u3002",y.map((E,W)=>(0,e.jsxs)("span",{children:[(0,e.jsx)("br",{}),(0,e.jsx)("code",{children:String(E?.larkAppId??"?")}),": ",String(E?.error??"unknown")]},`${E?.larkAppId??"?"}-${W}`))]}):null,G?(0,e.jsx)("p",{className:G.kind==="ok"?"hint-ok":"hint-warn",children:G.text}):null,P.length||N.length?(0,e.jsxs)("ul",{children:[P.length?(0,e.jsxs)("li",{children:["\u65E0\u6548 bot id: ",(0,e.jsx)("code",{children:P.join(", ")})]}):null,N.length?(0,e.jsxs)("li",{children:["\u65E0\u6548\u7528\u6237 open_id: ",(0,e.jsx)("code",{children:N.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:b,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:f=>{_(f)},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)(De,{bots:o.bots,tr:t,selected:g,onToggle:(f,b)=>C(P=>{let N=new Set(P);return b?N.add(f):N.delete(f),N})})})]}),(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:I}),(0,e.jsx)(me,{className:"g-profile-menu",ariaLabel:t("groups.roleProfile"),label:I||t("groups.roleProfileNone"),value:I,options:[{value:"",label:t("groups.roleProfileNone")},...o.roleProfiles.map(f=>({value:f.profileId,label:f.profileId}))],onChange:u}),(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)(be,{groups:k,selectedId:L,newName:O,disabled:$||!!A,onChange:(f,b)=>{B(f),j(b)}}),(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:D,onClick:()=>{U()},children:D?"\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&&k.length===0?(0,e.jsx)("small",{children:"\u5F53\u524D\u6CA1\u6709\u6807\u7B7E\uFF0C\u53EF\u76F4\u63A5\u521B\u5EFA\u4E00\u4E2A\u3002"}):null]})]}),F?(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(F,"_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:d,placeholder:"http://127.0.0.1:9768/callback?code=\u2026&state=\u2026",onChange:f=>w(f.currentTarget.value)})]}),(0,e.jsxs)("div",{className:"actions",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{M(""),w("")},children:"\u53D6\u6D88"}),(0,e.jsx)("button",{type:"button",className:"primary",disabled:!d.trim()||D,onClick:()=>{H(d)},children:D?"\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)(ae,{...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 Ze(o){let t=o.resp,r=t.autoInvitedOpenId,n=!!t.autoInviteRejected,a=t.ownerTransferredTo,c=t.transferError,s=t.notifyMessageId,p=t.notifyError;return r?(0,e.jsxs)("p",{className:"hint-ok",children:["\u5DF2\u81EA\u52A8\u9080\u8BF7\u4F60\uFF08",(0,e.jsx)("code",{children:r}),"\uFF09\u4F5C\u4E3A\u6210\u5458\u3002",a?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsx)("small",{children:"\u7FA4\u4E3B\u5DF2\u4ECE\u673A\u5668\u4EBA\u8F6C\u8BA9\u7ED9\u4F60\u3002"})]}):null,c?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{className:"hint-warn-inline",children:["\u26A0 \u81EA\u52A8\u8F6C\u8BA9\u7FA4\u4E3B\u5931\u8D25\uFF08",c,"\uFF09\uFF0C\u4F60\u73B0\u5728\u662F\u6210\u5458\u4F46\u7FA4\u4E3B\u4ECD\u662F\u673A\u5668\u4EBA\u3002"]})]}):null,s?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("br",{}),(0,e.jsxs)("small",{children:["\u673A\u5668\u4EBA\u5DF2\u5728\u7FA4\u91CC @ \u4E86\u4F60\uFF08\u6D88\u606F id ",(0,e.jsx)("code",{children:s}),"\uFF09\uFF0C\u770B\u98DE\u4E66\u901A\u77E5\u5C31\u80FD\u8FDB\u7FA4\u3002"]})]}):null,p?(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",p,"\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 Xe(o){let{chat:t,tr:r}=o,[n,a]=(0,l.useState)(!1),[c,s]=(0,l.useState)(null),[p,h]=(0,l.useState)(null),[R,g]=(0,l.useState)(new Set),C=(0,l.useMemo)(()=>new Set((t.memberBots??[]).filter(u=>u.inChat).map(u=>u.larkAppId)),[t]);async function I(u){u.preventDefault();let k=[...R];if(k.length===0){s({title:"\u8BF7\u9009\u62E9 bot",reason:"\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A bot \u540E\u518D\u6DFB\u52A0\u3002"}),h(null);return}a(!0),s(null),h(null);try{let S=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/add-bots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:k})})).json();if(S.error==="no_proxy_bot")s({title:"\u65E0\u6CD5\u6DFB\u52A0 bot",reason:"\u5F53\u524D\u7FA4\u91CC\u6CA1\u6709\u53EF\u4EE3\u7406\u64CD\u4F5C\u7684 bot\u3002\u8BF7\u5148\u5728\u98DE\u4E66\u91CC\u624B\u52A8\u62C9\u5165\u4E00\u4E2A bot\uFF0C\u7136\u540E\u91CD\u8BD5\u3002"});else if(S.result){let x=Ee(S.result);try{await o.onReloadGroups({force:!0}),h({result:x})}catch(L){h({result:x,refreshError:`\u6DFB\u52A0\u7ED3\u679C\u5DF2\u8FD4\u56DE\uFF0C\u4F46\u5237\u65B0\u7FA4\u7EC4\u5217\u8868\u5931\u8D25\uFF1A${L}`})}}else s({title:"\u54CD\u5E94\u5F02\u5E38",reason:JSON.stringify(S)})}catch(v){s({title:"\u7F51\u7EDC\u9519\u8BEF",reason:v})}finally{a(!1)}}return(0,e.jsxs)("article",{className:"g-add-bots-dialog",children:[(0,e.jsx)("header",{children:(0,e.jsxs)("h3",{children:[r("groups.addBots")," \xB7 ",t.name??t.chatId]})}),(0,e.jsx)("p",{children:r("groups.createHelp")}),(0,e.jsxs)("form",{id:"g-addform",onSubmit:u=>{I(u)},children:[(0,e.jsx)(De,{bots:o.bots,excludeIds:C,tr:r,selected:R,onToggle:(u,k)=>g(v=>{let S=new Set(v);return k?S.add(u):S.delete(u),S})}),(0,e.jsxs)("div",{"data-add-status":!0,"aria-live":"polite",children:[c?(0,e.jsx)(ae,{...c}):null,p?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(We,{summary:p.result}),p.refreshError?(0,e.jsx)(ae,{title:"\u5237\u65B0\u5931\u8D25",reason:p.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 Ye(o){let{tr:t}=o,[r,n]=(0,l.useState)([]),[a,c]=(0,l.useState)([]),[s,p]=(0,l.useState)(!0),[h,R]=(0,l.useState)(null),g=(0,l.useMemo)(()=>[...a].sort((d,w)=>d.profileId.localeCompare(w.profileId)),[a]),C=g.length>0,I=r.filter(d=>d.status==="empty").length,u=r.filter(d=>d.status==="error").length,k=!s&&!h&&r.length>0&&u===0,[v,S]=(0,l.useState)("new"),[x,L]=(0,l.useState)(o.suggestedProfileId),[B,O]=(0,l.useState)(""),[j,$]=(0,l.useState)(!1),[J,A]=(0,l.useState)(null),T=v==="overwrite"?B:x.trim(),D=t(v==="overwrite"?"groups.saveProfileOverwriteSubmit":"groups.saveProfileSubmit"),q=h||(s?t("groups.saveProfilePreparing"):u?t("groups.saveProfileFailedLoadSummary",{count:u}):r.length?I?t("groups.saveProfileEntrySummaryWithEmpty",{count:r.length,emptyCount:I}):t("groups.saveProfileEntrySummary",{count:r.length}):t("groups.saveProfileNoRoles"));(0,l.useEffect)(()=>{let d=!0;return p(!0),R(null),A(null),(async()=>{try{let[w,U]=await Promise.all([xe(o.chat),X().catch(()=>[])]);if(!d)return;let H=[...U].sort((_,f)=>_.profileId.localeCompare(f.profileId));n(w),c(U),O(_=>H.some(f=>f.profileId===_)?_:H[0]?.profileId??"")}catch(w){if(!d)return;n([]),c([]),O(""),R(w instanceof Error?w.message:String(w))}finally{d&&p(!1)}})(),()=>{d=!1}},[o.chat]);async function F(d){if(d.preventDefault(),!!k){if(!re(T)){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(T)}/${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:T,count:U}),className:"ok"}),await o.onRefreshRoleContext(),o.setTimer(o.onClose,700)}catch(w){A({text:String(w),className:"error"}),$(!1)}}}function M(d){d==="overwrite"&&!C||(S(d),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:s?"-":r.length})})]}),(0,e.jsxs)("form",{id:"g-save-profile-form",onSubmit:d=>{F(d)},children:[(0,e.jsxs)("section",{className:"g-save-profile-panel",children:[(0,e.jsxs)("div",{className:"g-save-profile-section-head",children:[(0,e.jsx)("span",{children:t("groups.saveProfileScope")}),(0,e.jsx)("small",{children:t("groups.saveProfileScopeHelp")})]}),(0,e.jsxs)("div",{className:"g-save-profile-stats",children:[(0,e.jsxs)("span",{children:[t("groups.saveProfileBotCount")," ",(0,e.jsx)("strong",{children:s?"-":r.length})]}),u?(0,e.jsxs)("span",{className:"warn",children:[t("groups.saveProfileLoadFailed")," ",(0,e.jsx)("strong",{children:u})]}):null]}),(0,e.jsx)("div",{className:"g-save-profile-entry-list",children:s?(0,e.jsx)("div",{className:"g-save-profile-loading",children:(0,e.jsx)(Q,{label:t("common.loading")})}):h?(0,e.jsx)("div",{className:"g-save-profile-empty",children:h}):r.length?r.map(d=>(0,e.jsxs)("div",{className:`g-save-profile-entry ${d.status==="error"?"error":""}`,children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("strong",{children:d.botName??d.larkAppId}),(0,e.jsx)("code",{children:d.larkAppId})]}),(0,e.jsx)("span",{className:`g-save-profile-entry-status ${d.status==="error"?"error":"ok"}`,children:t(d.status==="error"?"groups.saveProfileStatus.error":"groups.saveProfileStatus.entry")})]},d.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:()=>M("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:!C,onClick:()=>M("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:x,maxLength:64,autoComplete:"off",onChange:d=>{L(d.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")}),C?(0,e.jsx)("div",{className:"g-save-profile-picker",children:g.map(d=>(0,e.jsxs)("button",{type:"button",className:`g-save-profile-pick ${d.profileId===B?"selected":""}`,"data-profile-id":d.profileId,"aria-pressed":d.profileId===B,onClick:()=>{O(d.profileId),S("overwrite"),A(null)},children:[(0,e.jsx)("span",{children:d.profileId}),(0,e.jsx)("small",{children:t("groups.saveProfileExistingMeta",{count:d.entryCount??0})})]},d.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:T||"-"}),(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 ${k?"":"warn"}`,children:q}),(0,e.jsx)("div",{className:`g-save-profile-status ${J?.className??""}`,"data-save-profile-status":!0,children:J?.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:!k||j||v==="overwrite"&&!B,children:j?t("groups.saveProfileSaving"):D})]})]})]})}function Qe(o){let{member:t,tr:r}=o,n=(0,l.useRef)(null),[a,c]=(0,l.useState)(!!t.oncallChat),[s,p]=(0,l.useState)(t.oncallChat?.workingDir??""),[h,R]=(0,l.useState)(!1),[g,C]=(0,l.useState)(null);async function I(){C(null);let u=s.trim();if(a&&!u){C({text:r("groups.needWorkingDir"),className:"hint-warn-inline"});return}R(!0);try{let k=`/api/groups/${encodeURIComponent(o.chat.chatId)}/oncall/${encodeURIComponent(t.larkAppId)}`,v=a?await fetch(k,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({workingDir:u})}):await fetch(k,{method:"DELETE"}),S=await v.json().catch(()=>({}));if(v.ok&&S.ok){C({text:a?`\u2713 \u5DF2\u7ED1\u5B9A \u2192 ${S.resolvedPath??u}`:"\u2713 \u5DF2\u89E3\u7ED1",className:"hint-ok"});try{await o.onSaved()}catch{}}else C({text:`\u2717 ${S.error??v.status}`,className:"hint-warn-inline"})}catch(k){C({text:`\u2717 ${k?.message??k}`,className:"hint-warn-inline"})}finally{R(!1)}}return(0,e.jsxs)("div",{className:"oncall-row","data-bot":t.larkAppId,children:[(0,e.jsxs)("label",{className:"checkbox-row",children:[(0,e.jsx)("input",{type:"checkbox","data-action":"toggle",checked:a,onChange:u=>{c(u.currentTarget.checked),u.currentTarget.checked&&window.setTimeout(()=>n.current?.focus(),0)}}),(0,e.jsx)("strong",{children:t.botName??t.larkAppId}),(0,e.jsxs)("small",{children:["(",t.larkAppId,")"]})]}),(0,e.jsxs)("div",{className:"oncall-row-body",children:[(0,e.jsx)("input",{ref:n,type:"text","data-input":"workingDir",placeholder:"e.g. /root/iserver/botmux",value:s,disabled:!a,onChange:u=>p(u.currentTarget.value)}),(0,e.jsx)("button",{type:"button","data-action":"save",disabled:h,onClick:()=>{I()},children:r("groups.save")}),(0,e.jsx)("span",{className:`oncall-status ${g?.className??""}`,"data-status":!0,children:g?.text??""})]})]})}function et(o){let{chat:t,tr:r}=o,n=(t.memberBots??[]).filter(g=>g.inChat),a=typeof t.ownerId=="string"?t.ownerId:"",[c,s]=(0,l.useState)(()=>new Set);function p(g,C){s(I=>{let u=new Set(I);return C?u.add(g):u.delete(g),u})}async function h(){let g=[...c];if(g.length===0){alert("\u81F3\u5C11\u9009\u4E00\u4E2A\u673A\u5668\u4EBA");return}if(confirm(`\u786E\u5B9A\u8BA9 ${g.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 I=await(await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/leave`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppIds:g})})).json(),u=(I.result??[]).map(k=>{if(!k.ok)return`${k.larkAppId}: \u5931\u8D25 (${k.error??"unknown"})`;let v=k.closedSessions??[],S=v.filter(B=>!B.ok).length,x=v.length-S,L=v.length===0?"":S===0?`\uFF08\u5173\u95ED ${x} \u4E2A\u4F1A\u8BDD\uFF09`:`\uFF08\u5173\u95ED ${x} \u4E2A\uFF0C${S} \u4E2A\u5931\u8D25\uFF09`;return`${k.larkAppId}: OK${L}`}).join(`
2
2
  `);alert(u||`Unexpected: ${JSON.stringify(I)}`),await o.onReloadGroups({force:!0})}catch(C){alert("Network error: "+C)}finally{o.onClose()}}async function R(){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 g=[...n].sort((I,u)=>(u.larkAppId===a?1:0)-(I.larkAppId===a?1:0)),C=[];for(let I of g)try{let u=await fetch(`/api/groups/${encodeURIComponent(t.chatId)}/disband`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({larkAppId:I.larkAppId})}),k=await u.json();if(k.ok){let v=k.closedSessions??[],S=v.filter(B=>!B.ok).length,x=v.length-S,L=v.length===0?"":S===0?`
3
3
  \u5173\u95ED\u4E86 ${x} \u4E2A\u4F1A\u8BDD\u3002`:`
4
4
  \u5173\u95ED\u4E86 ${x} \u4E2A\u4F1A\u8BDD\uFF0C${S} \u4E2A\u4F1A\u8BDD\u5173\u95ED\u5931\u8D25\u3002`;alert(`\u5DF2\u89E3\u6563\uFF08\u7531 ${I.botName??I.larkAppId} \u6267\u884C\uFF09${L}`),await o.onReloadGroups({force:!0}),o.onClose();return}C.push(`${I.botName??I.larkAppId}: ${k.error??u.status}`)}catch(u){C.push(`${I.botName??I.larkAppId}: ${u}`)}alert(`\u6240\u6709\u5728\u7FA4\u673A\u5668\u4EBA\u5747\u65E0\u6CD5\u89E3\u6563\uFF1A