botmux 3.12.0 → 3.12.1

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 (229) hide show
  1. package/dist/.runtime-build-id +1 -1
  2. package/dist/adapters/backend/riff-backend.d.ts +18 -0
  3. package/dist/adapters/backend/riff-backend.d.ts.map +1 -1
  4. package/dist/adapters/backend/riff-backend.js +143 -0
  5. package/dist/adapters/backend/riff-backend.js.map +1 -1
  6. package/dist/adapters/cli/kimi.d.ts.map +1 -1
  7. package/dist/adapters/cli/kimi.js +22 -8
  8. package/dist/adapters/cli/kimi.js.map +1 -1
  9. package/dist/adapters/cli/pi.d.ts.map +1 -1
  10. package/dist/adapters/cli/pi.js +3 -1
  11. package/dist/adapters/cli/pi.js.map +1 -1
  12. package/dist/bot-registry.d.ts.map +1 -1
  13. package/dist/bot-registry.js +4 -1
  14. package/dist/bot-registry.js.map +1 -1
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +65 -27
  17. package/dist/cli.js.map +1 -1
  18. package/dist/core/command-handler.d.ts.map +1 -1
  19. package/dist/core/command-handler.js +16 -2
  20. package/dist/core/command-handler.js.map +1 -1
  21. package/dist/core/dashboard-ipc-server.js +1 -1
  22. package/dist/core/dashboard-ipc-server.js.map +1 -1
  23. package/dist/core/dashboard-rows.d.ts +17 -1
  24. package/dist/core/dashboard-rows.d.ts.map +1 -1
  25. package/dist/core/dashboard-rows.js +13 -1
  26. package/dist/core/dashboard-rows.js.map +1 -1
  27. package/dist/core/maintenance.d.ts.map +1 -1
  28. package/dist/core/maintenance.js +5 -0
  29. package/dist/core/maintenance.js.map +1 -1
  30. package/dist/core/skills/cli-admin-command.d.ts.map +1 -1
  31. package/dist/core/skills/cli-admin-command.js +142 -3
  32. package/dist/core/skills/cli-admin-command.js.map +1 -1
  33. package/dist/core/skills/frontmatter.d.ts.map +1 -1
  34. package/dist/core/skills/frontmatter.js +44 -7
  35. package/dist/core/skills/frontmatter.js.map +1 -1
  36. package/dist/core/skills/im-command.d.ts +6 -0
  37. package/dist/core/skills/im-command.d.ts.map +1 -1
  38. package/dist/core/skills/im-command.js +34 -7
  39. package/dist/core/skills/im-command.js.map +1 -1
  40. package/dist/core/skills/install-command.d.ts +4 -0
  41. package/dist/core/skills/install-command.d.ts.map +1 -0
  42. package/dist/core/skills/install-command.js +89 -0
  43. package/dist/core/skills/install-command.js.map +1 -0
  44. package/dist/core/skills/package.d.ts.map +1 -1
  45. package/dist/core/skills/package.js +10 -3
  46. package/dist/core/skills/package.js.map +1 -1
  47. package/dist/core/skills/policy.d.ts +5 -1
  48. package/dist/core/skills/policy.d.ts.map +1 -1
  49. package/dist/core/skills/policy.js +66 -3
  50. package/dist/core/skills/policy.js.map +1 -1
  51. package/dist/core/skills/references.d.ts +9 -1
  52. package/dist/core/skills/references.d.ts.map +1 -1
  53. package/dist/core/skills/references.js +35 -2
  54. package/dist/core/skills/references.js.map +1 -1
  55. package/dist/core/skills/registry-paths.d.ts +1 -0
  56. package/dist/core/skills/registry-paths.d.ts.map +1 -1
  57. package/dist/core/skills/registry-paths.js +3 -0
  58. package/dist/core/skills/registry-paths.js.map +1 -1
  59. package/dist/core/skills/session-resolver.d.ts +2 -1
  60. package/dist/core/skills/session-resolver.d.ts.map +1 -1
  61. package/dist/core/skills/session-resolver.js +1 -0
  62. package/dist/core/skills/session-resolver.js.map +1 -1
  63. package/dist/core/skills/session-runtime.d.ts.map +1 -1
  64. package/dist/core/skills/session-runtime.js +2 -0
  65. package/dist/core/skills/session-runtime.js.map +1 -1
  66. package/dist/core/skills/sources.d.ts +23 -0
  67. package/dist/core/skills/sources.d.ts.map +1 -1
  68. package/dist/core/skills/sources.js +128 -12
  69. package/dist/core/skills/sources.js.map +1 -1
  70. package/dist/core/skills/types.d.ts +22 -1
  71. package/dist/core/skills/types.d.ts.map +1 -1
  72. package/dist/core/types.d.ts +2 -0
  73. package/dist/core/types.d.ts.map +1 -1
  74. package/dist/core/types.js.map +1 -1
  75. package/dist/core/worker-pool.d.ts.map +1 -1
  76. package/dist/core/worker-pool.js +52 -1
  77. package/dist/core/worker-pool.js.map +1 -1
  78. package/dist/dashboard/bot-onboarding.d.ts.map +1 -1
  79. package/dist/dashboard/bot-onboarding.js +2 -114
  80. package/dist/dashboard/bot-onboarding.js.map +1 -1
  81. package/dist/dashboard/connector-api.d.ts.map +1 -1
  82. package/dist/dashboard/connector-api.js +66 -6
  83. package/dist/dashboard/connector-api.js.map +1 -1
  84. package/dist/dashboard/public-redact.d.ts.map +1 -1
  85. package/dist/dashboard/public-redact.js +3 -0
  86. package/dist/dashboard/public-redact.js.map +1 -1
  87. package/dist/dashboard/skill-install-request.js +10 -11
  88. package/dist/dashboard/skill-install-request.js.map +1 -1
  89. package/dist/dashboard/skill-pack-response.d.ts +15 -0
  90. package/dist/dashboard/skill-pack-response.d.ts.map +1 -0
  91. package/dist/dashboard/skill-pack-response.js +32 -0
  92. package/dist/dashboard/skill-pack-response.js.map +1 -0
  93. package/dist/dashboard/web/connectors-page.d.ts +69 -0
  94. package/dist/dashboard/web/connectors-page.d.ts.map +1 -1
  95. package/dist/dashboard/web/connectors-page.js +47 -7
  96. package/dist/dashboard/web/connectors-page.js.map +1 -1
  97. package/dist/dashboard/web/i18n.d.ts.map +1 -1
  98. package/dist/dashboard/web/i18n.js +301 -26
  99. package/dist/dashboard/web/i18n.js.map +1 -1
  100. package/dist/dashboard/web/preferences.d.ts +4 -2
  101. package/dist/dashboard/web/preferences.d.ts.map +1 -1
  102. package/dist/dashboard/web/preferences.js +14 -6
  103. package/dist/dashboard/web/preferences.js.map +1 -1
  104. package/dist/dashboard/web/sessions-page.d.ts.map +1 -1
  105. package/dist/dashboard/web/sessions-page.js +99 -3
  106. package/dist/dashboard/web/sessions-page.js.map +1 -1
  107. package/dist/dashboard/web/sessions.d.ts +3 -1
  108. package/dist/dashboard/web/sessions.d.ts.map +1 -1
  109. package/dist/dashboard/web/sessions.js +13 -6
  110. package/dist/dashboard/web/sessions.js.map +1 -1
  111. package/dist/dashboard/web/skills/bot-assignments-tab.d.ts +27 -0
  112. package/dist/dashboard/web/skills/bot-assignments-tab.d.ts.map +1 -0
  113. package/dist/dashboard/web/skills/bot-assignments-tab.js +257 -0
  114. package/dist/dashboard/web/skills/bot-assignments-tab.js.map +1 -0
  115. package/dist/dashboard/web/skills/delivery-settings-tab.d.ts +25 -0
  116. package/dist/dashboard/web/skills/delivery-settings-tab.d.ts.map +1 -0
  117. package/dist/dashboard/web/skills/delivery-settings-tab.js +20 -0
  118. package/dist/dashboard/web/skills/delivery-settings-tab.js.map +1 -0
  119. package/dist/dashboard/web/skills/shared.d.ts +86 -0
  120. package/dist/dashboard/web/skills/shared.d.ts.map +1 -0
  121. package/dist/dashboard/web/skills/shared.js +178 -0
  122. package/dist/dashboard/web/skills/shared.js.map +1 -0
  123. package/dist/dashboard/web/skills/skill-library-tab.d.ts +75 -0
  124. package/dist/dashboard/web/skills/skill-library-tab.d.ts.map +1 -0
  125. package/dist/dashboard/web/skills/skill-library-tab.js +108 -0
  126. package/dist/dashboard/web/skills/skill-library-tab.js.map +1 -0
  127. package/dist/dashboard/web/skills/skill-packs-tab.d.ts +21 -0
  128. package/dist/dashboard/web/skills/skill-packs-tab.d.ts.map +1 -0
  129. package/dist/dashboard/web/skills/skill-packs-tab.js +185 -0
  130. package/dist/dashboard/web/skills/skill-packs-tab.js.map +1 -0
  131. package/dist/dashboard/web/skills/types.d.ts +95 -0
  132. package/dist/dashboard/web/skills/types.d.ts.map +1 -0
  133. package/dist/dashboard/web/skills/types.js +2 -0
  134. package/dist/dashboard/web/skills/types.js.map +1 -0
  135. package/dist/dashboard/web/skills/use-skills-data.d.ts +31 -0
  136. package/dist/dashboard/web/skills/use-skills-data.d.ts.map +1 -0
  137. package/dist/dashboard/web/skills/use-skills-data.js +86 -0
  138. package/dist/dashboard/web/skills/use-skills-data.js.map +1 -0
  139. package/dist/dashboard/web/skills-page.d.ts +34 -31
  140. package/dist/dashboard/web/skills-page.d.ts.map +1 -1
  141. package/dist/dashboard/web/skills-page.js +321 -176
  142. package/dist/dashboard/web/skills-page.js.map +1 -1
  143. package/dist/dashboard/webhook-routes.d.ts +18 -0
  144. package/dist/dashboard/webhook-routes.d.ts.map +1 -1
  145. package/dist/dashboard/webhook-routes.js +35 -1
  146. package/dist/dashboard/webhook-routes.js.map +1 -1
  147. package/dist/dashboard-web/app.js +1 -1
  148. package/dist/dashboard-web/chunks/{bot-defaults-page-USC6EZXP.js → bot-defaults-page-HL655CNR.js} +1 -1
  149. package/dist/dashboard-web/chunks/{chunk-KOPISPHN.js → chunk-5PAYQ3KT.js} +1 -1
  150. package/dist/dashboard-web/chunks/{chunk-RXRJB5SO.js → chunk-5ZL7NLR5.js} +1 -1
  151. package/dist/dashboard-web/chunks/{chunk-A7VC4BXR.js → chunk-BFUTTYVK.js} +1 -1
  152. package/dist/dashboard-web/chunks/chunk-ELL53D62.js +55 -0
  153. package/dist/dashboard-web/chunks/connectors-page-3QQACF23.js +1 -0
  154. package/dist/dashboard-web/chunks/{groups-page-C6NSDTIN.js → groups-page-SDZMJ7UV.js} +1 -1
  155. package/dist/dashboard-web/chunks/{insights-page-UTOVYLLY.js → insights-page-ZZ3JEJ6L.js} +1 -1
  156. package/dist/dashboard-web/chunks/{monitor-room-UKTJYTA2.js → monitor-room-ROJ5GZ4N.js} +1 -1
  157. package/dist/dashboard-web/chunks/{monitoring-page-Q3CEZIVX.js → monitoring-page-IATV7KJF.js} +1 -1
  158. package/dist/dashboard-web/chunks/{office-page-GYCZOOVJ.js → office-page-TYO5OIIT.js} +1 -1
  159. package/dist/dashboard-web/chunks/{overview-page-W2VBJ6OH.js → overview-page-VJUULZF2.js} +1 -1
  160. package/dist/dashboard-web/chunks/{roles-page-U4SHER4K.js → roles-page-7RJJKZGK.js} +1 -1
  161. package/dist/dashboard-web/chunks/{schedules-page-TNPW3N3Q.js → schedules-page-JTEJ5IXW.js} +1 -1
  162. package/dist/dashboard-web/chunks/sessions-page-KD7HDT3U.js +8 -0
  163. package/dist/dashboard-web/chunks/{settings-page-VKW5ZK5K.js → settings-page-7CTTFBRS.js} +1 -1
  164. package/dist/dashboard-web/chunks/skills-page-57NZECJ3.js +4 -0
  165. package/dist/dashboard-web/chunks/{team-federation-page-OMFGGBT2.js → team-federation-page-6YYIMJG3.js} +1 -1
  166. package/dist/dashboard-web/chunks/{v3-page-PLXWK4KO.js → v3-page-ZGKBSBK3.js} +1 -1
  167. package/dist/dashboard-web/chunks/{whiteboards-page-NJQOEO2P.js → whiteboards-page-AACJF6DB.js} +1 -1
  168. package/dist/dashboard-web/style.css +1623 -160
  169. package/dist/dashboard.js +200 -16
  170. package/dist/dashboard.js.map +1 -1
  171. package/dist/i18n/en.d.ts.map +1 -1
  172. package/dist/i18n/en.js +2 -0
  173. package/dist/i18n/en.js.map +1 -1
  174. package/dist/i18n/zh.d.ts.map +1 -1
  175. package/dist/i18n/zh.js +2 -0
  176. package/dist/i18n/zh.js.map +1 -1
  177. package/dist/index-daemon.js +6 -1
  178. package/dist/index-daemon.js.map +1 -1
  179. package/dist/services/connector-store.d.ts +14 -1
  180. package/dist/services/connector-store.d.ts.map +1 -1
  181. package/dist/services/connector-store.js.map +1 -1
  182. package/dist/services/connector-topic-template.d.ts +7 -0
  183. package/dist/services/connector-topic-template.d.ts.map +1 -0
  184. package/dist/services/connector-topic-template.js +210 -0
  185. package/dist/services/connector-topic-template.js.map +1 -0
  186. package/dist/services/project-scanner.d.ts +33 -0
  187. package/dist/services/project-scanner.d.ts.map +1 -1
  188. package/dist/services/project-scanner.js +40 -1
  189. package/dist/services/project-scanner.js.map +1 -1
  190. package/dist/services/skill-pack-store.d.ts +50 -0
  191. package/dist/services/skill-pack-store.d.ts.map +1 -0
  192. package/dist/services/skill-pack-store.js +270 -0
  193. package/dist/services/skill-pack-store.js.map +1 -0
  194. package/dist/services/skill-registry-store.d.ts +8 -0
  195. package/dist/services/skill-registry-store.d.ts.map +1 -1
  196. package/dist/services/skill-registry-store.js +100 -68
  197. package/dist/services/skill-registry-store.js.map +1 -1
  198. package/dist/services/todo-state.d.ts +74 -0
  199. package/dist/services/todo-state.d.ts.map +1 -0
  200. package/dist/services/todo-state.js +351 -0
  201. package/dist/services/todo-state.js.map +1 -0
  202. package/dist/setup/agent-preset.d.ts.map +1 -1
  203. package/dist/setup/agent-preset.js +2 -0
  204. package/dist/setup/agent-preset.js.map +1 -1
  205. package/dist/setup/owner-identity.d.ts +47 -0
  206. package/dist/setup/owner-identity.d.ts.map +1 -0
  207. package/dist/setup/owner-identity.js +196 -0
  208. package/dist/setup/owner-identity.js.map +1 -0
  209. package/dist/setup/register-app.d.ts +4 -3
  210. package/dist/setup/register-app.d.ts.map +1 -1
  211. package/dist/setup/register-app.js.map +1 -1
  212. package/dist/setup/setup-args.d.ts +1 -1
  213. package/dist/setup/setup-args.d.ts.map +1 -1
  214. package/dist/setup/setup-args.js +7 -3
  215. package/dist/setup/setup-args.js.map +1 -1
  216. package/dist/types.d.ts +11 -0
  217. package/dist/types.d.ts.map +1 -1
  218. package/dist/utils/child-env.d.ts +25 -0
  219. package/dist/utils/child-env.d.ts.map +1 -1
  220. package/dist/utils/child-env.js +47 -0
  221. package/dist/utils/child-env.js.map +1 -1
  222. package/dist/worker.js +55 -16
  223. package/dist/worker.js.map +1 -1
  224. package/dist/workflows/definition.d.ts +44 -44
  225. package/package.json +1 -1
  226. package/dist/dashboard-web/chunks/chunk-M6BHWQFO.js +0 -51
  227. package/dist/dashboard-web/chunks/connectors-page-4Z76HWRH.js +0 -1
  228. package/dist/dashboard-web/chunks/sessions-page-YWWDDV57.js +0 -6
  229. package/dist/dashboard-web/chunks/skills-page-ZCEDFGZZ.js +0 -4
@@ -1,2 +1,2 @@
1
- import{b as xe,c as A}from"./chunk-KOPISPHN.js";import{a as H,c as ce,j as Me,l as T,q as O}from"./chunk-5CJMHTT4.js";import{a as ve,t as be}from"./chunk-M6BHWQFO.js";import{a as Oe}from"./chunk-SYC6D5XU.js";import{a as Te,d as de}from"./chunk-5THX4DI2.js";import{c as Y}from"./chunk-7SZRL6FY.js";var p=Y(Te(),1);var N=Y(Te(),1);var a=Y(de(),1),Le=["transcript_received","chat_received","participant_joined","participant_left","magic_share_started","magic_share_ended"],he=8e3,Ue=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,Ee="\u6301\u7EED\u6574\u7406\u4F1A\u8BAE\u7EAA\u8981\uFF0C\u91CD\u70B9\u8BB0\u5F55\u5DF2\u786E\u8BA4\u7684\u51B3\u7B56\u3001\u5F85\u529E\u4E8B\u9879\uFF08\u542B\u8D1F\u8D23\u4EBA\u548C\u622A\u6B62\u65F6\u95F4\uFF09\u4EE5\u53CA\u672A\u89E3\u51B3\u98CE\u9669\uFF1B\u5B57\u5E55\u4FEE\u8BA2\u65F6\u66F4\u65B0\u5DF2\u6709\u6761\u76EE\uFF0C\u4E0D\u91CD\u590D\u8BB0\u5F55\u540C\u4E00\u4E8B\u9879\u3002\u4EC5\u5728\u51FA\u73B0\u65B0\u7684\u5173\u952E\u51B3\u7B56\u3001\u660E\u786E\u5F85\u529E\u6216\u98CE\u9669\uFF0C\u6216\u88AB\u7528\u6237\u70B9\u540D\u65F6\uFF0C\u624D\u5728\u76D1\u542C\u7FA4\u8F93\u51FA\u7B80\u6D01\u589E\u91CF\uFF1B\u65E0\u5B9E\u8D28\u589E\u91CF\u65F6\u4FDD\u6301\u9759\u9ED8\uFF0C\u4E0D\u53D1\u9001\u786E\u8BA4\u6216\u5FC3\u8DF3\u3002\u9700\u8981\u5411\u4F1A\u8BAE\u5185\u53D1\u9001\u6587\u5B57\u6216\u8BED\u97F3\u65F6\uFF0C\u5FC5\u987B\u901A\u8FC7 botmux \u53D7\u7BA1 request-output/action gate \u63D0\u4EA4\uFF0C\u4E0D\u5F97\u7ED5\u8FC7\u6743\u9650\u3001\u6240\u6709\u6743\u4E0E\u5BA1\u6838\u7B56\u7565\u3002",Ie=0;function Ne(){return Ie+=1,`p${Ie}`}function we(e){return{...e,listenerPlacement:e.listenerPlacement??"auto",uiKey:Ne(),isNew:!1}}function He(e){let{uiKey:t,isNew:i,...r}=e;return r}function j(e){return(0,a.jsxs)("span",{className:"vc-profile-field-head",children:[e.title,(0,a.jsx)(Me,{label:e.title,children:(0,a.jsx)("span",{className:"vc-profile-help",children:e.help})})]})}function Re(e){let t=A(),i=(0,N.useRef)(null);return(0,N.useEffect)(()=>{let r=i.current;if(!(!r||r.open))try{r.showModal()}catch{r.setAttribute("open","")}},[]),(0,a.jsxs)("dialog",{ref:i,className:["vc-profile-dialog",e.className].filter(Boolean).join(" "),onClose:e.onClose,onCancel:r=>{r.preventDefault(),e.onClose()},children:[(0,a.jsxs)("header",{className:"vc-profile-dialog-head",children:[(0,a.jsxs)("div",{children:[e.eyebrow?(0,a.jsx)("span",{children:e.eyebrow}):null,(0,a.jsx)("h3",{children:e.title})]}),(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-close","aria-label":t("settings.vcProfiles.close"),onClick:e.onClose})]}),(0,a.jsx)("div",{className:"vc-profile-dialog-body",children:e.children})]})}function Be(e){let t=A();return e.enabled?e.canWrite?(0,a.jsx)(_e,{canWrite:e.canWrite,listenerBotAppId:e.listenerBotAppId,listenerBotOptions:e.listenerBotOptions}):(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.needAuth")}):null}function _e(e){let t=A(),i=xe(),r=(0,N.useRef)(!1),g=e.listenerBotOptions,[f,m]=(0,N.useState)(e.listenerBotAppId??g[0]?.larkAppId??""),[u,y]=(0,N.useState)(null),[S,h]=(0,N.useState)(null),[b,C]=(0,N.useState)(!1),[$,V]=(0,N.useState)(!1),[R,W]=(0,N.useState)(!1),[c,v]=(0,N.useState)(!1),[k,x]=(0,N.useState)({}),[ee,z]=(0,N.useState)(!1),[ie,B]=(0,N.useState)(null),[ae,Z]=(0,N.useState)(null);(0,N.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let G=(0,N.useRef)(0);(0,N.useEffect)(()=>{e.listenerBotAppId&&e.listenerBotAppId!==f&&!$&&m(e.listenerBotAppId)},[$,e.listenerBotAppId,f]);let K=(0,N.useCallback)(async l=>{let s=++G.current;if(y(null),V(!1),v(!1),x({}),B(null),Z(null),!l){h(null);return}C(!0);try{let o=await fetch(`/api/vc-meeting/consumer-profiles?listenerBotAppId=${encodeURIComponent(l)}`),d=await o.json().catch(()=>({}));if(!r.current||G.current!==s)return;!o.ok||d?.ok!==!0?(y(null),h(typeof d?.error=="string"?d.error:`HTTP ${o.status}`)):(y({forBot:l,revision:d.revision,catalogState:d.catalogState==="explicit_empty"||d.catalogState==="legacy_or_partial"||d.catalogState==="profiles"?d.catalogState:"uninitialized",defaultMode:d.defaultMode==="agents"?"agents":"listenOnly",defaultConsumerIds:Array.isArray(d.defaultConsumerIds)?d.defaultConsumerIds:[],profiles:(Array.isArray(d.profiles)?d.profiles:[]).map(we),agentOptions:Array.isArray(d.agentOptions)?d.agentOptions:[],templateCatalog:d.templateCatalog?.schemaVersion===1&&Array.isArray(d.templateCatalog.templates)?d.templateCatalog:{schemaVersion:1,templates:[]},...d.migrationOffer==="enable_seeded_minutes_default"?{migrationOffer:d.migrationOffer}:{}}),h(null),V(!1))}catch(o){if(!r.current||G.current!==s)return;y(null),h(o instanceof Error?o.message:String(o))}finally{r.current&&G.current===s&&C(!1)}},[]);(0,N.useEffect)(()=>{K(f)},[K,f]);let I=(0,N.useCallback)(l=>{y(s=>s&&l(s)),V(!0),z(!1)},[]),se=(0,N.useCallback)((l,s)=>{I(o=>({...o,profiles:o.profiles.map(d=>d.uiKey===l?{...d,...s}:d)}))},[I]),ue=(0,N.useCallback)(async()=>{if(!u||R||b||!u.forBot||u.forBot!==f)return;let l={};if(u.profiles.forEach((s,o)=>{Ue.test(s.id)||(l[`profiles[${o}].id`]=t("settings.vcProfiles.idInvalid")),(s.instructions??"").length>he&&(l[`profiles[${o}].instructions`]=t("settings.vcProfiles.instructionsTooLong"))}),Object.keys(l).length>0){x(l);return}W(!0),v(!1),x({});try{let s=await fetch("/api/vc-meeting/consumer-profiles",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({listenerBotAppId:u.forBot,expectedRevision:u.revision,defaultMode:u.defaultMode,defaultConsumerIds:u.defaultConsumerIds,profiles:u.profiles.map(He)})}),o=await s.json().catch(()=>({}));if(!r.current||u.forBot!==f)return;if(s.status===409){v(!0);return}if(s.status===422){let d={};for(let P of Array.isArray(o?.fieldErrors)?o.fieldErrors:[])typeof P?.path=="string"&&typeof P?.message=="string"&&(d[P.path]=P.message);x(Object.keys(d).length>0?d:{profiles:t("settings.vcProfiles.validationFailed")});return}if(!s.ok||o?.ok!==!0){x({profiles:typeof o?.error=="string"?o.error:`HTTP ${s.status}`});return}y({forBot:u.forBot,revision:o.revision,catalogState:o.catalogState==="explicit_empty"||o.catalogState==="legacy_or_partial"||o.catalogState==="profiles"?o.catalogState:"uninitialized",defaultMode:o.defaultMode==="agents"?"agents":"listenOnly",defaultConsumerIds:Array.isArray(o.defaultConsumerIds)?o.defaultConsumerIds:[],profiles:(Array.isArray(o.profiles)?o.profiles:[]).map(we),agentOptions:Array.isArray(o.agentOptions)?o.agentOptions:[],templateCatalog:o.templateCatalog?.schemaVersion===1&&Array.isArray(o.templateCatalog.templates)?o.templateCatalog:{schemaVersion:1,templates:[]},...o.migrationOffer==="enable_seeded_minutes_default"?{migrationOffer:o.migrationOffer}:{}}),V(!1),z(!0)}catch(s){if(!r.current)return;x({profiles:s instanceof Error?s.message:String(s)})}finally{r.current&&W(!1)}},[u,R,f,t]),Q=(0,N.useMemo)(()=>g.map(l=>({value:l.larkAppId,label:l.botName||l.larkAppId})),[g]),ge=Q.find(l=>l.value===f)?.label??f,L=(0,N.useMemo)(()=>u?u.agentOptions.map(l=>{let s=[l.online?void 0:t("settings.vcProfiles.agentOffline"),l.workingDirReady?void 0:t("settings.vcProfiles.agentNoWorkingDir"),l.reliableTurnTerminal?void 0:t("settings.vcProfiles.agentNoReliableTerminal"),l.managedSideEffectIsolation?void 0:t("settings.vcProfiles.agentNoManagedIsolation")].filter(Boolean);return{value:l.appId,label:(0,a.jsxs)("span",{className:"vc-agent-option",children:[(0,a.jsxs)("span",{className:"vc-agent-option-name",children:[l.label,l.cliId?(0,a.jsx)("em",{className:"vc-agent-option-cli",children:l.cliId}):null]}),s.length>0?(0,a.jsxs)("span",{className:"vc-agent-option-warn",children:["\u26A0 ",s.join(" \xB7 ")]}):null]})}}):[],[u,t]),fe=l=>{let s=u?.agentOptions.find(d=>d.appId===l);return s?!s.online||!s.workingDirReady||!s.reliableTurnTerminal||!s.managedSideEffectIsolation?`\u26A0 ${s.label}`:s.label:l},D=(0,N.useCallback)(l=>{let o=["observe_only","meeting_text","meeting_voice","meeting_text_voice"].map(d=>({value:d,label:t(`settings.vcProfiles.preset.${d}`)}));return(!l.isNew||l.permissionPreset==="custom")&&o.push({value:"custom",label:t("settings.vcProfiles.preset.custom")}),o},[t]),le=(0,N.useCallback)(()=>{let l=Ne();I(s=>({...s,profiles:[...s.profiles,{uiKey:l,isNew:!0,id:"",agentAppId:s.agentOptions[0]?.appId??"",responseMode:"silent",listenerPlacement:"auto",permissionPreset:"observe_only"}]})),B(l)},[I]),oe=(0,N.useCallback)(l=>{let s=Ne();I(o=>{let d=new Set(o.profiles.map(w=>w.id)),P=l.suggestedProfileId;for(let w=2;d.has(P);w+=1)P=`${l.suggestedProfileId.slice(0,60)}-${w}`;return{...o,profiles:[...o.profiles,{uiKey:s,isNew:!0,id:P,label:l.profileLabel[i],agentAppId:o.agentOptions[0]?.appId??"",instructions:l.instructions[i],activityTypes:[...l.activityTypes],responseMode:l.responseMode,listenerPlacement:l.listenerPlacement,permissionPreset:l.permissionPreset}]}}),Z(null),B(s)},[i,I]),J=(0,N.useCallback)(l=>{I(s=>({...s,profiles:s.profiles.filter(o=>o.uiKey!==l),defaultConsumerIds:s.defaultConsumerIds.filter(o=>s.profiles.some(d=>d.uiKey!==l&&d.id===o))})),B(s=>s===l?null:s)},[I]);if(g.length===0)return null;let F=l=>k[l],q=!e.canWrite||R||b,pe=u?.agentOptions.some(l=>l.workingDirReady&&l.reliableTurnTerminal&&l.managedSideEffectIsolation)??!1,te=u?.profiles.findIndex(l=>l.uiKey===ie)??-1,U=te>=0?u?.profiles[te]??null:null,ne=u?.templateCatalog.templates.find(l=>l.templateId===ae)??null,Ae=(l,s)=>{l.id&&I(o=>{let d=s?[...new Set([...o.defaultConsumerIds,l.id])]:o.defaultConsumerIds.filter(P=>P!==l.id);return{...o,defaultMode:d.length>0?"agents":"listenOnly",defaultConsumerIds:d}})};return(0,a.jsxs)("div",{className:"vc-profiles-section",children:[(0,a.jsxs)("div",{className:"settings-field-row",children:[(0,a.jsx)(T,{help:t("settings.vcProfiles.help"),children:t("settings.vcProfiles.title")}),e.listenerBotAppId===null&&Q.length>1?(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.listenerOwner")}),(0,a.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.vcProfiles.listenerOwner"),disabled:b||R,value:f,label:H(Q,f),options:Q,onChange:l=>{l!==f&&($&&!window.confirm(t("settings.vcProfiles.discardConfirm"))||m(l))}})]}):(0,a.jsx)("span",{className:"vc-profile-config-target",children:t("settings.vcProfiles.configuringBot",{bot:ge})})]}),(0,a.jsx)("p",{className:"hint vc-profiles-freeze",children:t("settings.vcProfiles.freezeNotice")}),b?(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.loading")}):null,S?(0,a.jsx)("p",{className:"hint-warn",children:S==="bot_not_in_config"?t("settings.vcProfiles.botNotInConfig"):`${t("settings.vcProfiles.loadFailed")}: ${S}`}):null,c?(0,a.jsxs)("p",{className:"hint-warn",children:[t("settings.vcProfiles.conflict")," ",(0,a.jsx)("button",{type:"button",className:"vc-profiles-link",onClick:()=>{K(f)},children:t("settings.vcProfiles.reload")})]}):null,F("profiles")?(0,a.jsx)("p",{className:"hint-warn",children:F("profiles")}):null,u?(0,a.jsxs)(a.Fragment,{children:[u.migrationOffer==="enable_seeded_minutes_default"?(0,a.jsxs)("p",{className:"hint-warn vc-profile-migration-offer",children:[t("settings.vcProfiles.migrationOffer")," ",(0,a.jsx)("button",{type:"button",className:"vc-profiles-link",disabled:q||$,onClick:()=>I(l=>({...l,defaultMode:"agents",defaultConsumerIds:["minutes"],profiles:l.profiles.map(s=>s.id==="minutes"?{...s,instructions:Ee,responseMode:"listener_thread",permissionPreset:"meeting_text_voice"}:s),migrationOffer:void 0})),children:t("settings.vcProfiles.migrationEnable")})]}):null,u.catalogState==="uninitialized"&&u.profiles.length===0&&!pe?(0,a.jsx)("p",{className:"hint-warn",children:t("settings.vcProfiles.noEligibleDefaultAgent")}):null,u.catalogState==="legacy_or_partial"?(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.legacyCatalog")}):null,(0,a.jsxs)("section",{className:"vc-profile-library-section",children:[(0,a.jsxs)("div",{className:"vc-profile-list-heading",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.list.title")}),(0,a.jsx)("p",{children:t("settings.vcProfiles.list.help")})]}),e.canWrite?(0,a.jsx)("button",{type:"button",className:"vc-profiles-link vc-profile-add",disabled:R||b,onClick:le,children:t("settings.vcProfiles.add")}):null]}),u.profiles.length>0?(0,a.jsx)("div",{className:"vc-profile-card-grid",children:u.profiles.map(l=>{let s=u.agentOptions.find(d=>d.appId===l.agentAppId),o=u.defaultMode==="agents"&&u.defaultConsumerIds.includes(l.id);return(0,a.jsxs)("article",{className:"vc-profile-summary-card",role:"button",tabIndex:0,onClick:()=>B(l.uiKey),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),B(l.uiKey))},children:[(0,a.jsxs)("div",{className:"vc-profile-summary-top",children:[(0,a.jsx)("span",{className:"vc-profile-summary-icon","aria-hidden":"true",children:(l.label||l.id||"?").slice(0,1)}),(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:l.label||l.id||t("settings.vcProfiles.untitled")}),(0,a.jsx)("code",{children:l.id||t("settings.vcProfiles.newBadge")})]}),l.isNew?(0,a.jsx)("em",{children:t("settings.vcProfiles.newBadge")}):null]}),(0,a.jsx)("p",{children:(l.instructions??"").trim()||t("settings.vcProfiles.noInstructions")}),(0,a.jsxs)("div",{className:"vc-profile-summary-meta",children:[(0,a.jsx)("span",{children:s?.label??l.agentAppId}),(0,a.jsx)("span",{children:l.responseMode==="listener_thread"?t("settings.vcProfiles.responseListener"):t("settings.vcProfiles.responseSilent")})]}),(0,a.jsxs)("label",{className:"vc-profile-default-toggle",onClick:d=>d.stopPropagation(),children:[(0,a.jsx)("input",{type:"checkbox",checked:o,disabled:q||!l.id,onChange:d=>Ae(l,d.currentTarget.checked)}),(0,a.jsx)("span",{children:t("settings.vcProfiles.setDefault")})]})]},l.uiKey)})}):(0,a.jsx)("p",{className:"vc-profile-empty",children:t("settings.vcProfiles.list.empty")})]}),u.templateCatalog.templates.length>0?(0,a.jsxs)("section",{className:"vc-profile-template-catalog",children:[(0,a.jsxs)("div",{className:"vc-profile-template-heading",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.templates.title")}),(0,a.jsx)("p",{children:t("settings.vcProfiles.templates.help")})]}),(0,a.jsx)("span",{children:t("settings.vcProfiles.templates.builtinBadge")})]}),(0,a.jsx)("div",{className:"vc-profile-template-grid",children:u.templateCatalog.templates.map(l=>(0,a.jsxs)("button",{type:"button",className:"vc-profile-template-card",onClick:()=>Z(l.templateId),children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"\u2726"}),(0,a.jsx)("strong",{children:l.title[i]}),(0,a.jsx)("p",{children:l.description[i]}),(0,a.jsxs)("em",{children:[t("settings.vcProfiles.viewDetails")," \u2192"]})]},`${l.templateId}@${l.version}`))})]}):null,(0,a.jsxs)("div",{className:"settings-field-row vc-profile-default-mode-row",children:[(0,a.jsx)(T,{help:t("settings.vcProfiles.defaultModeHelp"),children:t("settings.vcProfiles.defaultMode")}),(0,a.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.vcProfiles.defaultMode"),disabled:q,value:u.defaultMode,label:u.defaultMode==="agents"?t("settings.vcProfiles.defaultModeAgents"):t("settings.vcProfiles.defaultModeListenOnly"),options:[{value:"listenOnly",label:t("settings.vcProfiles.defaultModeListenOnly")},{value:"agents",label:t("settings.vcProfiles.defaultModeAgents")}],onChange:l=>I(s=>({...s,defaultMode:l==="agents"?"agents":"listenOnly"}))})]}),F("defaultConsumerIds")?(0,a.jsx)("em",{className:"vc-profile-err",children:F("defaultConsumerIds")}):null,F("defaultMode")?(0,a.jsx)("em",{className:"vc-profile-err",children:F("defaultMode")}):null,e.canWrite?(0,a.jsxs)("div",{className:"vc-profiles-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profiles-save",disabled:!$||R||c,onClick:()=>{ue()},children:t(R?"settings.vcProfiles.saving":"settings.vcProfiles.save")}),ee?(0,a.jsx)("span",{className:"vc-profile-hint",children:t("settings.vcProfiles.saved")}):null,$&&!R?(0,a.jsx)("span",{className:"vc-profile-hint",children:t("settings.vcProfiles.unsaved")}):null]}):null,U?(0,a.jsx)($e,{profile:U,index:te,frozen:q,canWrite:e.canWrite,agentOptions:L,agentLabel:fe(U.agentAppId),presetOptions:D(U),error:F,onClose:()=>B(null),onUpdate:l=>se(U.uiKey,l),onIdChange:l=>{let s=U.id;I(o=>({...o,profiles:o.profiles.map(d=>d.uiKey===U.uiKey?{...d,id:l}:d),defaultConsumerIds:o.defaultConsumerIds.map(d=>d===s&&s?l:d).filter(Boolean)}))},onRemove:()=>J(U.uiKey)}):null,ne?(0,a.jsx)(Ve,{template:ne,locale:i,disabled:q||u.agentOptions.length===0,onClose:()=>Z(null),onUse:()=>oe(ne)}):null]}):null]})}function $e(e){let t=A(),{profile:i,index:r}=e;return(0,a.jsxs)(Re,{className:"vc-profile-editor-dialog",eyebrow:t("settings.vcProfiles.list.title"),title:i.label||i.id||t("settings.vcProfiles.untitled"),onClose:e.onClose,children:[(0,a.jsxs)("div",{className:"vc-profile-grid",children:[(0,a.jsxs)("label",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldId"),help:t("settings.vcProfiles.idHelp")})}),(0,a.jsx)("input",{type:"text",value:i.id,disabled:e.frozen||!i.isNew,placeholder:"minutes",onChange:g=>e.onIdChange(g.currentTarget.value)}),e.error(`profiles[${r}].id`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].id`)}):null]}),(0,a.jsxs)("label",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldLabel"),help:t("settings.vcProfiles.labelHelp")})}),(0,a.jsx)("input",{type:"text",value:i.label??"",disabled:e.frozen,onChange:g=>e.onUpdate({label:g.currentTarget.value||void 0})}),e.error(`profiles[${r}].label`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].label`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldAgent"),help:t("settings.vcProfiles.agentHelp")})}),(0,a.jsx)(O,{className:"vc-profile-agent-menu",ariaLabel:t("settings.vcProfiles.fieldAgent"),disabled:e.frozen,value:i.agentAppId,label:e.agentLabel,options:e.agentOptions,onChange:g=>e.onUpdate({agentAppId:g})}),e.error(`profiles[${r}].agentAppId`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].agentAppId`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldResponseMode"),help:t("settings.vcProfiles.responseModeHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldResponseMode"),disabled:e.frozen,value:i.responseMode,label:i.responseMode==="listener_thread"?t("settings.vcProfiles.responseListener"):t("settings.vcProfiles.responseSilent"),options:[{value:"silent",label:t("settings.vcProfiles.responseSilent")},{value:"listener_thread",label:t("settings.vcProfiles.responseListener")}],onChange:g=>e.onUpdate({responseMode:g})}),e.error(`profiles[${r}].responseMode`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].responseMode`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldListenerPlacement"),help:t("settings.vcProfiles.listenerPlacementHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldListenerPlacement"),disabled:e.frozen||i.responseMode==="silent",value:i.listenerPlacement??"auto",label:t(`settings.vcProfiles.listenerPlacement.${i.listenerPlacement??"auto"}`),options:["auto","chat","topic"].map(g=>({value:g,label:t(`settings.vcProfiles.listenerPlacement.${g}`)})),onChange:g=>e.onUpdate({listenerPlacement:g})}),e.error(`profiles[${r}].listenerPlacement`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].listenerPlacement`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldPreset"),help:t("settings.vcProfiles.presetHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldPreset"),disabled:e.frozen,value:i.permissionPreset,label:H(e.presetOptions,i.permissionPreset),options:e.presetOptions,onChange:g=>e.onUpdate({permissionPreset:g})}),e.error(`profiles[${r}].permissionPreset`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].permissionPreset`)}):null]})]}),(0,a.jsxs)("label",{className:"vc-profile-field vc-profile-instructions",children:[(0,a.jsxs)("span",{children:[(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldInstructions"),help:t("settings.vcProfiles.instructionsHelp")}),(0,a.jsxs)("em",{className:"vc-profile-count",children:[(i.instructions??"").length,"/",he]})]}),(0,a.jsx)("textarea",{rows:7,maxLength:he,value:i.instructions??"",disabled:e.frozen,placeholder:t("settings.vcProfiles.instructionsPlaceholder"),onChange:g=>e.onUpdate({instructions:g.currentTarget.value||void 0})}),e.error(`profiles[${r}].instructions`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].instructions`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldActivityTypes"),help:t("settings.vcProfiles.activityHelp")})}),(0,a.jsx)("div",{className:"vc-profile-activity",children:Le.map(g=>{let f=i.activityTypes?.includes(g)??!1;return(0,a.jsxs)("label",{className:"vc-profile-check",children:[(0,a.jsx)("input",{type:"checkbox",checked:f,disabled:e.frozen,onChange:m=>{let u=new Set(i.activityTypes??[]);m.currentTarget.checked?u.add(g):u.delete(g),e.onUpdate({activityTypes:u.size>0?[...u]:void 0})}}),t(`settings.vcProfiles.activity.${g}`)]},g)})}),(0,a.jsx)("em",{className:"vc-profile-hint",children:t("settings.vcProfiles.activityAllHint")}),e.error(`profiles[${r}].activityTypes`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].activityTypes`)}):null]}),e.canWrite?(0,a.jsxs)("footer",{className:"vc-profile-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profiles-link vc-profile-remove",disabled:e.frozen,onClick:e.onRemove,children:t("settings.vcProfiles.remove")}),(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-done",onClick:e.onClose,children:t("settings.vcProfiles.done")})]}):null]})}function Ve(e){let t=A(),i=e.template;return(0,a.jsxs)(Re,{className:"vc-profile-template-dialog",eyebrow:t("settings.vcProfiles.templates.title"),title:i.title[e.locale],onClose:e.onClose,children:[(0,a.jsx)("p",{className:"vc-profile-template-description",children:i.description[e.locale]}),(0,a.jsxs)("div",{className:"vc-profile-template-facts",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldResponseMode")}),(0,a.jsx)("strong",{children:t(i.responseMode==="listener_thread"?"settings.vcProfiles.responseListener":"settings.vcProfiles.responseSilent")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldListenerPlacement")}),(0,a.jsx)("strong",{children:t(`settings.vcProfiles.listenerPlacement.${i.listenerPlacement}`)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldPreset")}),(0,a.jsx)("strong",{children:t(`settings.vcProfiles.preset.${i.permissionPreset}`)})]})]}),(0,a.jsxs)("section",{className:"vc-profile-template-prompt",children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.fieldInstructions")}),(0,a.jsx)("p",{children:i.instructions[e.locale]})]}),(0,a.jsxs)("section",{className:"vc-profile-template-events",children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.fieldActivityTypes")}),(0,a.jsx)("div",{children:i.activityTypes.map(r=>(0,a.jsx)("span",{children:t(`settings.vcProfiles.activity.${r}`)},r))})]}),(0,a.jsxs)("footer",{className:"vc-profile-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-secondary",onClick:e.onClose,children:t("settings.vcProfiles.close")}),(0,a.jsx)("button",{type:"button",className:"vc-profile-template-use",disabled:e.disabled,onClick:e.onUse,children:t("settings.vcProfiles.templates.use")})]})]})}var n=Y(de(),1),ye=["Asia/Shanghai","Asia/Hong_Kong","Asia/Tokyo","Asia/Singapore","Asia/Kolkata","UTC","Europe/London","Europe/Paris","Europe/Moscow","America/Los_Angeles","America/New_York","America/Sao_Paulo","Australia/Sydney"];function Fe(e,t){if(!e||typeof e!="object")return null;if(e.failed){let i=e.failed.step==="install"?t("settings.herdrTraexInstallStepInstall"):t("settings.herdrTraexInstallStepAction");return{text:`${t("settings.herdrTraexInstallFailed")}\uFF08${i}\uFF09: ${e.failed.reason??""}`,cls:"hint-warn-inline"}}if(e.skippedReason==="plugin_unsupported"){let i=typeof e.herdrVersion=="string"&&e.herdrVersion?` (${e.herdrVersion})`:"";return{text:`${t("settings.herdrTraexUnsupported")}${i}`,cls:"hint-warn-inline"}}return e.installed||e.actionInvoked?{text:t("settings.herdrTraexInstalled"),cls:"hint-ok"}:e.alreadyInstalled?{text:t("settings.herdrTraexAlreadyInstalled"),cls:"hint-ok"}:null}function Pe(e){return{groupNamePrefix:typeof e?.groupNamePrefix=="string"?e.groupNamePrefix:"",publicReadOnly:e?.publicReadOnly===!0,openTerminalInFeishu:e?.openTerminalInFeishu===!0,enableLocalCliOpen:e?.enableLocalCliOpen===!0,localCliOpenMode:e?.localCliOpenMode==="resume"?"resume":"attach",chatBotDiscovery:e?.chatBotDiscovery!==!1,herdrTraexPlugin:{enabled:e?.herdrTraexPlugin?.enabled===!0,source:typeof e?.herdrTraexPlugin?.source=="string"?e.herdrTraexPlugin.source:"",ref:typeof e?.herdrTraexPlugin?.ref=="string"?e.herdrTraexPlugin.ref:"",recommendedSource:typeof e?.herdrTraexPlugin?.recommendedSource=="string"?e.herdrTraexPlugin.recommendedSource:"",recommendedRef:typeof e?.herdrTraexPlugin?.recommendedRef=="string"?e.herdrTraexPlugin.recommendedRef:""},codexRpcInput:e?.codexRpcInput===!0,bypassCodexHookTrust:e?.bypassCodexHookTrust!==!1,codexNotifier:{enabled:e?.codexNotifier?.enabled===!0,targetBotAppId:typeof e?.codexNotifier?.targetBotAppId=="string"?e.codexNotifier.targetBotAppId:null,notifyWhen:e?.codexNotifier?.notifyWhen==="always"?"always":"locked_only",platformSupported:e?.codexNotifier?.platformSupported===!0,hookInstalled:e?.codexNotifier?.hookInstalled===!0,botOptions:Array.isArray(e?.codexNotifier?.botOptions)?e.codexNotifier.botOptions:[],targetDaemonOnline:e?.codexNotifier?.targetDaemonOnline===!0,pendingCount:Number.isSafeInteger(e?.codexNotifier?.pendingCount)?Math.max(0,e.codexNotifier.pendingCount):0,workerOnline:e?.codexNotifier?.workerOnline===!0,lastError:e?.codexNotifier?.lastError&&typeof e.codexNotifier.lastError.message=="string"?e.codexNotifier.lastError:null},hostOverloadAlert:{enabled:e?.hostOverloadAlert?.enabled===!0,targetBotAppId:typeof e?.hostOverloadAlert?.targetBotAppId=="string"?e.hostOverloadAlert.targetBotAppId:null,enterLoadRatio:typeof e?.hostOverloadAlert?.enterLoadRatio=="number"?e.hostOverloadAlert.enterLoadRatio:1.5,enterMemUsedFrac:typeof e?.hostOverloadAlert?.enterMemUsedFrac=="number"?e.hostOverloadAlert.enterMemUsedFrac:.92,botOptions:Array.isArray(e?.hostOverloadAlert?.botOptions)?e.hostOverloadAlert.botOptions:[],targetDaemonOnline:e?.hostOverloadAlert?.targetDaemonOnline===!0},noVisibleOutputHint:e?.noVisibleOutputHint===!0,vcMeetingAgent:{enabled:e?.vcMeetingAgent?.enabled!==!1,listenerBotAppId:typeof e?.vcMeetingAgent?.listenerBotAppId=="string"?e.vcMeetingAgent.listenerBotAppId:null,listenerBotOptions:Array.isArray(e?.vcMeetingAgent?.listenerBotOptions)?e.vcMeetingAgent.listenerBotOptions:[],larkCliVersion:e?.vcMeetingAgent?.larkCliVersion===void 0?void 0:e.vcMeetingAgent.larkCliVersion??null,larkCliMeetsRequirement:e?.vcMeetingAgent?.larkCliMeetsRequirement===!0,larkCliMinVersion:typeof e?.vcMeetingAgent?.larkCliMinVersion=="string"?e.vcMeetingAgent.larkCliMinVersion:void 0},repoPickerMode:e?.repoPickerMode==="repos"?"repos":"all",maintenance:e?.maintenance&&typeof e.maintenance=="object"?e.maintenance:{},localDevInstall:e?.localDevInstall===!0,autoUpdateSupported:e?.autoUpdateSupported!==!1,whiteboard:{enabled:e?.whiteboard?.enabled===!0},remoteAccess:e?.remoteAccess===!0,scheduleTimeZone:typeof e?.scheduleTimeZone=="string"?e.scheduleTimeZone:"",hostTimeZone:typeof e?.hostTimeZone=="string"&&e.hostTimeZone?e.hostTimeZone:"UTC",effectiveScheduleTimeZone:typeof e?.effectiveScheduleTimeZone=="string"&&e.effectiveScheduleTimeZone?e.effectiveScheduleTimeZone:typeof e?.scheduleTimeZone=="string"&&e.scheduleTimeZone?e.scheduleTimeZone:typeof e?.hostTimeZone=="string"&&e.hostTimeZone?e.hostTimeZone:"UTC"}}function We(e,t){let i=e?.[t]??{};return{enabled:i.enabled===!0,time:typeof i.time=="string"?i.time:"04:00"}}function De(e,t){return t(e==="npm-global"?"update.kindNpm":e==="pnpm-global"?"update.kindPnpm":e==="yarn-global"?"update.kindYarn":e==="bun-global"?"update.kindBun":e==="source-checkout"?"update.kindSource":"update.kindUnknown")}function Ze(){let e=A(),t=(0,p.useRef)(!1),i=(0,p.useRef)(new Set),[r,g]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),[u,y]=(0,p.useState)(null),[S,h]=(0,p.useState)(!0),[b,C]=(0,p.useState)(!1),[$,V]=(0,p.useState)(null),[R,W]=(0,p.useState)(null),[c,v]=(0,p.useState)(null),[k,x]=(0,p.useState)(null),[ee,z]=(0,p.useState)(null),[ie,B]=(0,p.useState)(null),[ae,Z]=(0,p.useState)(!1),[G,K]=(0,p.useState)(!0),[I,se]=(0,p.useState)(!1),[ue,Q]=(0,p.useState)(""),[ge,L]=(0,p.useState)(!1),[fe,D]=(0,p.useState)(null),le=(0,p.useCallback)(()=>{for(let s of i.current)window.clearTimeout(s);i.current.clear()},[]),oe=(0,p.useCallback)((s,o)=>{let d=window.setTimeout(()=>{i.current.delete(d),s()},o);return i.current.add(d),d},[]),J=(0,p.useCallback)(async()=>{try{let s=await fetch("/api/update/status"),o=await s.json().catch(()=>({}));if(!t.current)return;if(!s.ok){x(null),z(o?.error??`HTTP ${s.status}`);return}x(o),z(null)}catch(s){if(!t.current)return;x(null),z(s instanceof Error?s.message:String(s))}},[]),F=(0,p.useCallback)(async()=>{try{let s=await fetch("/api/settings"),o=await s.json().catch(()=>({}));if(!t.current)return;if(!s.ok){g(null),y(o?.error??`HTTP ${s.status}`),m(!0);return}g(Pe(o.settings)),h(o.authed===!0),C(o.bound===!0),y(null),m(!0)}catch(s){if(!t.current)return;g(null),y(s instanceof Error?s.message:String(s)),m(!0)}},[]);(0,p.useEffect)(()=>(t.current=!0,F(),()=>{t.current=!1,le()}),[le,F]),(0,p.useEffect)(()=>{f&&(L(!1),D(null),Z(!1),S&&J())},[S,J,f]);async function q(s,o,d){if(!r)return;let P=r;g(d(r)),V(s),W({text:e("settings.saving")});try{let w=await fetch("/api/settings",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(o)}),E=await w.json().catch(()=>({}));if(!t.current)return;if(!w.ok||E.ok===!1)throw typeof E?.feishuLoginQr=="string"&&E.feishuLoginQr&&v(E.feishuLoginQr),new Error(E?.error??`HTTP ${w.status}`);v(null);let X=Pe(E.settings);g(X),be.publicReadOnly=X.publicReadOnly,ve.setScheduleTimeZone(X.effectiveScheduleTimeZone);let re=Fe(E.herdrTraexInstall,e);W(re??{text:e("settings.saved"),cls:"hint-ok"})}catch(w){if(!t.current)return;let E=!1;try{let re=await fetch("/api/settings"),Se=await re.json().catch(()=>({}));if(t.current&&re.ok&&Se?.settings){let me=Pe(Se.settings);g(me),be.publicReadOnly=me.publicReadOnly,ve.setScheduleTimeZone(me.effectiveScheduleTimeZone),E=!0}}catch{}if(!t.current)return;E||g(P);let X=w instanceof Error?w.message:String(w);W({text:E?`${e("settings.saveReconciled")}: ${X}`:`${e("settings.saveFailed")}: ${X}`,cls:"hint-warn-inline"})}finally{t.current&&V(null)}}async function pe(){B(null),K(!0),se(!1);try{let s=await fetch("/api/update/changelog"),o=await s.json().catch(()=>({}));if(!t.current)return;Q(typeof o?.releasesUrl=="string"?o.releasesUrl:""),s.ok?(B(Array.isArray(o.releases)?o.releases:[]),K(o.ok!==!1),se(o.rateLimited===!0)):(B([]),K(!1))}catch{if(!t.current)return;B([]),K(!1)}}function te(){let s=Date.now(),o=async()=>{if(t.current){if(Date.now()-s>9e4){L(!1),D({text:e("update.restartSlow"),cls:"hint-warn-inline"});return}try{let d=await fetch("/__health",{cache:"no-store"});if(!t.current)return;if(d.ok){location.reload();return}}catch{}t.current&&oe(()=>{o()},2e3)}};oe(()=>{o()},3e3)}async function U(s){L(!0),D({text:e("update.restarting")});try{let o=await fetch("/api/update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s?{update:s}:{})}),d=await o.json().catch(()=>({}));if(!o.ok||d.ok===!1)throw new Error(String(d.detail??d.error??`HTTP ${o.status}`));if(!t.current)return}catch(o){if(!t.current)return;L(!1),D({text:e("update.restartFailed",{detail:o instanceof Error?o.message:String(o)}),cls:"hint-warn-inline"});return}te()}async function ne(){let s=k;if(!s)return;if(!s.node.ok){window.alert(e("update.nodeTooOldAlert",{version:s.node.version,required:s.node.required}));return}if(!s.updateSupported||!s.updateCommand){window.alert(e("update.unsupportedInstall"));return}if(s.installs.multiple){let d=s.installs.entries.map(P=>`\u2022 ${P.binPath} (${De(P.kind,e)})`).join(`
1
+ import{b as xe,c as A}from"./chunk-5PAYQ3KT.js";import{a as H,c as ce,j as Me,l as T,q as O}from"./chunk-5CJMHTT4.js";import{a as ve,t as be}from"./chunk-ELL53D62.js";import{a as Oe}from"./chunk-SYC6D5XU.js";import{a as Te,d as de}from"./chunk-5THX4DI2.js";import{c as Y}from"./chunk-7SZRL6FY.js";var p=Y(Te(),1);var N=Y(Te(),1);var a=Y(de(),1),Le=["transcript_received","chat_received","participant_joined","participant_left","magic_share_started","magic_share_ended"],he=8e3,Ue=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,Ee="\u6301\u7EED\u6574\u7406\u4F1A\u8BAE\u7EAA\u8981\uFF0C\u91CD\u70B9\u8BB0\u5F55\u5DF2\u786E\u8BA4\u7684\u51B3\u7B56\u3001\u5F85\u529E\u4E8B\u9879\uFF08\u542B\u8D1F\u8D23\u4EBA\u548C\u622A\u6B62\u65F6\u95F4\uFF09\u4EE5\u53CA\u672A\u89E3\u51B3\u98CE\u9669\uFF1B\u5B57\u5E55\u4FEE\u8BA2\u65F6\u66F4\u65B0\u5DF2\u6709\u6761\u76EE\uFF0C\u4E0D\u91CD\u590D\u8BB0\u5F55\u540C\u4E00\u4E8B\u9879\u3002\u4EC5\u5728\u51FA\u73B0\u65B0\u7684\u5173\u952E\u51B3\u7B56\u3001\u660E\u786E\u5F85\u529E\u6216\u98CE\u9669\uFF0C\u6216\u88AB\u7528\u6237\u70B9\u540D\u65F6\uFF0C\u624D\u5728\u76D1\u542C\u7FA4\u8F93\u51FA\u7B80\u6D01\u589E\u91CF\uFF1B\u65E0\u5B9E\u8D28\u589E\u91CF\u65F6\u4FDD\u6301\u9759\u9ED8\uFF0C\u4E0D\u53D1\u9001\u786E\u8BA4\u6216\u5FC3\u8DF3\u3002\u9700\u8981\u5411\u4F1A\u8BAE\u5185\u53D1\u9001\u6587\u5B57\u6216\u8BED\u97F3\u65F6\uFF0C\u5FC5\u987B\u901A\u8FC7 botmux \u53D7\u7BA1 request-output/action gate \u63D0\u4EA4\uFF0C\u4E0D\u5F97\u7ED5\u8FC7\u6743\u9650\u3001\u6240\u6709\u6743\u4E0E\u5BA1\u6838\u7B56\u7565\u3002",Ie=0;function Ne(){return Ie+=1,`p${Ie}`}function we(e){return{...e,listenerPlacement:e.listenerPlacement??"auto",uiKey:Ne(),isNew:!1}}function He(e){let{uiKey:t,isNew:i,...r}=e;return r}function j(e){return(0,a.jsxs)("span",{className:"vc-profile-field-head",children:[e.title,(0,a.jsx)(Me,{label:e.title,children:(0,a.jsx)("span",{className:"vc-profile-help",children:e.help})})]})}function Re(e){let t=A(),i=(0,N.useRef)(null);return(0,N.useEffect)(()=>{let r=i.current;if(!(!r||r.open))try{r.showModal()}catch{r.setAttribute("open","")}},[]),(0,a.jsxs)("dialog",{ref:i,className:["vc-profile-dialog",e.className].filter(Boolean).join(" "),onClose:e.onClose,onCancel:r=>{r.preventDefault(),e.onClose()},children:[(0,a.jsxs)("header",{className:"vc-profile-dialog-head",children:[(0,a.jsxs)("div",{children:[e.eyebrow?(0,a.jsx)("span",{children:e.eyebrow}):null,(0,a.jsx)("h3",{children:e.title})]}),(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-close","aria-label":t("settings.vcProfiles.close"),onClick:e.onClose})]}),(0,a.jsx)("div",{className:"vc-profile-dialog-body",children:e.children})]})}function Be(e){let t=A();return e.enabled?e.canWrite?(0,a.jsx)(_e,{canWrite:e.canWrite,listenerBotAppId:e.listenerBotAppId,listenerBotOptions:e.listenerBotOptions}):(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.needAuth")}):null}function _e(e){let t=A(),i=xe(),r=(0,N.useRef)(!1),g=e.listenerBotOptions,[f,m]=(0,N.useState)(e.listenerBotAppId??g[0]?.larkAppId??""),[u,y]=(0,N.useState)(null),[S,h]=(0,N.useState)(null),[b,C]=(0,N.useState)(!1),[$,V]=(0,N.useState)(!1),[R,W]=(0,N.useState)(!1),[c,v]=(0,N.useState)(!1),[k,x]=(0,N.useState)({}),[ee,z]=(0,N.useState)(!1),[ie,B]=(0,N.useState)(null),[ae,Z]=(0,N.useState)(null);(0,N.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let G=(0,N.useRef)(0);(0,N.useEffect)(()=>{e.listenerBotAppId&&e.listenerBotAppId!==f&&!$&&m(e.listenerBotAppId)},[$,e.listenerBotAppId,f]);let K=(0,N.useCallback)(async l=>{let s=++G.current;if(y(null),V(!1),v(!1),x({}),B(null),Z(null),!l){h(null);return}C(!0);try{let o=await fetch(`/api/vc-meeting/consumer-profiles?listenerBotAppId=${encodeURIComponent(l)}`),d=await o.json().catch(()=>({}));if(!r.current||G.current!==s)return;!o.ok||d?.ok!==!0?(y(null),h(typeof d?.error=="string"?d.error:`HTTP ${o.status}`)):(y({forBot:l,revision:d.revision,catalogState:d.catalogState==="explicit_empty"||d.catalogState==="legacy_or_partial"||d.catalogState==="profiles"?d.catalogState:"uninitialized",defaultMode:d.defaultMode==="agents"?"agents":"listenOnly",defaultConsumerIds:Array.isArray(d.defaultConsumerIds)?d.defaultConsumerIds:[],profiles:(Array.isArray(d.profiles)?d.profiles:[]).map(we),agentOptions:Array.isArray(d.agentOptions)?d.agentOptions:[],templateCatalog:d.templateCatalog?.schemaVersion===1&&Array.isArray(d.templateCatalog.templates)?d.templateCatalog:{schemaVersion:1,templates:[]},...d.migrationOffer==="enable_seeded_minutes_default"?{migrationOffer:d.migrationOffer}:{}}),h(null),V(!1))}catch(o){if(!r.current||G.current!==s)return;y(null),h(o instanceof Error?o.message:String(o))}finally{r.current&&G.current===s&&C(!1)}},[]);(0,N.useEffect)(()=>{K(f)},[K,f]);let I=(0,N.useCallback)(l=>{y(s=>s&&l(s)),V(!0),z(!1)},[]),se=(0,N.useCallback)((l,s)=>{I(o=>({...o,profiles:o.profiles.map(d=>d.uiKey===l?{...d,...s}:d)}))},[I]),ue=(0,N.useCallback)(async()=>{if(!u||R||b||!u.forBot||u.forBot!==f)return;let l={};if(u.profiles.forEach((s,o)=>{Ue.test(s.id)||(l[`profiles[${o}].id`]=t("settings.vcProfiles.idInvalid")),(s.instructions??"").length>he&&(l[`profiles[${o}].instructions`]=t("settings.vcProfiles.instructionsTooLong"))}),Object.keys(l).length>0){x(l);return}W(!0),v(!1),x({});try{let s=await fetch("/api/vc-meeting/consumer-profiles",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({listenerBotAppId:u.forBot,expectedRevision:u.revision,defaultMode:u.defaultMode,defaultConsumerIds:u.defaultConsumerIds,profiles:u.profiles.map(He)})}),o=await s.json().catch(()=>({}));if(!r.current||u.forBot!==f)return;if(s.status===409){v(!0);return}if(s.status===422){let d={};for(let P of Array.isArray(o?.fieldErrors)?o.fieldErrors:[])typeof P?.path=="string"&&typeof P?.message=="string"&&(d[P.path]=P.message);x(Object.keys(d).length>0?d:{profiles:t("settings.vcProfiles.validationFailed")});return}if(!s.ok||o?.ok!==!0){x({profiles:typeof o?.error=="string"?o.error:`HTTP ${s.status}`});return}y({forBot:u.forBot,revision:o.revision,catalogState:o.catalogState==="explicit_empty"||o.catalogState==="legacy_or_partial"||o.catalogState==="profiles"?o.catalogState:"uninitialized",defaultMode:o.defaultMode==="agents"?"agents":"listenOnly",defaultConsumerIds:Array.isArray(o.defaultConsumerIds)?o.defaultConsumerIds:[],profiles:(Array.isArray(o.profiles)?o.profiles:[]).map(we),agentOptions:Array.isArray(o.agentOptions)?o.agentOptions:[],templateCatalog:o.templateCatalog?.schemaVersion===1&&Array.isArray(o.templateCatalog.templates)?o.templateCatalog:{schemaVersion:1,templates:[]},...o.migrationOffer==="enable_seeded_minutes_default"?{migrationOffer:o.migrationOffer}:{}}),V(!1),z(!0)}catch(s){if(!r.current)return;x({profiles:s instanceof Error?s.message:String(s)})}finally{r.current&&W(!1)}},[u,R,f,t]),Q=(0,N.useMemo)(()=>g.map(l=>({value:l.larkAppId,label:l.botName||l.larkAppId})),[g]),ge=Q.find(l=>l.value===f)?.label??f,L=(0,N.useMemo)(()=>u?u.agentOptions.map(l=>{let s=[l.online?void 0:t("settings.vcProfiles.agentOffline"),l.workingDirReady?void 0:t("settings.vcProfiles.agentNoWorkingDir"),l.reliableTurnTerminal?void 0:t("settings.vcProfiles.agentNoReliableTerminal"),l.managedSideEffectIsolation?void 0:t("settings.vcProfiles.agentNoManagedIsolation")].filter(Boolean);return{value:l.appId,label:(0,a.jsxs)("span",{className:"vc-agent-option",children:[(0,a.jsxs)("span",{className:"vc-agent-option-name",children:[l.label,l.cliId?(0,a.jsx)("em",{className:"vc-agent-option-cli",children:l.cliId}):null]}),s.length>0?(0,a.jsxs)("span",{className:"vc-agent-option-warn",children:["\u26A0 ",s.join(" \xB7 ")]}):null]})}}):[],[u,t]),fe=l=>{let s=u?.agentOptions.find(d=>d.appId===l);return s?!s.online||!s.workingDirReady||!s.reliableTurnTerminal||!s.managedSideEffectIsolation?`\u26A0 ${s.label}`:s.label:l},D=(0,N.useCallback)(l=>{let o=["observe_only","meeting_text","meeting_voice","meeting_text_voice"].map(d=>({value:d,label:t(`settings.vcProfiles.preset.${d}`)}));return(!l.isNew||l.permissionPreset==="custom")&&o.push({value:"custom",label:t("settings.vcProfiles.preset.custom")}),o},[t]),le=(0,N.useCallback)(()=>{let l=Ne();I(s=>({...s,profiles:[...s.profiles,{uiKey:l,isNew:!0,id:"",agentAppId:s.agentOptions[0]?.appId??"",responseMode:"silent",listenerPlacement:"auto",permissionPreset:"observe_only"}]})),B(l)},[I]),oe=(0,N.useCallback)(l=>{let s=Ne();I(o=>{let d=new Set(o.profiles.map(w=>w.id)),P=l.suggestedProfileId;for(let w=2;d.has(P);w+=1)P=`${l.suggestedProfileId.slice(0,60)}-${w}`;return{...o,profiles:[...o.profiles,{uiKey:s,isNew:!0,id:P,label:l.profileLabel[i],agentAppId:o.agentOptions[0]?.appId??"",instructions:l.instructions[i],activityTypes:[...l.activityTypes],responseMode:l.responseMode,listenerPlacement:l.listenerPlacement,permissionPreset:l.permissionPreset}]}}),Z(null),B(s)},[i,I]),J=(0,N.useCallback)(l=>{I(s=>({...s,profiles:s.profiles.filter(o=>o.uiKey!==l),defaultConsumerIds:s.defaultConsumerIds.filter(o=>s.profiles.some(d=>d.uiKey!==l&&d.id===o))})),B(s=>s===l?null:s)},[I]);if(g.length===0)return null;let F=l=>k[l],q=!e.canWrite||R||b,pe=u?.agentOptions.some(l=>l.workingDirReady&&l.reliableTurnTerminal&&l.managedSideEffectIsolation)??!1,te=u?.profiles.findIndex(l=>l.uiKey===ie)??-1,U=te>=0?u?.profiles[te]??null:null,ne=u?.templateCatalog.templates.find(l=>l.templateId===ae)??null,Ae=(l,s)=>{l.id&&I(o=>{let d=s?[...new Set([...o.defaultConsumerIds,l.id])]:o.defaultConsumerIds.filter(P=>P!==l.id);return{...o,defaultMode:d.length>0?"agents":"listenOnly",defaultConsumerIds:d}})};return(0,a.jsxs)("div",{className:"vc-profiles-section",children:[(0,a.jsxs)("div",{className:"settings-field-row",children:[(0,a.jsx)(T,{help:t("settings.vcProfiles.help"),children:t("settings.vcProfiles.title")}),e.listenerBotAppId===null&&Q.length>1?(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.listenerOwner")}),(0,a.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.vcProfiles.listenerOwner"),disabled:b||R,value:f,label:H(Q,f),options:Q,onChange:l=>{l!==f&&($&&!window.confirm(t("settings.vcProfiles.discardConfirm"))||m(l))}})]}):(0,a.jsx)("span",{className:"vc-profile-config-target",children:t("settings.vcProfiles.configuringBot",{bot:ge})})]}),(0,a.jsx)("p",{className:"hint vc-profiles-freeze",children:t("settings.vcProfiles.freezeNotice")}),b?(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.loading")}):null,S?(0,a.jsx)("p",{className:"hint-warn",children:S==="bot_not_in_config"?t("settings.vcProfiles.botNotInConfig"):`${t("settings.vcProfiles.loadFailed")}: ${S}`}):null,c?(0,a.jsxs)("p",{className:"hint-warn",children:[t("settings.vcProfiles.conflict")," ",(0,a.jsx)("button",{type:"button",className:"vc-profiles-link",onClick:()=>{K(f)},children:t("settings.vcProfiles.reload")})]}):null,F("profiles")?(0,a.jsx)("p",{className:"hint-warn",children:F("profiles")}):null,u?(0,a.jsxs)(a.Fragment,{children:[u.migrationOffer==="enable_seeded_minutes_default"?(0,a.jsxs)("p",{className:"hint-warn vc-profile-migration-offer",children:[t("settings.vcProfiles.migrationOffer")," ",(0,a.jsx)("button",{type:"button",className:"vc-profiles-link",disabled:q||$,onClick:()=>I(l=>({...l,defaultMode:"agents",defaultConsumerIds:["minutes"],profiles:l.profiles.map(s=>s.id==="minutes"?{...s,instructions:Ee,responseMode:"listener_thread",permissionPreset:"meeting_text_voice"}:s),migrationOffer:void 0})),children:t("settings.vcProfiles.migrationEnable")})]}):null,u.catalogState==="uninitialized"&&u.profiles.length===0&&!pe?(0,a.jsx)("p",{className:"hint-warn",children:t("settings.vcProfiles.noEligibleDefaultAgent")}):null,u.catalogState==="legacy_or_partial"?(0,a.jsx)("p",{className:"hint",children:t("settings.vcProfiles.legacyCatalog")}):null,(0,a.jsxs)("section",{className:"vc-profile-library-section",children:[(0,a.jsxs)("div",{className:"vc-profile-list-heading",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.list.title")}),(0,a.jsx)("p",{children:t("settings.vcProfiles.list.help")})]}),e.canWrite?(0,a.jsx)("button",{type:"button",className:"vc-profiles-link vc-profile-add",disabled:R||b,onClick:le,children:t("settings.vcProfiles.add")}):null]}),u.profiles.length>0?(0,a.jsx)("div",{className:"vc-profile-card-grid",children:u.profiles.map(l=>{let s=u.agentOptions.find(d=>d.appId===l.agentAppId),o=u.defaultMode==="agents"&&u.defaultConsumerIds.includes(l.id);return(0,a.jsxs)("article",{className:"vc-profile-summary-card",role:"button",tabIndex:0,onClick:()=>B(l.uiKey),onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),B(l.uiKey))},children:[(0,a.jsxs)("div",{className:"vc-profile-summary-top",children:[(0,a.jsx)("span",{className:"vc-profile-summary-icon","aria-hidden":"true",children:(l.label||l.id||"?").slice(0,1)}),(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:l.label||l.id||t("settings.vcProfiles.untitled")}),(0,a.jsx)("code",{children:l.id||t("settings.vcProfiles.newBadge")})]}),l.isNew?(0,a.jsx)("em",{children:t("settings.vcProfiles.newBadge")}):null]}),(0,a.jsx)("p",{children:(l.instructions??"").trim()||t("settings.vcProfiles.noInstructions")}),(0,a.jsxs)("div",{className:"vc-profile-summary-meta",children:[(0,a.jsx)("span",{children:s?.label??l.agentAppId}),(0,a.jsx)("span",{children:l.responseMode==="listener_thread"?t("settings.vcProfiles.responseListener"):t("settings.vcProfiles.responseSilent")})]}),(0,a.jsxs)("label",{className:"vc-profile-default-toggle",onClick:d=>d.stopPropagation(),children:[(0,a.jsx)("input",{type:"checkbox",checked:o,disabled:q||!l.id,onChange:d=>Ae(l,d.currentTarget.checked)}),(0,a.jsx)("span",{children:t("settings.vcProfiles.setDefault")})]})]},l.uiKey)})}):(0,a.jsx)("p",{className:"vc-profile-empty",children:t("settings.vcProfiles.list.empty")})]}),u.templateCatalog.templates.length>0?(0,a.jsxs)("section",{className:"vc-profile-template-catalog",children:[(0,a.jsxs)("div",{className:"vc-profile-template-heading",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.templates.title")}),(0,a.jsx)("p",{children:t("settings.vcProfiles.templates.help")})]}),(0,a.jsx)("span",{children:t("settings.vcProfiles.templates.builtinBadge")})]}),(0,a.jsx)("div",{className:"vc-profile-template-grid",children:u.templateCatalog.templates.map(l=>(0,a.jsxs)("button",{type:"button",className:"vc-profile-template-card",onClick:()=>Z(l.templateId),children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"\u2726"}),(0,a.jsx)("strong",{children:l.title[i]}),(0,a.jsx)("p",{children:l.description[i]}),(0,a.jsxs)("em",{children:[t("settings.vcProfiles.viewDetails")," \u2192"]})]},`${l.templateId}@${l.version}`))})]}):null,(0,a.jsxs)("div",{className:"settings-field-row vc-profile-default-mode-row",children:[(0,a.jsx)(T,{help:t("settings.vcProfiles.defaultModeHelp"),children:t("settings.vcProfiles.defaultMode")}),(0,a.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.vcProfiles.defaultMode"),disabled:q,value:u.defaultMode,label:u.defaultMode==="agents"?t("settings.vcProfiles.defaultModeAgents"):t("settings.vcProfiles.defaultModeListenOnly"),options:[{value:"listenOnly",label:t("settings.vcProfiles.defaultModeListenOnly")},{value:"agents",label:t("settings.vcProfiles.defaultModeAgents")}],onChange:l=>I(s=>({...s,defaultMode:l==="agents"?"agents":"listenOnly"}))})]}),F("defaultConsumerIds")?(0,a.jsx)("em",{className:"vc-profile-err",children:F("defaultConsumerIds")}):null,F("defaultMode")?(0,a.jsx)("em",{className:"vc-profile-err",children:F("defaultMode")}):null,e.canWrite?(0,a.jsxs)("div",{className:"vc-profiles-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profiles-save",disabled:!$||R||c,onClick:()=>{ue()},children:t(R?"settings.vcProfiles.saving":"settings.vcProfiles.save")}),ee?(0,a.jsx)("span",{className:"vc-profile-hint",children:t("settings.vcProfiles.saved")}):null,$&&!R?(0,a.jsx)("span",{className:"vc-profile-hint",children:t("settings.vcProfiles.unsaved")}):null]}):null,U?(0,a.jsx)($e,{profile:U,index:te,frozen:q,canWrite:e.canWrite,agentOptions:L,agentLabel:fe(U.agentAppId),presetOptions:D(U),error:F,onClose:()=>B(null),onUpdate:l=>se(U.uiKey,l),onIdChange:l=>{let s=U.id;I(o=>({...o,profiles:o.profiles.map(d=>d.uiKey===U.uiKey?{...d,id:l}:d),defaultConsumerIds:o.defaultConsumerIds.map(d=>d===s&&s?l:d).filter(Boolean)}))},onRemove:()=>J(U.uiKey)}):null,ne?(0,a.jsx)(Ve,{template:ne,locale:i,disabled:q||u.agentOptions.length===0,onClose:()=>Z(null),onUse:()=>oe(ne)}):null]}):null]})}function $e(e){let t=A(),{profile:i,index:r}=e;return(0,a.jsxs)(Re,{className:"vc-profile-editor-dialog",eyebrow:t("settings.vcProfiles.list.title"),title:i.label||i.id||t("settings.vcProfiles.untitled"),onClose:e.onClose,children:[(0,a.jsxs)("div",{className:"vc-profile-grid",children:[(0,a.jsxs)("label",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldId"),help:t("settings.vcProfiles.idHelp")})}),(0,a.jsx)("input",{type:"text",value:i.id,disabled:e.frozen||!i.isNew,placeholder:"minutes",onChange:g=>e.onIdChange(g.currentTarget.value)}),e.error(`profiles[${r}].id`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].id`)}):null]}),(0,a.jsxs)("label",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldLabel"),help:t("settings.vcProfiles.labelHelp")})}),(0,a.jsx)("input",{type:"text",value:i.label??"",disabled:e.frozen,onChange:g=>e.onUpdate({label:g.currentTarget.value||void 0})}),e.error(`profiles[${r}].label`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].label`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldAgent"),help:t("settings.vcProfiles.agentHelp")})}),(0,a.jsx)(O,{className:"vc-profile-agent-menu",ariaLabel:t("settings.vcProfiles.fieldAgent"),disabled:e.frozen,value:i.agentAppId,label:e.agentLabel,options:e.agentOptions,onChange:g=>e.onUpdate({agentAppId:g})}),e.error(`profiles[${r}].agentAppId`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].agentAppId`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldResponseMode"),help:t("settings.vcProfiles.responseModeHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldResponseMode"),disabled:e.frozen,value:i.responseMode,label:i.responseMode==="listener_thread"?t("settings.vcProfiles.responseListener"):t("settings.vcProfiles.responseSilent"),options:[{value:"silent",label:t("settings.vcProfiles.responseSilent")},{value:"listener_thread",label:t("settings.vcProfiles.responseListener")}],onChange:g=>e.onUpdate({responseMode:g})}),e.error(`profiles[${r}].responseMode`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].responseMode`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldListenerPlacement"),help:t("settings.vcProfiles.listenerPlacementHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldListenerPlacement"),disabled:e.frozen||i.responseMode==="silent",value:i.listenerPlacement??"auto",label:t(`settings.vcProfiles.listenerPlacement.${i.listenerPlacement??"auto"}`),options:["auto","chat","topic"].map(g=>({value:g,label:t(`settings.vcProfiles.listenerPlacement.${g}`)})),onChange:g=>e.onUpdate({listenerPlacement:g})}),e.error(`profiles[${r}].listenerPlacement`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].listenerPlacement`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldPreset"),help:t("settings.vcProfiles.presetHelp")})}),(0,a.jsx)(O,{ariaLabel:t("settings.vcProfiles.fieldPreset"),disabled:e.frozen,value:i.permissionPreset,label:H(e.presetOptions,i.permissionPreset),options:e.presetOptions,onChange:g=>e.onUpdate({permissionPreset:g})}),e.error(`profiles[${r}].permissionPreset`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].permissionPreset`)}):null]})]}),(0,a.jsxs)("label",{className:"vc-profile-field vc-profile-instructions",children:[(0,a.jsxs)("span",{children:[(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldInstructions"),help:t("settings.vcProfiles.instructionsHelp")}),(0,a.jsxs)("em",{className:"vc-profile-count",children:[(i.instructions??"").length,"/",he]})]}),(0,a.jsx)("textarea",{rows:7,maxLength:he,value:i.instructions??"",disabled:e.frozen,placeholder:t("settings.vcProfiles.instructionsPlaceholder"),onChange:g=>e.onUpdate({instructions:g.currentTarget.value||void 0})}),e.error(`profiles[${r}].instructions`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].instructions`)}):null]}),(0,a.jsxs)("div",{className:"vc-profile-field",children:[(0,a.jsx)("span",{children:(0,a.jsx)(j,{title:t("settings.vcProfiles.fieldActivityTypes"),help:t("settings.vcProfiles.activityHelp")})}),(0,a.jsx)("div",{className:"vc-profile-activity",children:Le.map(g=>{let f=i.activityTypes?.includes(g)??!1;return(0,a.jsxs)("label",{className:"vc-profile-check",children:[(0,a.jsx)("input",{type:"checkbox",checked:f,disabled:e.frozen,onChange:m=>{let u=new Set(i.activityTypes??[]);m.currentTarget.checked?u.add(g):u.delete(g),e.onUpdate({activityTypes:u.size>0?[...u]:void 0})}}),t(`settings.vcProfiles.activity.${g}`)]},g)})}),(0,a.jsx)("em",{className:"vc-profile-hint",children:t("settings.vcProfiles.activityAllHint")}),e.error(`profiles[${r}].activityTypes`)?(0,a.jsx)("em",{className:"vc-profile-err",children:e.error(`profiles[${r}].activityTypes`)}):null]}),e.canWrite?(0,a.jsxs)("footer",{className:"vc-profile-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profiles-link vc-profile-remove",disabled:e.frozen,onClick:e.onRemove,children:t("settings.vcProfiles.remove")}),(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-done",onClick:e.onClose,children:t("settings.vcProfiles.done")})]}):null]})}function Ve(e){let t=A(),i=e.template;return(0,a.jsxs)(Re,{className:"vc-profile-template-dialog",eyebrow:t("settings.vcProfiles.templates.title"),title:i.title[e.locale],onClose:e.onClose,children:[(0,a.jsx)("p",{className:"vc-profile-template-description",children:i.description[e.locale]}),(0,a.jsxs)("div",{className:"vc-profile-template-facts",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldResponseMode")}),(0,a.jsx)("strong",{children:t(i.responseMode==="listener_thread"?"settings.vcProfiles.responseListener":"settings.vcProfiles.responseSilent")})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldListenerPlacement")}),(0,a.jsx)("strong",{children:t(`settings.vcProfiles.listenerPlacement.${i.listenerPlacement}`)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:t("settings.vcProfiles.fieldPreset")}),(0,a.jsx)("strong",{children:t(`settings.vcProfiles.preset.${i.permissionPreset}`)})]})]}),(0,a.jsxs)("section",{className:"vc-profile-template-prompt",children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.fieldInstructions")}),(0,a.jsx)("p",{children:i.instructions[e.locale]})]}),(0,a.jsxs)("section",{className:"vc-profile-template-events",children:[(0,a.jsx)("strong",{children:t("settings.vcProfiles.fieldActivityTypes")}),(0,a.jsx)("div",{children:i.activityTypes.map(r=>(0,a.jsx)("span",{children:t(`settings.vcProfiles.activity.${r}`)},r))})]}),(0,a.jsxs)("footer",{className:"vc-profile-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"vc-profile-dialog-secondary",onClick:e.onClose,children:t("settings.vcProfiles.close")}),(0,a.jsx)("button",{type:"button",className:"vc-profile-template-use",disabled:e.disabled,onClick:e.onUse,children:t("settings.vcProfiles.templates.use")})]})]})}var n=Y(de(),1),ye=["Asia/Shanghai","Asia/Hong_Kong","Asia/Tokyo","Asia/Singapore","Asia/Kolkata","UTC","Europe/London","Europe/Paris","Europe/Moscow","America/Los_Angeles","America/New_York","America/Sao_Paulo","Australia/Sydney"];function Fe(e,t){if(!e||typeof e!="object")return null;if(e.failed){let i=e.failed.step==="install"?t("settings.herdrTraexInstallStepInstall"):t("settings.herdrTraexInstallStepAction");return{text:`${t("settings.herdrTraexInstallFailed")}\uFF08${i}\uFF09: ${e.failed.reason??""}`,cls:"hint-warn-inline"}}if(e.skippedReason==="plugin_unsupported"){let i=typeof e.herdrVersion=="string"&&e.herdrVersion?` (${e.herdrVersion})`:"";return{text:`${t("settings.herdrTraexUnsupported")}${i}`,cls:"hint-warn-inline"}}return e.installed||e.actionInvoked?{text:t("settings.herdrTraexInstalled"),cls:"hint-ok"}:e.alreadyInstalled?{text:t("settings.herdrTraexAlreadyInstalled"),cls:"hint-ok"}:null}function Pe(e){return{groupNamePrefix:typeof e?.groupNamePrefix=="string"?e.groupNamePrefix:"",publicReadOnly:e?.publicReadOnly===!0,openTerminalInFeishu:e?.openTerminalInFeishu===!0,enableLocalCliOpen:e?.enableLocalCliOpen===!0,localCliOpenMode:e?.localCliOpenMode==="resume"?"resume":"attach",chatBotDiscovery:e?.chatBotDiscovery!==!1,herdrTraexPlugin:{enabled:e?.herdrTraexPlugin?.enabled===!0,source:typeof e?.herdrTraexPlugin?.source=="string"?e.herdrTraexPlugin.source:"",ref:typeof e?.herdrTraexPlugin?.ref=="string"?e.herdrTraexPlugin.ref:"",recommendedSource:typeof e?.herdrTraexPlugin?.recommendedSource=="string"?e.herdrTraexPlugin.recommendedSource:"",recommendedRef:typeof e?.herdrTraexPlugin?.recommendedRef=="string"?e.herdrTraexPlugin.recommendedRef:""},codexRpcInput:e?.codexRpcInput===!0,bypassCodexHookTrust:e?.bypassCodexHookTrust!==!1,codexNotifier:{enabled:e?.codexNotifier?.enabled===!0,targetBotAppId:typeof e?.codexNotifier?.targetBotAppId=="string"?e.codexNotifier.targetBotAppId:null,notifyWhen:e?.codexNotifier?.notifyWhen==="always"?"always":"locked_only",platformSupported:e?.codexNotifier?.platformSupported===!0,hookInstalled:e?.codexNotifier?.hookInstalled===!0,botOptions:Array.isArray(e?.codexNotifier?.botOptions)?e.codexNotifier.botOptions:[],targetDaemonOnline:e?.codexNotifier?.targetDaemonOnline===!0,pendingCount:Number.isSafeInteger(e?.codexNotifier?.pendingCount)?Math.max(0,e.codexNotifier.pendingCount):0,workerOnline:e?.codexNotifier?.workerOnline===!0,lastError:e?.codexNotifier?.lastError&&typeof e.codexNotifier.lastError.message=="string"?e.codexNotifier.lastError:null},hostOverloadAlert:{enabled:e?.hostOverloadAlert?.enabled===!0,targetBotAppId:typeof e?.hostOverloadAlert?.targetBotAppId=="string"?e.hostOverloadAlert.targetBotAppId:null,enterLoadRatio:typeof e?.hostOverloadAlert?.enterLoadRatio=="number"?e.hostOverloadAlert.enterLoadRatio:1.5,enterMemUsedFrac:typeof e?.hostOverloadAlert?.enterMemUsedFrac=="number"?e.hostOverloadAlert.enterMemUsedFrac:.92,botOptions:Array.isArray(e?.hostOverloadAlert?.botOptions)?e.hostOverloadAlert.botOptions:[],targetDaemonOnline:e?.hostOverloadAlert?.targetDaemonOnline===!0},noVisibleOutputHint:e?.noVisibleOutputHint===!0,vcMeetingAgent:{enabled:e?.vcMeetingAgent?.enabled!==!1,listenerBotAppId:typeof e?.vcMeetingAgent?.listenerBotAppId=="string"?e.vcMeetingAgent.listenerBotAppId:null,listenerBotOptions:Array.isArray(e?.vcMeetingAgent?.listenerBotOptions)?e.vcMeetingAgent.listenerBotOptions:[],larkCliVersion:e?.vcMeetingAgent?.larkCliVersion===void 0?void 0:e.vcMeetingAgent.larkCliVersion??null,larkCliMeetsRequirement:e?.vcMeetingAgent?.larkCliMeetsRequirement===!0,larkCliMinVersion:typeof e?.vcMeetingAgent?.larkCliMinVersion=="string"?e.vcMeetingAgent.larkCliMinVersion:void 0},repoPickerMode:e?.repoPickerMode==="repos"?"repos":"all",maintenance:e?.maintenance&&typeof e.maintenance=="object"?e.maintenance:{},localDevInstall:e?.localDevInstall===!0,autoUpdateSupported:e?.autoUpdateSupported!==!1,whiteboard:{enabled:e?.whiteboard?.enabled===!0},remoteAccess:e?.remoteAccess===!0,scheduleTimeZone:typeof e?.scheduleTimeZone=="string"?e.scheduleTimeZone:"",hostTimeZone:typeof e?.hostTimeZone=="string"&&e.hostTimeZone?e.hostTimeZone:"UTC",effectiveScheduleTimeZone:typeof e?.effectiveScheduleTimeZone=="string"&&e.effectiveScheduleTimeZone?e.effectiveScheduleTimeZone:typeof e?.scheduleTimeZone=="string"&&e.scheduleTimeZone?e.scheduleTimeZone:typeof e?.hostTimeZone=="string"&&e.hostTimeZone?e.hostTimeZone:"UTC"}}function We(e,t){let i=e?.[t]??{};return{enabled:i.enabled===!0,time:typeof i.time=="string"?i.time:"04:00"}}function De(e,t){return t(e==="npm-global"?"update.kindNpm":e==="pnpm-global"?"update.kindPnpm":e==="yarn-global"?"update.kindYarn":e==="bun-global"?"update.kindBun":e==="source-checkout"?"update.kindSource":"update.kindUnknown")}function Ze(){let e=A(),t=(0,p.useRef)(!1),i=(0,p.useRef)(new Set),[r,g]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),[u,y]=(0,p.useState)(null),[S,h]=(0,p.useState)(!0),[b,C]=(0,p.useState)(!1),[$,V]=(0,p.useState)(null),[R,W]=(0,p.useState)(null),[c,v]=(0,p.useState)(null),[k,x]=(0,p.useState)(null),[ee,z]=(0,p.useState)(null),[ie,B]=(0,p.useState)(null),[ae,Z]=(0,p.useState)(!1),[G,K]=(0,p.useState)(!0),[I,se]=(0,p.useState)(!1),[ue,Q]=(0,p.useState)(""),[ge,L]=(0,p.useState)(!1),[fe,D]=(0,p.useState)(null),le=(0,p.useCallback)(()=>{for(let s of i.current)window.clearTimeout(s);i.current.clear()},[]),oe=(0,p.useCallback)((s,o)=>{let d=window.setTimeout(()=>{i.current.delete(d),s()},o);return i.current.add(d),d},[]),J=(0,p.useCallback)(async()=>{try{let s=await fetch("/api/update/status"),o=await s.json().catch(()=>({}));if(!t.current)return;if(!s.ok){x(null),z(o?.error??`HTTP ${s.status}`);return}x(o),z(null)}catch(s){if(!t.current)return;x(null),z(s instanceof Error?s.message:String(s))}},[]),F=(0,p.useCallback)(async()=>{try{let s=await fetch("/api/settings"),o=await s.json().catch(()=>({}));if(!t.current)return;if(!s.ok){g(null),y(o?.error??`HTTP ${s.status}`),m(!0);return}g(Pe(o.settings)),h(o.authed===!0),C(o.bound===!0),y(null),m(!0)}catch(s){if(!t.current)return;g(null),y(s instanceof Error?s.message:String(s)),m(!0)}},[]);(0,p.useEffect)(()=>(t.current=!0,F(),()=>{t.current=!1,le()}),[le,F]),(0,p.useEffect)(()=>{f&&(L(!1),D(null),Z(!1),S&&J())},[S,J,f]);async function q(s,o,d){if(!r)return;let P=r;g(d(r)),V(s),W({text:e("settings.saving")});try{let w=await fetch("/api/settings",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(o)}),E=await w.json().catch(()=>({}));if(!t.current)return;if(!w.ok||E.ok===!1)throw typeof E?.feishuLoginQr=="string"&&E.feishuLoginQr&&v(E.feishuLoginQr),new Error(E?.error??`HTTP ${w.status}`);v(null);let X=Pe(E.settings);g(X),be.publicReadOnly=X.publicReadOnly,ve.setScheduleTimeZone(X.effectiveScheduleTimeZone);let re=Fe(E.herdrTraexInstall,e);W(re??{text:e("settings.saved"),cls:"hint-ok"})}catch(w){if(!t.current)return;let E=!1;try{let re=await fetch("/api/settings"),Se=await re.json().catch(()=>({}));if(t.current&&re.ok&&Se?.settings){let me=Pe(Se.settings);g(me),be.publicReadOnly=me.publicReadOnly,ve.setScheduleTimeZone(me.effectiveScheduleTimeZone),E=!0}}catch{}if(!t.current)return;E||g(P);let X=w instanceof Error?w.message:String(w);W({text:E?`${e("settings.saveReconciled")}: ${X}`:`${e("settings.saveFailed")}: ${X}`,cls:"hint-warn-inline"})}finally{t.current&&V(null)}}async function pe(){B(null),K(!0),se(!1);try{let s=await fetch("/api/update/changelog"),o=await s.json().catch(()=>({}));if(!t.current)return;Q(typeof o?.releasesUrl=="string"?o.releasesUrl:""),s.ok?(B(Array.isArray(o.releases)?o.releases:[]),K(o.ok!==!1),se(o.rateLimited===!0)):(B([]),K(!1))}catch{if(!t.current)return;B([]),K(!1)}}function te(){let s=Date.now(),o=async()=>{if(t.current){if(Date.now()-s>9e4){L(!1),D({text:e("update.restartSlow"),cls:"hint-warn-inline"});return}try{let d=await fetch("/__health",{cache:"no-store"});if(!t.current)return;if(d.ok){location.reload();return}}catch{}t.current&&oe(()=>{o()},2e3)}};oe(()=>{o()},3e3)}async function U(s){L(!0),D({text:e("update.restarting")});try{let o=await fetch("/api/update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s?{update:s}:{})}),d=await o.json().catch(()=>({}));if(!o.ok||d.ok===!1)throw new Error(String(d.detail??d.error??`HTTP ${o.status}`));if(!t.current)return}catch(o){if(!t.current)return;L(!1),D({text:e("update.restartFailed",{detail:o instanceof Error?o.message:String(o)}),cls:"hint-warn-inline"});return}te()}async function ne(){let s=k;if(!s)return;if(!s.node.ok){window.alert(e("update.nodeTooOldAlert",{version:s.node.version,required:s.node.required}));return}if(!s.updateSupported||!s.updateCommand){window.alert(e("update.unsupportedInstall"));return}if(s.installs.multiple){let d=s.installs.entries.map(P=>`\u2022 ${P.binPath} (${De(P.kind,e)})`).join(`
2
2
  `);if(!window.confirm(e("update.confirmMultiInstall",{paths:d})))return}let o=s.latest?e("update.confirmUpdate",{version:`v${s.latest}`,command:s.updateCommand}):e("update.confirmUpdateNoVer",{command:s.updateCommand});if(window.confirm(o)){L(!0),D({text:e("update.updating",{command:s.updateCommand})});try{let d=await fetch("/api/update/run",{method:"POST"}),P=await d.json().catch(()=>({}));if(!t.current)return;if(!d.ok||P.ok===!1){let w=P?.detail??P?.error??`HTTP ${d.status}`;L(!1),D({text:e("update.updateFailed",{detail:w}),cls:"hint-warn-inline"});return}P.changed?(L(!1),D({text:e("update.updatedChanged",{old:`v${P.oldVersion}`,new:`v${P.newVersion}`}),cls:"hint-ok"}),window.confirm(e("update.confirmRestart"))?await U({oldVersion:P.oldVersion,newVersion:P.newVersion}):t.current&&D({text:e("update.noRestartHint"),cls:"hint-ok"})):(L(!1),D({text:e("update.alreadyLatestRun",{version:`v${P.newVersion}`}),cls:"hint-ok"}),await J())}catch(d){if(!t.current)return;L(!1),D({text:e("update.updateFailed",{detail:d instanceof Error?d.message:String(d)}),cls:"hint-warn-inline"})}}}let l=r?(0,n.jsx)(Ke,{settings:r,canWrite:S,bound:b,savingKey:$,message:R,updateBlock:(0,n.jsx)(Ye,{canWrite:S,status:k,statusError:ee,changelog:ie,changelogOpen:ae,changelogOk:G,changelogRateLimited:I,releasesUrl:ue,busy:ge,message:fe,onCheck:()=>{x(null),B(null),Z(!1),D(null),z(null),J()},onToggleChangelog:()=>{let s=!ae;Z(s),s&&ie===null&&pe()},onUpdate:()=>{ne()},onRestart:()=>{window.confirm(e("update.confirmPlainRestart"))&&U(null)}}),feishuLoginQr:c,onCloseFeishuLoginQr:()=>v(null),onSave:q}):u?(0,n.jsxs)("p",{className:"hint-warn",children:[e("settings.loadFailed"),": ",u]}):(0,n.jsx)(ce,{label:e("settings.loading")});return(0,n.jsxs)("section",{className:"page settings-page",children:[(0,n.jsx)("div",{className:"page-heading",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"eyebrow",children:e("nav.settings")}),(0,n.jsx)("h1",{children:e("settings.title")})]})}),l]})}function Ke(e){let t=A(),{settings:i,canWrite:r,bound:g,savingKey:f}=e,m=!r,u=We(i.maintenance,"autoUpdate"),y=!r||i.localDevInstall||!i.autoUpdateSupported,S=!r||i.maintenance.autoUpdate?.enabled!==!0,h=(c,v)=>{e.onSave(c,{[c]:v},k=>({...k,[c]:v}))},b=c=>e.onSave("herdrTraexPlugin",{herdrTraexPlugin:c},v=>({...v,herdrTraexPlugin:{...v.herdrTraexPlugin,...c}})),C=c=>e.onSave("codexNotifier",{codexNotifier:c},v=>({...v,codexNotifier:{...v.codexNotifier,...c}})),$=c=>e.onSave("hostOverloadAlert",{hostOverloadAlert:c},v=>({...v,hostOverloadAlert:{...v.hostOverloadAlert,...c}})),V=(0,p.useMemo)(()=>[{value:"all",label:t("settings.repoPickerModeAll")},{value:"repos",label:t("settings.repoPickerModeRepos")}],[t]),R=(0,p.useMemo)(()=>[{value:"attach",label:t("settings.localCliOpenModeAttach")},{value:"resume",label:t("settings.localCliOpenModeResume")}],[t]),W=(0,p.useMemo)(()=>[{value:"",label:t("settings.vcMeetingListenerBotAuto")},...i.vcMeetingAgent.listenerBotOptions.map(c=>{let v=c.botName||c.larkAppId,k=c.cliId?` \xB7 ${c.cliId}`:"",x=[c.vcMeetingAgentEnabled===!0?void 0:t("settings.vcMeetingListenerBotDisabled"),c.hasLarkCliProfile===!0?void 0:t("settings.vcMeetingListenerBotNoProfile")].filter(Boolean),ee=x.length>0?` \xB7 ${x.join(" \xB7 ")}`:"";return{value:c.larkAppId,label:`${v}${k}${ee}`}})],[i.vcMeetingAgent.listenerBotOptions,t]);return(0,n.jsxs)("div",{className:"settings-layout",children:[r?null:(0,n.jsx)("article",{className:"bd-card settings-card settings-alert-card",children:(0,n.jsx)("p",{className:"hint-warn",children:t("settings.readOnlyVisitor")})}),(0,n.jsx)(Ce,{title:t("settings.moduleGeneral"),description:t("settings.moduleGeneralHelp"),children:(0,n.jsxs)(ke,{className:"settings-group-main",children:[(0,n.jsxs)(_,{title:t("settings.sectionAccess"),children:[(0,n.jsx)(M,{title:t("settings.publicReadOnly"),help:t("settings.publicReadOnlyHelp"),checked:i.publicReadOnly,disabled:m||f==="publicReadOnly",onChange:c=>h("publicReadOnly",c)}),g?(0,n.jsx)(M,{title:t("settings.remoteAccess"),help:t("settings.remoteAccessHelp"),checked:i.remoteAccess,disabled:m||f==="remoteAccess",onChange:c=>h("remoteAccess",c)}):null]}),(0,n.jsxs)(_,{title:t("settings.sectionCards"),children:[(0,n.jsx)(M,{title:t("settings.openTerminalInFeishu"),help:t("settings.openTerminalInFeishuHelp"),checked:i.openTerminalInFeishu,disabled:m||f==="openTerminalInFeishu",onChange:c=>h("openTerminalInFeishu",c)}),(0,n.jsx)(M,{title:t("settings.enableLocalCliOpen"),help:t("settings.enableLocalCliOpenHelp"),checked:i.enableLocalCliOpen,disabled:m||f==="enableLocalCliOpen",onChange:c=>h("enableLocalCliOpen",c)}),(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.localCliOpenModeHelp"),children:t("settings.localCliOpenMode")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.localCliOpenMode"),disabled:m||!i.enableLocalCliOpen||f==="localCliOpenMode",value:i.localCliOpenMode,label:H(R,i.localCliOpenMode),options:R,onChange:c=>{e.onSave("localCliOpenMode",{localCliOpenMode:c},v=>({...v,localCliOpenMode:c}))}})]})]}),(0,n.jsx)(_,{title:t("settings.sectionGroupCreation"),children:(0,n.jsx)(Je,{value:i.groupNamePrefix,disabled:m||f==="groupNamePrefix",onSave:c=>e.onSave("groupNamePrefix",{groupNamePrefix:c},v=>({...v,groupNamePrefix:c}))})}),(0,n.jsxs)(_,{title:t("settings.sectionExperimental"),children:[(0,n.jsx)(M,{title:t("settings.chatBotDiscovery"),help:t("settings.chatBotDiscoveryHelp"),checked:i.chatBotDiscovery,disabled:m||f==="chatBotDiscovery",onChange:c=>h("chatBotDiscovery",c)}),(0,n.jsx)(M,{title:t("settings.herdrTraexPlugin"),help:t("settings.herdrTraexPluginHelp"),checked:i.herdrTraexPlugin.enabled,disabled:m||f==="herdrTraexPlugin",onChange:c=>b({enabled:c})}),i.herdrTraexPlugin.enabled?(0,n.jsx)(Xe,{value:i.herdrTraexPlugin,disabled:m||f==="herdrTraexPlugin",onSave:c=>b(c)}):null,(0,n.jsx)(M,{title:t("settings.codexRpcInput"),help:t("settings.codexRpcInputHelp"),checked:i.codexRpcInput,disabled:m||f==="codexRpcInput",onChange:c=>h("codexRpcInput",c)}),(0,n.jsx)(M,{title:t("settings.bypassCodexHookTrust"),help:t("settings.bypassCodexHookTrustHelp"),checked:i.bypassCodexHookTrust,disabled:m||f==="bypassCodexHookTrust",onChange:c=>h("bypassCodexHookTrust",c)}),(0,n.jsx)(ze,{value:i.codexNotifier,disabled:m,saving:f==="codexNotifier",onSave:C}),(0,n.jsx)(M,{title:t("settings.noVisibleOutputHint"),help:t("settings.noVisibleOutputHintHelp"),checked:i.noVisibleOutputHint,disabled:m||f==="noVisibleOutputHint",onChange:c=>h("noVisibleOutputHint",c)})]}),(0,n.jsx)(_,{title:t("settings.sectionHostOverloadAlert"),children:(0,n.jsx)(qe,{value:i.hostOverloadAlert,disabled:m,saving:f==="hostOverloadAlert",onSave:$})}),(0,n.jsx)(_,{title:t("settings.sectionWhiteboard"),children:(0,n.jsx)(M,{title:t("settings.whiteboardEnable"),help:t("settings.whiteboardEnableHelp"),checked:i.whiteboard.enabled,disabled:m||f==="whiteboard",onChange:c=>{e.onSave("whiteboard",{whiteboard:{enabled:c}},v=>({...v,whiteboard:{enabled:c}}))}})}),(0,n.jsx)(_,{title:t("settings.sectionRepoPicker"),children:(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.repoPickerModeHelp"),children:t("settings.repoPickerMode")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.repoPickerMode"),disabled:m||f==="repoPickerMode",value:i.repoPickerMode,label:H(V,i.repoPickerMode),options:V,onChange:c=>{e.onSave("repoPickerMode",{repoPickerMode:c},v=>({...v,repoPickerMode:c}))}})]})}),(0,n.jsx)(_,{title:t("settings.sectionSchedule"),children:(0,n.jsx)(Ge,{value:i.scheduleTimeZone,host:i.hostTimeZone,effective:i.effectiveScheduleTimeZone,disabled:m||f==="scheduleTimeZone",onSave:c=>{e.onSave("scheduleTimeZone",{scheduleTimeZone:c},v=>({...v,scheduleTimeZone:c??""}))}})})]})}),(0,n.jsx)(Ce,{className:"settings-module-meeting",title:t("settings.moduleMeeting"),description:t("settings.moduleMeetingHelp"),children:(0,n.jsx)(ke,{className:"settings-group-meeting",children:(0,n.jsxs)(_,{className:"settings-vc-block",title:t("settings.sectionVcMeetingAgent"),children:[(0,n.jsx)(M,{title:t("settings.vcMeetingAgent"),help:t("settings.vcMeetingAgentHelp"),checked:i.vcMeetingAgent.enabled,disabled:m||f==="vcMeetingAgent",onChange:c=>{e.onSave("vcMeetingAgent",{vcMeetingAgent:{enabled:c}},v=>({...v,vcMeetingAgent:{...v.vcMeetingAgent,enabled:c}}))}}),(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.vcMeetingListenerBotHelp"),children:t("settings.vcMeetingListenerBot")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.vcMeetingListenerBot"),disabled:m||f==="vcMeetingAgent",value:i.vcMeetingAgent.listenerBotAppId??"",label:H(W,i.vcMeetingAgent.listenerBotAppId??""),options:W,onChange:c=>{let v=c||null;e.onSave("vcMeetingAgent",{vcMeetingAgent:{listenerBotAppId:v}},k=>({...k,vcMeetingAgent:{...k.vcMeetingAgent,listenerBotAppId:v}}))}})]}),(0,n.jsx)(je,{settings:i.vcMeetingAgent}),(0,n.jsx)(Be,{enabled:i.vcMeetingAgent.enabled,canWrite:r,listenerBotAppId:i.vcMeetingAgent.listenerBotAppId,listenerBotOptions:i.vcMeetingAgent.listenerBotOptions}),e.feishuLoginQr?(0,n.jsxs)("div",{className:"settings-feishu-login",children:[(0,n.jsx)("button",{type:"button",className:"settings-feishu-login-close","aria-label":t("settings.feishuLoginClose"),title:t("settings.feishuLoginClose"),onClick:e.onCloseFeishuLoginQr}),(0,n.jsx)("p",{children:t("settings.feishuLoginRequired")}),(0,n.jsx)("img",{src:e.feishuLoginQr,alt:t("settings.feishuLoginQrAlt")})]}):null]})})}),(0,n.jsx)(Ce,{title:t("settings.moduleSystem"),description:t("settings.moduleSystemHelp"),children:(0,n.jsxs)(ke,{className:"settings-group-ops",children:[(0,n.jsx)(_,{title:t("settings.sectionMaintenance"),titleExtra:i.localDevInstall?(0,n.jsx)("span",{className:"settings-title-note",children:t("settings.autoUpdateLocalDev")}):i.autoUpdateSupported?null:(0,n.jsx)("span",{className:"settings-title-note",children:t("settings.autoUpdateUnsupportedInstall")}),children:(0,n.jsxs)("div",{className:"settings-maintenance-grid",children:[(0,n.jsxs)("div",{className:"settings-maintenance-update",children:[(0,n.jsx)(M,{title:t("settings.autoUpdate"),help:t("settings.autoUpdateHelp"),checked:u.enabled,disabled:y||f==="autoUpdate",onChange:c=>{let v={enabled:c,time:u.time};e.onSave("autoUpdate",{maintenance:{autoUpdate:v}},k=>({...k,maintenance:{...k.maintenance,autoUpdate:v}}))}}),(0,n.jsx)("div",{className:"maint-time",children:(0,n.jsxs)("label",{children:[(0,n.jsx)("span",{children:t("settings.maintenanceTime")}),(0,n.jsx)("input",{type:"time",value:u.time,disabled:y||f==="autoUpdate",onChange:c=>{let v={enabled:u.enabled,time:c.currentTarget.value||"04:00"};e.onSave("autoUpdate",{maintenance:{autoUpdate:v}},k=>({...k,maintenance:{...k.maintenance,autoUpdate:v}}))}})]})})]}),(0,n.jsx)("div",{className:"settings-maintenance-restart",children:(0,n.jsx)(M,{title:t("settings.autoRestart"),help:t("settings.autoRestartHelp"),checked:i.maintenance.autoRestart?.enabled===!0,disabled:S||f==="autoRestart",onChange:c=>{let v={enabled:c};e.onSave("autoRestart",{maintenance:{autoRestart:v}},k=>({...k,maintenance:{...k.maintenance,autoRestart:v}}))}})})]})}),e.updateBlock]})}),(0,n.jsx)("div",{className:"settings-status-row",children:(0,n.jsx)("span",{className:`oncall-status ${e.message?.cls??""}`,"data-settings-status":!0,children:e.message?.text??""})})]})}function Ce(e){let t=["settings-module",e.className].filter(Boolean).join(" ");return(0,n.jsxs)("section",{className:t,children:[(0,n.jsxs)("header",{className:"settings-module-heading",children:[(0,n.jsx)("h2",{children:e.title}),(0,n.jsx)("p",{children:e.description})]}),e.children]})}function je(e){let t=A(),i=e.settings.larkCliVersion,r=typeof i=="string"&&e.settings.larkCliMeetsRequirement===!0,g=r?t("settings.larkCliReady",{version:i}):typeof i=="string"?t("settings.larkCliOutdated",{version:i,minimum:e.settings.larkCliMinVersion??"-"}):t("settings.larkCliMissing");return(0,n.jsxs)("div",{className:`settings-lark-cli-status ${r?"is-ready":"is-warning"}`,children:[(0,n.jsx)("span",{"aria-hidden":"true"}),(0,n.jsx)("strong",{children:g}),r?null:(0,n.jsx)("code",{children:"npm i -g @larksuite/cli@latest"})]})}function ke(e){let t=["settings-group",e.className].filter(Boolean).join(" ");return(0,n.jsx)("section",{className:t,children:(0,n.jsx)("article",{className:"bd-card settings-group-card",children:e.children})})}function _(e){let t=["settings-block",e.className].filter(Boolean).join(" ");return(0,n.jsx)("section",{className:t,children:(0,n.jsxs)("article",{className:"bd-card settings-card",children:[(0,n.jsxs)("div",{className:"settings-block-title-row",children:[(0,n.jsx)("h2",{className:"bd-section-title",children:e.title}),e.titleExtra?(0,n.jsx)("div",{className:"settings-block-title-extra",children:e.titleExtra}):null]}),e.children]})})}function ze(e){let t=A(),[i,r]=(0,p.useState)(!1),g=(0,p.useRef)(!1),f=(0,p.useMemo)(()=>[{value:"",label:t("settings.codexNotifierTargetPlaceholder")},...e.value.botOptions.map(C=>({value:C.larkAppId,label:[C.botName||C.larkAppId,C.cliId].filter(Boolean).join(" \xB7 ")}))],[e.value.botOptions,t]),m=(0,p.useMemo)(()=>[{value:"locked_only",label:t("settings.codexNotifierLockedOnly")},{value:"always",label:t("settings.codexNotifierAlways")}],[t]),u=e.value.botOptions.find(C=>C.larkAppId===e.value.targetBotAppId),y=!e.value.targetBotAppId||u?.recipientConfigured!==!0||u?.recipientVerified!==!0||!e.value.targetDaemonOnline||!e.value.platformSupported&&e.value.notifyWhen==="locked_only",S=e.value.enabled||i,h=e.disabled||e.saving;(0,p.useEffect)(()=>{if(!i||e.value.enabled||y){g.current=!1;return}h||g.current||(g.current=!0,e.onSave({enabled:!0}))},[h,y,i,e.onSave,e.value.enabled]),(0,p.useEffect)(()=>{e.value.enabled&&i&&r(!1)},[i,e.value.enabled]);let b=C=>{if(!C){g.current=!1,r(!1),e.value.enabled&&e.onSave({enabled:!1});return}if(y){r(!0);return}e.onSave({enabled:!0})};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(M,{title:t("settings.codexNotifier"),help:t("settings.codexNotifierHelp"),checked:e.value.enabled||i,disabled:h,onChange:b}),S?(0,n.jsxs)("div",{className:"settings-codex-notifier-details",children:[e.value.enabled?null:(0,n.jsx)("p",{className:"settings-subfield-hint",children:t("settings.codexNotifierEnablePending")}),(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.codexNotifierTargetHelp"),children:t("settings.codexNotifierTarget")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.codexNotifierTarget"),disabled:h,searchable:!0,value:e.value.targetBotAppId??"",label:H(f,e.value.targetBotAppId??""),options:f,onChange:C=>{e.onSave({targetBotAppId:C||null})}})]}),u?.recipientHint?(0,n.jsx)("p",{className:"settings-subfield-hint",children:t("settings.codexNotifierRecipient",{recipient:u.recipientHint})}):null,(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.codexNotifierNotifyWhenHelp"),children:t("settings.codexNotifierNotifyWhen")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.codexNotifierNotifyWhen"),disabled:h,value:e.value.notifyWhen,label:H(m,e.value.notifyWhen),options:m,onChange:C=>{e.onSave({notifyWhen:C})}})]}),e.value.targetBotAppId?u?.recipientConfigured!==!0?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierRecipientMissing")}):e.value.targetDaemonOnline?u?.recipientVerified!==!0?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierRecipientUnverified")}):!e.value.platformSupported&&e.value.notifyWhen==="locked_only"?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierUnsupported")}):e.value.enabled?e.value.hookInstalled?e.value.workerOnline?e.value.lastError?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierLastError",{error:e.value.lastError.message})}):e.value.pendingCount>0?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierPending",{count:e.value.pendingCount})}):null:(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierWorkerPending")}):(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierHookPending")}):null:(0,n.jsx)("p",{className:"hint-warn-inline",children:t(e.value.enabled?"settings.codexNotifierDaemonOffline":"settings.codexNotifierTargetOffline")}):(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.codexNotifierTargetRequired")})]}):null]})}function qe(e){let t=A(),i=e.disabled||e.saving,r=(0,p.useMemo)(()=>[{value:"",label:t("settings.hostOverloadAlertTargetPlaceholder")},...e.value.botOptions.map(b=>({value:b.larkAppId,label:[b.botName||b.larkAppId,b.cliId].filter(Boolean).join(" \xB7 ")}))],[e.value.botOptions,t]),g=e.value.botOptions.find(b=>b.larkAppId===e.value.targetBotAppId),[f,m]=(0,p.useState)(String(e.value.enterLoadRatio)),[u,y]=(0,p.useState)(String(Math.round(e.value.enterMemUsedFrac*100)));(0,p.useEffect)(()=>{m(String(e.value.enterLoadRatio))},[e.value.enterLoadRatio]),(0,p.useEffect)(()=>{y(String(Math.round(e.value.enterMemUsedFrac*100)))},[e.value.enterMemUsedFrac]);let S=()=>{let b=Number(f);Number.isFinite(b)&&b>0&&b!==e.value.enterLoadRatio?e.onSave({enterLoadRatio:b}):m(String(e.value.enterLoadRatio))},h=()=>{let b=Number(u),C=b/100;Number.isFinite(b)&&b>0&&b<=100&&C!==e.value.enterMemUsedFrac?e.onSave({enterMemUsedFrac:C}):y(String(Math.round(e.value.enterMemUsedFrac*100)))};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(M,{title:t("settings.hostOverloadAlert"),help:t("settings.hostOverloadAlertHelp"),checked:e.value.enabled,disabled:i||!e.value.enabled&&!e.value.targetBotAppId,onChange:b=>{e.onSave({enabled:b})}}),(0,n.jsxs)("div",{className:"settings-codex-notifier-details",children:[(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.hostOverloadAlertTargetHelp"),children:t("settings.hostOverloadAlertTarget")}),(0,n.jsx)(O,{className:"settings-field-menu",ariaLabel:t("settings.hostOverloadAlertTarget"),disabled:i,searchable:!0,value:e.value.targetBotAppId??"",label:H(r,e.value.targetBotAppId??""),options:r,onChange:b=>{e.onSave({targetBotAppId:b||null})}})]}),g?.recipientHint?(0,n.jsx)("p",{className:"settings-subfield-hint",children:t("settings.hostOverloadAlertRecipient",{recipient:g.recipientHint})}):null,(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.hostOverloadAlertEnterLoadHelp"),children:t("settings.hostOverloadAlertEnterLoad")}),(0,n.jsx)("input",{type:"number",min:.1,step:.1,className:"settings-text-input",value:f,disabled:i,onChange:b=>m(b.currentTarget.value),onBlur:S,onKeyDown:b=>{b.key==="Enter"&&S()}})]}),(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.hostOverloadAlertEnterMemHelp"),children:t("settings.hostOverloadAlertEnterMem")}),(0,n.jsx)("input",{type:"number",min:1,max:100,step:1,className:"settings-text-input",value:u,disabled:i,onChange:b=>y(b.currentTarget.value),onBlur:h,onKeyDown:b=>{b.key==="Enter"&&h()}})]}),e.value.targetBotAppId?g?.recipientConfigured!==!0?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.hostOverloadAlertRecipientMissing")}):e.value.targetDaemonOnline?g?.recipientVerified!==!0?(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.hostOverloadAlertRecipientUnverified")}):null:(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.hostOverloadAlertTargetOffline")}):(0,n.jsx)("p",{className:"hint-warn-inline",children:t("settings.hostOverloadAlertTargetRequired")})]})]})}function Ge(e){let t=A(),i=e.value.trim(),r=e.effective||e.value.trim()||e.host,g=(0,p.useMemo)(()=>{let f=i&&!ye.includes(i)?[i,...ye]:ye;return[{value:"",label:t("settings.scheduleTimeZoneHost",{host:e.host})},...f.map(m=>({value:m,label:m}))]},[e.host,t,i]);return(0,n.jsxs)("div",{className:"settings-field-row settings-timezone-row",children:[(0,n.jsx)(T,{help:t("settings.scheduleTimeZoneHelp",{host:e.host,effective:r}),children:t("settings.scheduleTimeZone")}),(0,n.jsx)(O,{className:"settings-field-menu settings-timezone-menu",ariaLabel:t("settings.scheduleTimeZone"),value:i,label:H(g,i),options:g,disabled:e.disabled,onChange:f=>e.onSave(f===""?null:f)})]})}function M(e){return(0,n.jsxs)("label",{className:"toggle-row",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.checked,disabled:e.disabled,onChange:t=>e.onChange(t.currentTarget.checked)}),(0,n.jsx)("span",{className:"switch","aria-hidden":"true"}),(0,n.jsx)("span",{className:"toggle-tx",children:(0,n.jsx)("strong",{children:(0,n.jsx)(T,{className:"settings-toggle-title",help:e.help,children:e.title})})})]})}var Qe=32;function Je(e){let t=A(),[i,r]=(0,p.useState)(e.value);(0,p.useEffect)(()=>r(e.value),[e.value]);let g=i.trim().length>0,f=i===""||g,m=i!==e.value,u=()=>{e.disabled||!m||!f||e.onSave(i)};return(0,n.jsxs)("div",{className:"settings-subfield settings-group-prefix-editor",children:[(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.groupNamePrefixHelp"),children:t("settings.groupNamePrefix")}),(0,n.jsx)("input",{className:"settings-text-input",type:"text",value:i,maxLength:Qe,placeholder:t("settings.groupNamePrefixPlaceholder"),disabled:e.disabled,onChange:y=>r(y.currentTarget.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),u())}})]}),(0,n.jsx)("p",{className:"settings-subfield-hint","data-group-name-prefix-preview":!0,children:g?t("settings.groupNamePrefixPreview",{name:`${i}${t("settings.groupNamePrefixPreviewName")}`}):t("settings.groupNamePrefixDisabled")}),(0,n.jsx)("div",{className:"actions",children:(0,n.jsx)("button",{type:"button",className:"page-primary-action",disabled:e.disabled||!m||!f,onClick:u,children:t("settings.groupNamePrefixSave")})})]})}function Xe(e){let t=A(),[i,r]=(0,p.useState)(e.value.source),[g,f]=(0,p.useState)(e.value.ref);(0,p.useEffect)(()=>{r(e.value.source),f(e.value.ref)},[e.value.source,e.value.ref]);let m=i.trim(),u=g.trim(),y=m!==e.value.source.trim()||u!==e.value.ref.trim(),S=()=>{e.disabled||!y||e.onSave({source:m,ref:u})};return(0,n.jsxs)("div",{className:"settings-subfield",children:[(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.herdrTraexPluginSourceHelp"),children:t("settings.herdrTraexPluginSource")}),(0,n.jsx)("input",{className:"settings-text-input",type:"text",value:i,placeholder:t("settings.herdrTraexPluginSourcePlaceholder"),disabled:e.disabled,onChange:h=>r(h.currentTarget.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),S())}})]}),(0,n.jsxs)("div",{className:"settings-field-row",children:[(0,n.jsx)(T,{help:t("settings.herdrTraexPluginRefHelp"),children:t("settings.herdrTraexPluginRef")}),(0,n.jsx)("input",{className:"settings-text-input",type:"text",value:g,placeholder:t("settings.herdrTraexPluginRefPlaceholder"),disabled:e.disabled,onChange:h=>f(h.currentTarget.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),S())}})]}),m?null:(0,n.jsx)("p",{className:"hint-warn-inline settings-subfield-hint",children:t("settings.herdrTraexPluginSourceRequired")}),e.value.recommendedSource&&(m!==e.value.recommendedSource||u!==e.value.recommendedRef)?(0,n.jsxs)("p",{className:"settings-subfield-hint",children:[t("settings.herdrTraexPluginRecommended")," ",(0,n.jsxs)("button",{type:"button",className:"settings-inline-link",disabled:e.disabled,onClick:()=>{r(e.value.recommendedSource),f(e.value.recommendedRef)},children:[e.value.recommendedSource,e.value.recommendedRef?` @ ${e.value.recommendedRef}`:""]})]}):null,(0,n.jsx)("div",{className:"actions",children:(0,n.jsx)("button",{type:"button",className:"page-primary-action",disabled:e.disabled||!y,onClick:S,children:t("settings.herdrTraexPluginSave")})})]})}function Ye(e){let t=A(),i;if(!e.canWrite)i=(0,n.jsx)("p",{className:"hint-warn",children:t("update.loginRequired")});else if(e.statusError)i=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("p",{className:"hint-warn",children:[t("update.checkFailed"),": ",e.statusError]}),(0,n.jsx)("div",{className:"update-actions",children:(0,n.jsx)("button",{type:"button","data-up":"check",onClick:e.onCheck,children:t("update.btnCheck")})})]});else if(!e.status)i=(0,n.jsx)(ce,{label:t("update.loading"),compact:!0});else{let r=e.status,g=r.localDevInstall||!r.updateSupported||e.busy;i=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("p",{className:"update-version",children:[(0,n.jsxs)("span",{children:[t("update.current"),": ",(0,n.jsxs)("strong",{children:["v",r.current]})]})," ",(0,n.jsx)(tt,{status:r})]}),r.node.ok?null:(0,n.jsx)("p",{className:"hint-warn",children:t("update.nodeWarn",{version:r.node.version,required:r.node.required})}),!r.localDevInstall&&!r.updateSupported?(0,n.jsx)("p",{className:"hint-warn",children:t("update.unsupportedInstall")}):null,r.installs.multiple?(0,n.jsx)(nt,{entries:r.installs.entries}):null,(0,n.jsxs)("div",{className:"update-actions",children:[(0,n.jsx)("button",{type:"button","data-up":"check",disabled:e.busy,onClick:e.onCheck,children:t("update.btnCheck")}),(0,n.jsx)("button",{type:"button","data-up":"changelog",disabled:e.busy,onClick:e.onToggleChangelog,children:e.changelogOpen?t("update.btnChangelogHide"):t("update.btnChangelog")}),(0,n.jsx)("button",{type:"button",className:"page-primary-action","data-up":"update",disabled:g,onClick:e.onUpdate,children:t("update.btnUpdate")}),(0,n.jsx)("button",{type:"button","data-up":"restart",disabled:e.busy,onClick:e.onRestart,children:t("update.btnRestart")})]}),r.cliUpdates?.length?(0,n.jsx)(et,{entries:r.cliUpdates}):null,e.changelogOpen?(0,n.jsx)(it,{changelog:e.changelog,ok:e.changelogOk,rateLimited:e.changelogRateLimited,releasesUrl:e.releasesUrl}):null,e.message?(0,n.jsx)("p",{className:`oncall-status ${e.message.cls??""}`,children:e.message.text}):null]})}return(0,n.jsx)(_,{className:"settings-update-block",title:t("update.section"),titleExtra:e.status?.localDevInstall?(0,n.jsx)("span",{className:"settings-title-note",children:t("update.localDev")}):e.status&&!e.status.updateSupported?(0,n.jsx)("span",{className:"settings-title-note",children:t("update.unsupportedInstall")}):null,children:i})}function et(e){let t=A();return(0,n.jsxs)("div",{className:"cli-runtime-updates",children:[(0,n.jsx)("strong",{children:t("update.runtimeTitle")}),(0,n.jsx)("ul",{children:e.entries.map(i=>(0,n.jsxs)("li",{className:i.updateAvailable?"is-behind":"",children:[(0,n.jsxs)("div",{className:"cli-runtime-update-head",children:[(0,n.jsx)("span",{children:i.displayName}),i.updateAvailable&&i.latest?(0,n.jsx)("span",{className:"update-badge update-badge-new",children:t("update.runtimeAvailable",{current:i.current??"?",latest:i.latest})}):i.managed?i.latest?(0,n.jsx)("span",{className:"update-badge update-badge-ok",children:t("update.upToDate")}):(0,n.jsx)("span",{className:"hint-warn-inline",children:t("update.checkUnavailable")}):(0,n.jsx)("span",{className:"hint-warn-inline",children:t("update.runtimeUnmanaged")})]}),(0,n.jsx)("code",{children:i.binPath}),i.updateAvailable&&i.updateCommand?(0,n.jsxs)("small",{children:[t("update.runtimeCommand"),": ",(0,n.jsx)("code",{children:i.updateCommand})]}):null]},`${i.runtimeId}:${i.binPath}`))}),(0,n.jsx)("p",{className:"settings-help",children:t("update.runtimeHelp")})]})}function tt(e){let t=A(),i=e.status;return i.latest?i.behind?(0,n.jsx)("span",{className:"update-badge update-badge-new",children:t("update.newAvailable",{version:`v${i.latest}`})}):(0,n.jsx)("span",{className:"update-badge update-badge-ok",children:t("update.upToDate")}):(0,n.jsx)("span",{className:"hint-warn-inline",children:t("update.checkUnavailable")})}function nt(e){let t=A();return(0,n.jsxs)("div",{className:"hint-warn",children:[(0,n.jsx)("p",{children:t("update.multiInstallWarn")}),(0,n.jsx)("ul",{className:"update-install-list",children:e.entries.map(i=>(0,n.jsxs)("li",{children:[(0,n.jsx)("code",{children:i.binPath})," \u2192 ",De(i.kind,t)," ",(0,n.jsx)("small",{children:i.root})]},`${i.binPath}:${i.root}`))})]})}function it(e){let t=A();if(e.changelog===null)return(0,n.jsx)(ce,{label:t("update.changelogLoading"),compact:!0});if(!e.ok){let i=e.rateLimited?t("update.changelogRateLimited"):t("update.changelogFailed");return(0,n.jsxs)("p",{className:"hint-warn-inline",children:[i,e.releasesUrl?(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("a",{href:e.releasesUrl,target:"_blank",rel:"noopener",children:t("update.changelogViewOnGitHub")})]}):null]})}return e.changelog.length===0?(0,n.jsx)("p",{className:"empty",children:t("update.changelogEmpty")}):(0,n.jsx)("div",{className:"update-changelog",children:e.changelog.map(i=>{let r=i.name&&i.name!==`v${i.version}`?i.name:"",g=i.publishedAt?new Date(i.publishedAt).toLocaleDateString():"";return(0,n.jsxs)("details",{className:"update-release",open:!0,children:[(0,n.jsxs)("summary",{children:[(0,n.jsxs)("strong",{children:["v",i.version]})," ",r," ",(0,n.jsx)("small",{children:g})," ",(0,n.jsx)("a",{href:i.url,target:"_blank",rel:"noopener",children:"\u2197"})]}),(0,n.jsx)("pre",{className:"update-release-body",children:i.body||""})]},i.version)})})}function ft(e){return Oe(e,(0,n.jsx)(Ze,{}))}export{ze as CodexNotifierSettingsEditor,Je as GroupNamePrefixRow,qe as HostOverloadAlertSettingsEditor,Ge as TimeZoneRow,ft as renderSettingsPage};
@@ -0,0 +1,4 @@
1
+ import{c as Z}from"./chunk-5PAYQ3KT.js";import{b as Ye,c as vl,d as ue,h as bl,l as hl}from"./chunk-5CJMHTT4.js";import{z as Ve}from"./chunk-ELL53D62.js";import{a as fl}from"./chunk-SYC6D5XU.js";import{a as Ae,b as ds,d as de}from"./chunk-5THX4DI2.js";import{c as ee}from"./chunk-7SZRL6FY.js";var c=ee(Ae(),1),Bl=ee(ds(),1);var J=ee(Ae(),1);var k=ee(de(),1);function us(e){return(e.missingSkills?.length??0)>0?"missing":(e.references?.length??0)===0?"unassigned":"complete"}function yl(e){let l=Z(),n=e.packs??[],m=e.skills??[],[f,p]=(0,J.useState)(!1),[g,S]=(0,J.useState)(null),[o,D]=(0,J.useState)(null),[B,v]=(0,J.useState)(null),[C,w]=(0,J.useState)(!1),h=()=>{S(null),p(!0)},x=y=>{S(y),p(!0)},[E,T]=(0,J.useState)(()=>new Set),{focusPackId:L,focusPackIds:A,onFocusConsumed:$}=e;(0,J.useEffect)(()=>{if(!(!L&&(A?.length??0)===0)){if(L){let y=n.find(b=>b.id===L);y&&(S(y),p(!0)),T(new Set([L]))}else A&&T(new Set(A));$?.()}},[L,A]);let H=()=>{p(!1),S(null),D({text:l("skills.saved"),ok:!0}),e.onRefresh()},K=async y=>{try{let b=await fetch(`/api/skill-packs/${encodeURIComponent(y.id)}`,{method:"DELETE"}),I=await b.json().catch(()=>({}));if(b.ok){D({text:l("skills.packDeleted",{name:y.name}),ok:!0}),e.onRefresh();return}if(b.status===409&&I?.error==="SKILL_PACK_IN_USE"){let d=Array.isArray(I?.references)?I.references:y.references??[];v({pack:y,references:d});return}throw new Error(I?.error??`HTTP ${b.status}`)}catch(b){D({text:`${l("skills.failed")}: ${b?.message??b}`,ok:!1})}},F=async()=>{if(B){w(!0);try{let y=await fetch(`/api/skill-packs/${encodeURIComponent(B.pack.id)}?force=1`,{method:"DELETE"}),b=await y.json().catch(()=>({}));if(!y.ok)throw new Error(b?.error??`HTTP ${y.status}`);D({text:l("skills.packDeleted",{name:B.pack.name}),ok:!0}),v(null),e.onRefresh()}catch(y){D({text:`${l("skills.failed")}: ${y?.message??y}`,ok:!1})}finally{w(!1)}}};return(0,k.jsxs)("section",{className:"skills-config-block",children:[(0,k.jsx)(ue,{title:l("skills.packs"),count:e.packsKnown===!1?"\u2014":l("skills.packCount",{count:n.length}),hint:l("skills.packsHelp")}),o&&(0,k.jsx)("p",{className:`hint-${o.ok?"ok":"warn"}`,children:o.text}),(0,k.jsx)("div",{className:"bd-card skills-config-card",children:e.packsKnown===!1&&n.length===0?(0,k.jsxs)("div",{className:"skills-empty-state","data-packs-unknown":!0,children:[(0,k.jsx)("p",{className:"hint-warn",children:l("skills.packsUnknown")}),(0,k.jsx)("button",{className:"bd-button",onClick:()=>e.onRefresh(),children:l("skills.refresh")})]}):n.length===0?(0,k.jsxs)("div",{className:"skills-empty-state",children:[(0,k.jsx)("p",{children:l("skills.packsEmpty")}),(0,k.jsx)("button",{className:"bd-button primary",onClick:h,children:l("skills.packCreate")})]}):(0,k.jsxs)("div",{className:"skills-pack-grid",children:[(0,k.jsxs)("button",{className:"skills-pack-create-tile",onClick:h,children:[(0,k.jsx)("span",{className:"skills-pack-create-plus",children:"+"}),(0,k.jsx)("span",{children:l("skills.packCreate")})]}),n.map(y=>{let b=us(y);return(0,k.jsxs)("div",{className:`skills-pack-card${E.has(y.id)?" skills-pack-card-focus":""}`,children:[(0,k.jsxs)("div",{className:"skills-pack-card-head",children:[(0,k.jsxs)("div",{className:"skills-pack-title",children:[(0,k.jsx)("strong",{children:y.name}),(0,k.jsx)("code",{className:"skills-pack-id",children:y.id})]}),(0,k.jsx)("span",{className:`skills-pack-health skills-pack-health-${b}`,children:b==="complete"?"\u2713":b==="missing"?"!":"\u25CB"})]}),y.description&&(0,k.jsx)("p",{className:"skills-pack-desc",children:y.description}),(0,k.jsxs)("div",{className:"skills-pack-meta",children:[(0,k.jsx)("span",{className:"skills-pack-meta-item",children:l("skills.skillCount",{count:y.include.length})}),(0,k.jsx)("span",{className:"skills-pack-meta-item",children:l("skills.packRefCount",{count:y.references?.length??0})})]}),y.tags&&y.tags.length>0&&(0,k.jsx)("div",{className:"skills-pack-tags",children:y.tags.map(I=>(0,k.jsx)("span",{className:"skills-pack-tag",children:I},I))}),(y.references?.length??0)>0&&(0,k.jsx)("div",{className:"skills-pack-refs",children:y.references.map(I=>(0,k.jsx)("button",{type:"button",className:"skills-pack-ref-chip","data-action":"open-pack-bot",disabled:!e.onOpenBot,onClick:()=>e.onOpenBot?.(I.larkAppId),children:I.botName},I.larkAppId))}),(y.missingSkills?.length??0)>0&&(0,k.jsxs)("div",{className:"skills-pack-missing",children:[l("skills.packMissing"),":"," ",y.missingSkills.map(I=>(0,k.jsx)("button",{type:"button",className:"skills-missing-skill-chip","data-action":"install-missing-skill",title:l("skills.installMissingHint",{skill:I}),disabled:!e.onInstallMissingSkill,onClick:()=>e.onInstallMissingSkill?.(I),children:I},I))]}),(0,k.jsxs)("div",{className:"skills-pack-actions",children:[(0,k.jsx)("button",{className:"bd-button small",onClick:()=>x(y),children:l("skills.packEdit")}),(0,k.jsx)("button",{className:"bd-button small danger",onClick:()=>{K(y)},children:l("skills.remove")})]})]},y.id)})]})}),f&&(0,k.jsx)(ks,{pack:g,skills:m,onClose:()=>{p(!1),S(null)},onSaved:H}),B&&(0,k.jsx)("dialog",{className:"bd-dialog skills-pack-delete-confirm",open:!0,onClose:()=>!C&&v(null),children:(0,k.jsxs)("form",{method:"dialog",onSubmit:y=>{y.preventDefault(),F()},children:[(0,k.jsx)("h3",{children:l("skills.packDeleteConfirmTitle")}),(0,k.jsx)("p",{children:l("skills.packDeleteConfirmBody",{name:B.pack.name})}),B.references.length>0&&(0,k.jsxs)("div",{className:"skills-pack-delete-refs",children:[(0,k.jsx)("p",{children:(0,k.jsxs)("strong",{children:[l("skills.packDeleteAffectedBots"),":"]})}),(0,k.jsx)("ul",{children:B.references.map(y=>(0,k.jsx)("li",{children:y.botName},y.larkAppId))})]}),(0,k.jsx)("p",{className:"hint-warn",children:l("skills.packDeleteForceWarning")}),(0,k.jsxs)("div",{className:"skills-dialog-actions",children:[(0,k.jsx)("button",{type:"button",className:"bd-button",onClick:()=>v(null),disabled:C,children:l("skills.cancel")}),(0,k.jsx)("button",{type:"submit",className:"bd-button danger",disabled:C,children:l(C?"skills.removing":"skills.removeAnyway")})]})]})})]})}function ks(e){let l=Z(),n=e.skills??[],[m,f]=(0,J.useState)(e.pack?.id??""),[p,g]=(0,J.useState)(e.pack?.name??""),[S,o]=(0,J.useState)(e.pack?.description??""),[D,B]=(0,J.useState)((e.pack?.tags??[]).join(", ")),[v,C]=(0,J.useState)(()=>new Set(e.pack?.include.map(d=>d.replace("skill:",""))??[])),[w,h]=(0,J.useState)(!1),[x,E]=(0,J.useState)(null),[T,L]=(0,J.useState)(""),A=(0,J.useRef)(null),$=(0,J.useMemo)(()=>new Set(n.map(d=>d.name)),[n]),H=(0,J.useMemo)(()=>[...v].filter(d=>!$.has(d)).sort(),[$,v]);(0,J.useEffect)(()=>{let d=A.current;d&&!d.open&&d.showModal()},[]);let K=(0,J.useMemo)(()=>{let d=T.trim().toLowerCase();return d?n.filter(U=>`${U.name} ${U.description??""}`.toLowerCase().includes(d)):n},[n,T]),F=K.length>0&&K.every(d=>v.has(d.name)),y=d=>{C(U=>{let G=new Set(U);return G.has(d)?G.delete(d):G.add(d),G})},b=()=>{C(d=>{let U=new Set(d);if(F)for(let G of K)U.delete(G.name);else for(let G of K)U.add(G.name);return U})},I=async()=>{h(!0),E(null);try{let d={id:m,name:p,description:S||void 0,tags:D.split(",").map(r=>r.trim()).filter(Boolean),include:[...v].map(r=>`skill:${r}`),...e.pack?{expectedRevision:e.pack.revision}:{}},U=e.pack?`/api/skill-packs/${encodeURIComponent(e.pack.id)}`:"/api/skill-packs",G=await fetch(U,{method:e.pack?"PUT":"POST",headers:{"content-type":"application/json"},body:JSON.stringify(d)}),te=await G.json().catch(()=>({}));if(!G.ok)throw new Error(te?.error??te?.reason??`HTTP ${G.status}`);e.onSaved()}catch(d){E(d?.message??String(d))}finally{h(!1)}};return(0,k.jsx)("dialog",{className:"bd-dialog skills-pack-editor",ref:A,onClose:e.onClose,children:(0,k.jsxs)("form",{method:"dialog",onSubmit:d=>{d.preventDefault(),I()},children:[(0,k.jsx)("h3",{children:e.pack?l("skills.packEdit"):l("skills.packCreate")}),x&&(0,k.jsx)("p",{className:"hint-warn",children:x}),(0,k.jsxs)("div",{className:"skills-control-block",children:[(0,k.jsx)("label",{children:l("skills.packId")}),(0,k.jsx)("input",{value:m,onChange:d=>f(d.target.value),disabled:!!e.pack,placeholder:l("skills.packIdPlaceholder")})]}),(0,k.jsxs)("div",{className:"skills-control-block",children:[(0,k.jsx)("label",{children:l("skills.packName")}),(0,k.jsx)("input",{value:p,onChange:d=>g(d.target.value)})]}),(0,k.jsxs)("div",{className:"skills-control-block",children:[(0,k.jsx)("label",{children:l("skills.packDescription")}),(0,k.jsx)("textarea",{value:S,onChange:d=>o(d.target.value),rows:2})]}),(0,k.jsxs)("div",{className:"skills-control-block",children:[(0,k.jsx)("label",{children:l("skills.packTags")}),(0,k.jsx)("input",{value:D,onChange:d=>B(d.target.value),placeholder:l("skills.packTagsPlaceholder")})]}),(0,k.jsxs)("div",{className:"skills-control-block",children:[(0,k.jsxs)("div",{className:"skills-pack-include-head",children:[(0,k.jsxs)("label",{children:[l("skills.packInclude")," (",v.size,"/",n.length+H.length,")"]}),(0,k.jsx)("input",{className:"skills-pack-skill-search",type:"text",placeholder:l("skills.searchPlaceholder"),value:T,onChange:d=>L(d.target.value)})]}),K.length>0&&(0,k.jsxs)("label",{className:"skills-pack-select-all",children:[(0,k.jsx)("input",{type:"checkbox",checked:F,onChange:b}),l(F?"skills.deselectAll":"skills.selectAll")]}),H.length>0&&(0,k.jsxs)("div",{className:"skills-pack-missing-editor",children:[(0,k.jsx)("small",{className:"muted",children:l("skills.packMissing")}),H.map(d=>(0,k.jsxs)("label",{className:"skills-pack-skill-item skills-pack-skill-missing","data-missing-skill":d,children:[(0,k.jsx)("input",{type:"checkbox",checked:!0,onChange:()=>y(d)}),(0,k.jsx)("span",{className:"skills-pack-skill-name",children:d}),(0,k.jsx)("small",{className:"skills-pack-skill-desc",children:l("skills.packMissing")})]},d))]}),(0,k.jsxs)("div",{className:"skills-pack-skill-list",children:[K.map(d=>(0,k.jsxs)("label",{className:"skills-pack-skill-item",children:[(0,k.jsx)("input",{type:"checkbox",checked:v.has(d.name),onChange:()=>y(d.name)}),(0,k.jsx)("span",{className:"skills-pack-skill-name",children:d.name}),d.description&&(0,k.jsx)("small",{className:"skills-pack-skill-desc",children:d.description})]},d.name)),K.length===0&&(0,k.jsx)("p",{className:"muted",children:l("skills.noResults")})]})]}),(0,k.jsxs)("div",{className:"skills-dialog-actions",children:[(0,k.jsx)("button",{type:"button",className:"bd-button",onClick:e.onClose,children:l("skills.cancel")}),(0,k.jsx)("button",{type:"submit",className:"bd-button primary",disabled:w||v.size===0||!p.trim(),children:l(w?"skills.saving":"skills.saveSelection")})]})]})})}var oe=ee(Ae(),1);var Nl=new Set(["-y","--yes","-g","--global"]);function ms(e){let l=[],n="",m,f=!1;for(let p=0;p<e.length;p++){let g=e[p];if(m){if(g===m){m=void 0;continue}if(g==="\\"&&m==='"'){if(p+1>=e.length)return null;n+=e[++p];continue}n+=g;continue}if(/\s/.test(g)){f&&(l.push(n),n="",f=!1);continue}if(g==="'"||g==='"'){m=g,f=!0;continue}if(g==="\\"){if(p+1>=e.length)return null;n+=e[++p],f=!0;continue}n+=g,f=!0}return m?null:(f&&l.push(n),l)}function Sl(e){for(let l of e)if(!Nl.has(l))return l.startsWith("-")?null:l||null;return null}function wl(e){let l=ms(e);if(!l)return null;let n=l.findIndex(g=>g==="skills"||g==="add-skill"||g.startsWith("skills@"));if(n<0)return null;let m=l[n],f=l.slice(n+1);if(m==="add-skill")return Sl(f);let p=0;for(;Nl.has(f[p]);)p++;return f[p]!=="add"?null:Sl(f.slice(p+1))}var q=ee(de(),1);function Il(e){let[l,n]=(0,oe.useState)(null),m=(0,oe.useRef)(null),{navIntent:f,onNavIntentConsumed:p}=e;(0,oe.useEffect)(()=>{if(f){if(f.openInstallWizard){let S=m.current;S?.scrollIntoView?.({behavior:"smooth",block:"start"}),S?.querySelector('input[data-install="source"]')?.focus()}p?.()}},[f,p]);let g=S=>{!S||S.length===0||S.length>1&&n(S)};return(0,q.jsxs)("div",{className:"skills-page-stack",children:[(0,q.jsx)("div",{className:"skills-install-anchor",ref:m,children:(0,q.jsx)(e.InstallPanel,{installSource:e.installSource,installPath:e.installPath,installRef:e.installRef,installFullDepth:e.installFullDepth,installTargetSkill:e.installTargetSkill??null,installStatus:e.installStatus,installBusy:e.installBusy,installDiscovering:e.installDiscovering,installSelectionOpen:e.installSelectionOpen,installCandidates:e.installCandidates,selectedInstallSkills:e.selectedInstallSkills,onInstallSourceChange:e.onInstallSourceChange,onInstallPathChange:e.onInstallPathChange,onInstallRefChange:e.onInstallRefChange,onInstallFullDepthChange:e.onInstallFullDepthChange,onClearInstallTarget:e.onClearInstallTarget,onToggleInstallSkill:e.onToggleInstallSkill,onSelectAllInstallSkills:e.onSelectAllInstallSkills,onConfirmInstallSelection:()=>{e.onConfirmInstallSelection().then(g)},onCloseInstallSelection:e.onCloseInstallSelection,onInstall:()=>{e.onInstall().then(g)},onOpenNativeDiscovery:e.onOpenNativeDiscovery})}),l&&(0,q.jsx)(gs,{skillNames:l,onClose:()=>n(null),onCreate:async S=>{await e.onCreatePack(S),n(null)}}),(0,q.jsx)(e.InstalledLibrary,{skills:e.skills,busySkill:e.skillBusy,removingNames:e.removingNames,status:e.installedStatus,onUpdate:e.onUpdateSkill,onRequestRemove:e.onRequestRemove,externalQuery:e.navIntent?.librarySearch??null,externalFilterNames:e.navIntent?.libraryFilterSkills??null,packsKnown:e.packsKnown,onInstallMissing:e.onInstallMissing,graph:e.graph,packNames:e.packNames,onShowSkillPacks:e.onShowSkillPacks,onShowSkillBots:e.onShowSkillBots}),(0,q.jsx)(e.RemoveDialog,{names:e.removalDialogOpen?e.pendingRemoval:null,references:e.removalReferences,busy:e.removingNames.size>0,error:e.removalError,onCancel:e.onCancelRemoval,onConfirm:e.onConfirmRemoval})]})}function gs(e){let l=Z(),[n,m]=(0,oe.useState)(""),[f,p]=(0,oe.useState)(""),[g,S]=(0,oe.useState)(!1),[o,D]=(0,oe.useState)(null),B=(0,oe.useRef)(null);(0,oe.useEffect)(()=>{let C=B.current;if(C&&!C.open)try{C.showModal()}catch{}},[]);let v=async()=>{if(!(!n.trim()||!f.trim())){S(!0),D(null);try{await e.onCreate({id:n.trim(),name:f.trim(),skillNames:e.skillNames})}catch(C){D(C?.message??String(C))}finally{S(!1)}}};return(0,q.jsx)("dialog",{className:"bd-dialog skills-post-install-pack",ref:B,onClose:()=>!g&&e.onClose(),children:(0,q.jsxs)("form",{method:"dialog",onSubmit:C=>{C.preventDefault(),v()},children:[(0,q.jsx)("h3",{children:l("skills.postInstallPackTitle")}),(0,q.jsx)("p",{children:l("skills.postInstallPackHelp",{count:e.skillNames.length})}),(0,q.jsxs)("div",{className:"skills-control-block",children:[(0,q.jsx)("label",{children:l("skills.packId")}),(0,q.jsx)("input",{autoFocus:!0,required:!0,value:n,onChange:C=>m(C.target.value)})]}),(0,q.jsxs)("div",{className:"skills-control-block",children:[(0,q.jsx)("label",{children:l("skills.packName")}),(0,q.jsx)("input",{required:!0,value:f,onChange:C=>p(C.target.value)})]}),(0,q.jsxs)("div",{className:"skills-resolved-preview",children:[(0,q.jsx)("strong",{children:l("skills.postInstallPackSkills")}),(0,q.jsx)("ul",{children:e.skillNames.map(C=>(0,q.jsx)("li",{children:(0,q.jsx)("code",{children:C})},C))})]}),o&&(0,q.jsx)("p",{className:"hint-warn",children:o}),(0,q.jsxs)("div",{className:"skills-dialog-actions",children:[(0,q.jsx)("button",{type:"button",className:"bd-button",disabled:g,onClick:e.onClose,children:l("skills.postInstallPackSkip")}),(0,q.jsx)("button",{type:"submit",className:"bd-button primary",disabled:g||!n.trim()||!f.trim(),children:l(g?"skills.saving":"skills.postInstallPackCreate")})]})]})})}function el(e){let l=e.trim(),n=l.toLowerCase();if(!l)return"unknown";if(/^agentbuddy:/i.test(l)||/(?:^|\s)(?:npx\s+)?agentbuddy(?:@[\w.-]+)?\s+(?:skill|plugin)\s/i.test(l))return"agentbuddy";let m=wl(l);return m?el(m):n.startsWith("github:")?"github":n.startsWith("git+")||n.startsWith("git@")||n.startsWith("git://")?"git":n.includes("github.com")?"github":n.startsWith("http://")||n.startsWith("https://")||n.endsWith(".git")?"git":/^[/~.]/.test(l)?"local":/^[A-Za-z0-9][A-Za-z0-9-]*\/[A-Za-z0-9._-]+(?:\/[\w./-]+)?$/.test(l)?"github":l.includes("://")?"unknown":"local"}var Q=ee(Ae(),1);function ps(e,l){let n=String(e??"").replace(/\\/g,"/");return n.includes("/.codex/skills/")?l("skills.sourceCodex"):n.includes("/.claude/skills/")?l("skills.sourceClaude"):n.includes("/.trae/skills/")?l("skills.sourceTrae"):n.includes("/.cursor/skills/")?l("skills.sourceCursor"):n.includes("/.gemini/skills/")?l("skills.sourceGemini"):n.includes("/.config/opencode/skills/")?l("skills.sourceOpenCode"):null}function ll(e,l){let n=e.source??{};return n.type==="github"?`github:${n.owner}/${n.repo}/${n.path??""}`:n.type==="git"?`${n.url??"git"}#${n.path??""}`:n.type==="local-link"?ps(n.path,l)??l("skills.sourceLocalLink"):n.type==="local-copy"?l("skills.sourceBotmuxCopy"):String(n.type??"unknown")}function ke(e){return(e?.include??[]).filter(l=>l.startsWith("skill:")).map(l=>l.slice(6))}function be(e){return(e?.include??[]).filter(l=>l.startsWith("pack:")).map(l=>l.slice(5))}function Cl(e,l,n){let m=(e?.include??[]).filter(g=>!g.startsWith("skill:")&&!g.startsWith("pack:")),f=[...new Set(l.map(g=>g.trim()).filter(Boolean))].map(g=>`skill:${g}`),p=[...new Set(n.map(g=>g.trim()).filter(Boolean))].map(g=>`pack:${g}`);return[...f,...p,...m]}function Pl(e){return(e?.include?.length??0)>0}function Be(e){return`${e.cliId}
2
+ ${e.rootDir}`}function Ge(e,l,n,m){let f=m?.packsKnown!==!1,p=new Set(e.map(v=>v.name)),g=new Map,S=v=>{let C=g.get(v);return C||(C={name:v,installed:p.has(v),packIds:[],directBotIds:[],viaPackBotIds:[]},g.set(v,C)),C};for(let v of p)S(v);let o=new Map,D=new Map;for(let v of l){D.set(v.id,v);let C=[],w=[];for(let h of v.include){if(!h.startsWith("skill:"))continue;let x=h.slice(6),E=S(x);E.packIds.includes(v.id)||E.packIds.push(v.id),(p.has(x)?C:w).push(x)}o.set(v.id,{id:v.id,resolved:C,missing:w,botIds:[]})}let B=new Map;for(let v of n){let C=v.skills?.include??[],w=new Map,h=new Set,x=[],E=!1;for(let L of C)if(L.startsWith("skill:")){let A=L.slice(6),$=S(A);$.directBotIds.includes(v.larkAppId)||$.directBotIds.push(v.larkAppId),p.has(A)?w.set(A,"direct"):h.add(A)}else if(L.startsWith("pack:")){let A=L.slice(5),$=D.get(A);if(!$){f?x.push(A):E=!0;continue}let H=o.get(A);H.botIds.includes(v.larkAppId)||H.botIds.push(v.larkAppId);for(let K of $.include){if(!K.startsWith("skill:"))continue;let F=K.slice(6),y=S(F);y.viaPackBotIds.includes(v.larkAppId)||y.viaPackBotIds.push(v.larkAppId),p.has(F)?w.has(F)||w.set(F,`pack:${A}`):h.add(F)}}let T=x.length>0?"pack_missing":h.size>0?"missing":E?"unknown":C.length===0?"default":"ok";B.set(v.larkAppId,{larkAppId:v.larkAppId,resolved:[...w.entries()].map(([L,A])=>({name:L,source:A})),missingSkills:[...h],missingPacks:x,finalCount:w.size,health:T})}return{skills:g,packs:o,bots:B}}function Rl(e){return[...e.skills.values()].filter(l=>!l.installed).map(l=>l.name).sort()}function sl(e,l){if(l){let n=e.some(m=>m.name===l);return{selected:n?new Set([l]):new Set,targetMissing:!n}}return{selected:new Set(e.map(n=>n.name)),targetMissing:!1}}var u=ee(de(),1);function Dl(e){let l=Z(),[n,m]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[g,S]=(0,Q.useState)(!1),[o,D]=(0,Q.useState)(null),[B,v]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(""),[h,x]=(0,Q.useState)(null),[E,T]=(0,Q.useState)(()=>new Set),[L,A]=(0,Q.useState)(null),{focusBotIds:$,focusSkill:H,onFocusConsumed:K}=e;(0,Q.useEffect)(()=>{($?.length??0)===0&&!H||($&&$.length>0&&T(new Set($)),H&&(A(H),w(H)),K?.())},[$,H]),(0,Q.useEffect)(()=>{if(!B)return;let r=setTimeout(()=>v(null),1600);return()=>clearTimeout(r)},[B]);let F=(0,Q.useMemo)(()=>Ge(e.skills,e.packs,e.bots,{packsKnown:e.packsKnown!==!1}),[e.skills,e.packs,e.bots,e.packsKnown]),y=(0,Q.useMemo)(()=>{let r=new Set;for(let a of e.skills)for(let M of a.tags??[])r.add(M);return[...r].sort()},[e.skills]),b=(0,Q.useMemo)(()=>{let r=C.trim().toLowerCase();return e.skills.filter(a=>h&&!(a.tags??[]).includes(h)?!1:r?`${a.name} ${a.description??""}`.toLowerCase().includes(r):!0)},[e.skills,C,h]),I=async r=>{if(!o||o.sourceBotId)return;p(null),D(null);let a=ke(r.skills),M=be(r.skills);if(o.type==="skill"){if(a.includes(o.id)){v({botId:r.larkAppId,itemLabel:o.id});return}e.onMutate?await e.onMutate(r.larkAppId,`skill:${o.id}`,!0):await e.onSave(r.larkAppId,[...a,o.id],M)}else{if(M.includes(o.id)){v({botId:r.larkAppId,itemLabel:e.packs.find(P=>P.id===o.id)?.name??o.id});return}e.onMutate?await e.onMutate(r.larkAppId,`pack:${o.id}`,!0):await e.onSave(r.larkAppId,a,[...M,o.id])}},d=async()=>{let r=o;if(!r?.sourceBotId)return;S(!1),p(null),D(null);let a=e.bots.find(_=>_.larkAppId===r.sourceBotId);if(!a)return;let M=ke(a.skills),P=be(a.skills);if(r.type==="skill"){if(!M.includes(r.id))return;e.onMutate?await e.onMutate(a.larkAppId,`skill:${r.id}`,!1):await e.onSave(a.larkAppId,M.filter(_=>_!==r.id),P)}else{if(!P.includes(r.id))return;e.onMutate?await e.onMutate(a.larkAppId,`pack:${r.id}`,!1):await e.onSave(a.larkAppId,M,P.filter(_=>_!==r.id))}},U=()=>{D(null),p(null),S(!1)},G=(r,a,M)=>{r.dataTransfer.effectAllowed=M,r.dataTransfer.setData("text/plain",a.id),v(null),D(a)},te=o?.sourceBotId?e.bots.find(r=>r.larkAppId===o.sourceBotId):null;return(0,u.jsxs)("section",{className:"skills-config-block",children:[(0,u.jsx)(ue,{title:l("skills.bots"),count:l("skills.botCount",{count:e.bots.length}),hint:l("skills.botsHelp")}),(0,u.jsxs)("div",{className:"skills-bot-assign-layout",children:[(0,u.jsxs)("div",{className:"skills-bot-palette",children:[(0,u.jsxs)("div",{className:"skills-bot-palette-hint",children:[(0,u.jsx)("span",{className:"skills-drag-icon",children:"\u2927"}),(0,u.jsx)("span",{children:l("skills.dragHint")})]}),o?.sourceBotId?(0,u.jsxs)("div",{className:`skills-unassign-dropzone${g?" is-active":""}`,"data-action":"unassign-dropzone","data-drag-over":g||void 0,role:"status","aria-live":"polite",onDragOver:r=>{r.preventDefault(),r.dataTransfer.dropEffect="move",S(!0)},onDragLeave:r=>{r.currentTarget.contains(r.relatedTarget)||S(!1)},onDrop:r=>{r.preventDefault(),d().catch(()=>{})},children:[(0,u.jsx)("span",{className:"skills-unassign-icon","aria-hidden":"true",children:"\u21A9"}),(0,u.jsxs)("span",{children:[(0,u.jsx)("strong",{children:l("skills.unassignDropTitle")}),(0,u.jsx)("small",{children:l("skills.unassignDropHint",{bot:te?.botName??o.sourceBotId})})]})]}):null,e.packs.length>0&&(0,u.jsxs)("div",{className:"skills-bot-palette-group",children:[(0,u.jsx)("span",{className:"skills-bot-palette-label",children:l("skills.packChips")}),(0,u.jsx)("div",{className:"skills-bot-palette-items",children:e.packs.map(r=>(0,u.jsx)("span",{className:"skills-draggable-chip skills-pack-chip",draggable:!0,"data-palette-drag-type":"pack","data-palette-drag-id":r.id,onDragStart:a=>G(a,{type:"pack",id:r.id},"copy"),onDragEnd:U,title:`${r.name} (${l("skills.skillCount",{count:r.include.length})})`,children:r.name},r.id))})]}),(0,u.jsxs)("div",{className:"skills-bot-palette-group",children:[(0,u.jsx)("span",{className:"skills-bot-palette-label",children:l("skills.individualSkills")}),(0,u.jsx)("input",{className:"skills-bot-palette-search",type:"text",placeholder:l("skills.searchPlaceholder"),value:C,onChange:r=>w(r.target.value)}),y.length>0&&(0,u.jsxs)("div",{className:"skills-bot-palette-tags",children:[(0,u.jsx)("button",{className:`skills-tag-filter${h===null?" active":""}`,onClick:()=>x(null),children:l("skills.all")}),y.map(r=>(0,u.jsx)("button",{className:`skills-tag-filter${h===r?" active":""}`,onClick:()=>x(h===r?null:r),children:r},r))]}),(0,u.jsxs)("div",{className:"skills-bot-palette-items",children:[b.map(r=>(0,u.jsx)("span",{className:"skills-draggable-chip skills-skill-chip",draggable:!0,"data-palette-drag-type":"skill","data-palette-drag-id":r.name,onDragStart:a=>G(a,{type:"skill",id:r.name},"copy"),onDragEnd:U,title:r.description??r.name,children:r.name},r.name)),b.length===0&&(0,u.jsx)("span",{className:"muted",children:l("skills.noResults")})]})]})]}),(0,u.jsx)("article",{className:"bd-card skills-config-card skills-bot-table-wrap",children:(0,u.jsx)("div",{className:"skills-bot-table",children:(0,u.jsxs)("table",{children:[(0,u.jsx)("thead",{children:(0,u.jsxs)("tr",{children:[(0,u.jsx)("th",{children:l("skills.bot")}),(0,u.jsx)("th",{children:l("skills.packChips")}),(0,u.jsx)("th",{children:l("skills.individualSkills")}),(0,u.jsx)("th",{children:l("skills.finalCount")}),(0,u.jsx)("th",{children:l("skills.health")}),(0,u.jsx)("th",{})]})}),(0,u.jsx)("tbody",{children:e.bots.map(r=>{let a=ke(r.skills),M=be(r.skills),P=F.bots.get(r.larkAppId),_=P?.finalCount??0,V=fs(P,l),he=f===r.larkAppId,fe=E.has(r.larkAppId)||L!=null&&(P?.resolved.some(W=>W.name===L)??!1),ye=B?.botId===r.larkAppId?B:null,le=e.statuses[r.larkAppId]??null,se=e.busyBotIds?.has(r.larkAppId)===!0;return(0,u.jsxs)("tr",{className:`skills-bot-row${he?" drag-over":""}${fe?" skills-bot-row-focus":""}${se?" is-busy":""}`,"aria-busy":se,onDragOver:W=>{se||!o||o.sourceBotId||(W.preventDefault(),W.dataTransfer.dropEffect="copy",p(r.larkAppId))},onDragLeave:W=>{W.currentTarget.contains(W.relatedTarget)||p(Y=>Y===r.larkAppId?null:Y)},onDrop:W=>{se||!o||o.sourceBotId||(W.preventDefault(),I(r).catch(()=>{}))},children:[(0,u.jsx)("td",{children:r.botName??r.larkAppId}),(0,u.jsx)("td",{children:(0,u.jsx)("div",{className:"skills-pack-chips",children:M.length===0?(0,u.jsx)("span",{className:"muted",children:"\u2014"}):M.map(W=>{let Y=e.packs.find(Se=>Se.id===W),we=!Y&&e.packsKnown===!1,xe=!Y&&!we;return(0,u.jsx)("span",{className:`skills-assigned-draggable${o?.sourceBotId===r.larkAppId&&o.type==="pack"&&o.id===W?" is-dragging":""}`,draggable:!se,"data-assigned-drag-type":"pack","data-assigned-drag-id":W,"data-assigned-bot":r.larkAppId,title:l("skills.dragToRemove"),onDragStart:Se=>{se||G(Se,{type:"pack",id:W,sourceBotId:r.larkAppId},"move")},onDragEnd:U,children:(0,u.jsx)("button",{type:"button",className:`skills-pack-chip${xe?" skills-chip-missing":""}${we?" skills-chip-unknown":""}`,"data-action":"open-bot-pack",title:we?l("skills.healthUnknown"):void 0,disabled:!Y||!e.onOpenPack,onClick:()=>e.onOpenPack?.(W),children:Y?.name??W})},W)})})}),(0,u.jsx)("td",{children:a.length===0?(0,u.jsx)("span",{className:"muted",children:"\u2014"}):(0,u.jsxs)("span",{className:"skills-skill-chips",children:[a.slice(0,3).map(W=>(0,u.jsx)("span",{className:`skills-assigned-draggable${o?.sourceBotId===r.larkAppId&&o.type==="skill"&&o.id===W?" is-dragging":""}`,draggable:!se,"data-assigned-drag-type":"skill","data-assigned-drag-id":W,"data-assigned-bot":r.larkAppId,title:l("skills.dragToRemove"),onDragStart:Y=>{se||G(Y,{type:"skill",id:W,sourceBotId:r.larkAppId},"move")},onDragEnd:U,children:(0,u.jsx)("button",{type:"button",className:"skills-skill-chip","data-action":"open-bot-skill",disabled:!e.onOpenSkill,onClick:()=>e.onOpenSkill?.(W),children:W})},W)),a.length>3&&(0,u.jsxs)("span",{className:"muted",children:["+",a.length-3]})]})}),(0,u.jsx)("td",{children:P?.health==="unknown"?(0,u.jsx)("span",{className:"muted",title:l("skills.healthUnknown"),children:"\u2014"}):_}),(0,u.jsx)("td",{children:(0,u.jsx)("span",{className:`skills-health skills-health-${V.level}`,children:V.label})}),(0,u.jsx)("td",{children:(0,u.jsxs)("div",{className:"skills-bot-row-actions",children:[ye?(0,u.jsx)("span",{className:"skills-duplicate-feedback",role:"status","aria-live":"polite",children:l("skills.alreadyAssigned",{item:ye.itemLabel})}):null,le?(0,u.jsx)("span",{className:`oncall-status ${le.ok?"hint-ok":"hint-warn-inline"}`,role:"status","aria-live":"polite",children:le.text}):se?(0,u.jsx)("span",{className:"oncall-status",role:"status","aria-live":"polite",children:l("skills.saving")}):null,(0,u.jsx)("button",{className:"bd-button",disabled:se,onClick:()=>m(r),children:l("skills.select")})]})})]},r.larkAppId)})})]})})})]}),n&&(0,u.jsx)(vs,{bot:n,skills:e.skills,packs:e.packs,status:e.statuses[n.larkAppId]??null,onClose:()=>m(null),onSave:(r,a)=>e.onSave(n.larkAppId,r,a)})]})}function fs(e,l){switch(e?.health){case"pack_missing":return{level:"error",label:l("skills.healthPackMissing")};case"missing":return{level:"warn",label:l("skills.healthMissing",{count:e.missingSkills.length})};case"unknown":return{level:"unknown",label:l("skills.healthUnknown")};case"default":case void 0:return{level:"ok",label:l("skills.healthDefault")};default:return{level:"ok",label:l("skills.healthOk")}}}function vs(e){let l=Z(),n=(0,Q.useMemo)(()=>ke(e.bot.skills),[e.bot.skills]),m=(0,Q.useMemo)(()=>be(e.bot.skills),[e.bot.skills]),[f,p]=(0,Q.useState)(()=>new Set(n)),[g,S]=(0,Q.useState)(()=>new Set(m)),[o,D]=(0,Q.useState)(!1),B=h=>{p(x=>{let E=new Set(x);return E.has(h)?E.delete(h):E.add(h),E})},v=h=>{S(x=>{let E=new Set(x);return E.has(h)?E.delete(h):E.add(h),E})},C=(0,Q.useMemo)(()=>{let h=new Map;for(let x of f)h.set(x,"direct");for(let x of g){let E=e.packs.find(T=>T.id===x);if(E)for(let T of E.include){let L=T.replace("skill:","");h.has(L)||h.set(L,`pack:${E.name}`)}}return[...h.entries()].map(([x,E])=>({name:x,source:E}))},[f,g,e.packs]),w=async()=>{D(!0);try{await e.onSave([...f],[...g]),e.onClose()}finally{D(!1)}};return(0,u.jsx)("dialog",{className:"bd-dialog skills-bot-editor",open:!0,onClose:e.onClose,children:(0,u.jsxs)("form",{method:"dialog","data-action":"save-bot-assignment",onSubmit:h=>{h.preventDefault(),w().catch(()=>{})},children:[(0,u.jsxs)("h3",{children:[l("skills.botEdit"),": ",e.bot.botName??e.bot.larkAppId]}),e.status&&(0,u.jsx)("p",{className:`hint-${e.status.ok?"ok":"warn"}`,children:e.status.text}),(0,u.jsxs)("div",{className:"skills-control-block",children:[(0,u.jsx)("label",{children:l("skills.packChips")}),(0,u.jsxs)("div",{className:"skills-pack-skill-list",children:[e.packs.map(h=>(0,u.jsxs)("label",{className:"skills-pack-skill-item",children:[(0,u.jsx)("input",{type:"checkbox",checked:g.has(h.id),onChange:()=>v(h.id)}),(0,u.jsx)("span",{children:h.name}),(0,u.jsx)("small",{children:l("skills.skillCount",{count:h.include.length})})]},h.id)),e.packs.length===0&&(0,u.jsx)("small",{className:"muted",children:l("skills.packsEmpty")})]})]}),(0,u.jsxs)("div",{className:"skills-control-block",children:[(0,u.jsxs)("label",{children:[l("skills.individualSkills")," (",l("skills.advanced"),")"]}),(0,u.jsx)("div",{className:"skills-pack-skill-list",children:e.skills.map(h=>(0,u.jsxs)("label",{className:"skills-pack-skill-item",children:[(0,u.jsx)("input",{type:"checkbox",checked:f.has(h.name),onChange:()=>B(h.name)}),(0,u.jsx)("span",{children:h.name})]},h.name))})]}),(0,u.jsxs)("div",{className:"skills-control-block",children:[(0,u.jsxs)("label",{children:[l("skills.resolvedPreview")," (",C.length,")"]}),(0,u.jsx)("div",{className:"skills-resolved-preview",children:C.map(({name:h,source:x})=>(0,u.jsxs)("div",{className:"skills-resolved-item",children:[(0,u.jsx)("span",{children:h}),(0,u.jsx)("small",{className:"muted",children:x})]},h))})]}),(0,u.jsxs)("div",{className:"skills-dialog-actions",children:[(0,u.jsx)("button",{type:"button",className:"bd-button",onClick:e.onClose,children:l("skills.cancel")}),(0,u.jsx)("button",{type:"submit",className:"bd-button primary",disabled:o,children:l(o?"skills.saving":"skills.saveSelection")})]})]})})}var O=ee(de(),1);function Tl(e){let l=Z(),{SkillSegmented:n}=e;return(0,O.jsxs)("div",{className:"skills-page-stack",children:[(0,O.jsxs)("section",{className:"skills-config-block",children:[(0,O.jsx)(ue,{title:l("skills.globalDefaults")}),(0,O.jsxs)("article",{className:"bd-card skills-defaults-panel skills-config-card",children:[(0,O.jsxs)("div",{className:"skills-control-block",children:[(0,O.jsx)("span",{className:"skills-control-label",children:l("skills.globalProject")}),(0,O.jsx)(n,{value:e.trustProjectSkills,disabled:e.globalBusy==="project",options:[{value:"off",label:l("skills.globalProjectOff"),help:l("skills.globalProjectOffHelp")},{value:"all",label:l("skills.globalProjectAll"),help:l("skills.globalProjectAllHelp")}],onChange:m=>e.onUpdateProject(m)})]}),(0,O.jsxs)("div",{className:"skills-control-block",children:[(0,O.jsxs)("span",{className:"skills-control-label",children:[l("skills.globalDelivery"),(0,O.jsx)("small",{className:"skills-scope-note",children:l("skills.scopeGlobal")})]}),(0,O.jsx)(n,{value:e.delivery,disabled:e.globalBusy==="delivery",options:[{value:"auto",label:l("skills.deliveryAuto"),help:l("skills.deliveryAutoHelp")},{value:"prompt",label:l("skills.deliveryPrompt"),help:l("skills.deliveryPromptHelp")},{value:"native",label:l("skills.deliveryNative"),help:l("skills.deliveryNativeHelp")}],onChange:m=>e.onUpdateDelivery(m)})]})]})]}),(0,O.jsxs)("section",{className:"skills-config-block",children:[(0,O.jsx)(ue,{title:l("skills.botInjection"),hint:l("skills.botInjectionHelp")}),(0,O.jsxs)("article",{className:"bd-card skills-config-card",children:[(0,O.jsx)("p",{className:"skills-injection-note",children:l("skills.botInjectionNote")}),(0,O.jsx)("div",{className:"skills-bot-injection-table",children:(0,O.jsxs)("table",{children:[(0,O.jsx)("thead",{children:(0,O.jsxs)("tr",{children:[(0,O.jsx)("th",{children:l("skills.bot")}),(0,O.jsx)("th",{children:l("skills.cli")}),(0,O.jsx)("th",{children:l("skills.injection")}),(0,O.jsx)("th",{children:l("skills.status")})]})}),(0,O.jsx)("tbody",{children:e.bots.map(m=>(0,O.jsxs)("tr",{children:[(0,O.jsx)("td",{children:m.botName??m.larkAppId}),(0,O.jsx)("td",{children:(0,O.jsx)("code",{children:m.cliId??""})}),(0,O.jsx)("td",{children:(0,O.jsx)(n,{value:m.skillInjection??m.skillInjectionDefault??"prompt",options:[{value:"global",label:l("skills.injectionGlobal"),help:l("skills.injectionGlobalHelp")},{value:"prompt",label:l("skills.injectionPrompt"),help:l("skills.injectionPromptHelp")},{value:"off",label:l("skills.injectionOff"),help:l("skills.injectionOffHelp")}],onChange:f=>e.onUpdateBotInjection(m.larkAppId,f)})}),(0,O.jsx)("td",{children:e.botStatuses[m.larkAppId]?(0,O.jsx)("span",{className:`hint-${e.botStatuses[m.larkAppId].ok?"ok":"warn"}`,children:e.botStatuses[m.larkAppId].text}):null})]},m.larkAppId))})]})})]})]})]})}var X=ee(Ae(),1);function Al(e){let l=(0,X.useRef)(!0),[n,m]=(0,X.useState)([]),[f,p]=(0,X.useState)([]),[g,S]=(0,X.useState)([]),[o,D]=(0,X.useState)([]),[B,v]=(0,X.useState)("off"),[C,w]=(0,X.useState)("auto"),[h,x]=(0,X.useState)(!0),[E,T]=(0,X.useState)(null),[L,A]=(0,X.useState)(null),[$,H]=(0,X.useState)(!1),K=(0,X.useRef)(e.apiUnavailableText);K.current=e.apiUnavailableText;let F=(0,X.useCallback)(async()=>{x(!0);try{let[y,b,I]=await Promise.all([fetch("/api/skills"),fetch("/api/bots"),fetch("/api/skill-packs").catch(()=>null)]),d=await y.json().catch(()=>({})),U=await b.json().catch(()=>({})),G=I?await I.json().catch(()=>({})):{};if(!y.ok){let te=d?.error??`skills HTTP ${y.status}`;throw new Error(te==="not_found_yet"||te==="not_found"?K.current:te)}if(!b.ok)throw new Error(U?.error??`bots HTTP ${b.status}`);if(!l.current)return;m(Array.isArray(d.skills)?d.skills:[]),p(Array.isArray(d.nativeSkillGroups)?d.nativeSkillGroups:[]),S(Array.isArray(U.bots)?U.bots:[]),I?.ok&&Array.isArray(G.packs)?(D(G.packs),A(null),H(!0)):I?.status===404?(D([]),A(null),H(!0)):A(I?G?.error??`HTTP ${I.status}`:"network_error"),v(d.trustProjectSkills==="all"?"all":"off"),w(d.delivery==="prompt"||d.delivery==="native"?d.delivery:"auto"),T(null)}catch(y){l.current&&T(y?.message??String(y))}finally{l.current&&x(!1)}},[]);return(0,X.useEffect)(()=>(l.current=!0,F(),()=>{l.current=!1}),[F]),{skills:n,nativeSkillGroups:f,bots:g,packs:o,trustProjectSkills:B,delivery:C,loading:h,loadError:E,packsError:L,packsKnown:$,refresh:F,setSkills:m,setBots:S,setTrustProjectSkills:v,setDelivery:w}}var s=ee(de(),1),bs=2;function hs(e){return e>=1600?4:e<=620?1:e<=980?2:3}async function re(e,l){let n=await fetch(e,{...l,headers:{"content-type":"application/json",...l.headers??{}}}),m=await n.json().catch(()=>({}));if(!n.ok||m.ok===!1){let f=new Error(m?.error??`HTTP ${n.status}`);throw f.status=n.status,f.body=m,f}return m}function tl(e){return`oncall-status${e?` ${e.ok?"hint-ok":"hint-warn-inline"}`:""}`}function ys(e){let l=e.options.find(n=>n.value===e.value);return(0,s.jsxs)("div",{className:"skills-segmented-control",children:[(0,s.jsx)("div",{className:"segmented skills-segmented",role:"group",children:e.options.map(n=>(0,s.jsx)("button",{type:"button",className:e.value===n.value?"active":"","aria-pressed":e.value===n.value?"true":"false",title:typeof n.help=="string"?n.help:void 0,disabled:e.disabled,onClick:()=>e.onChange(n.value),children:n.label},n.value))}),l?.help?(0,s.jsx)("span",{className:"skills-setting-hint",children:l.help}):null]})}function Ss(e){let l=Z(),n=(0,c.useRef)(null),m=(0,c.useRef)(null),f=(0,c.useId)(),p=`${f}-input`,g=`${f}-title`,[S,o]=(0,c.useState)(!1),D=e.installCandidates??[],B=e.selectedInstallSkills??new Set,v=D.length>0&&D.every(T=>B.has(T.name)),C=e.installBusy||e.installDiscovering,w=el(e.installSource),h=l(w==="github"?"skills.sourceDetectedGithub":w==="git"?"skills.sourceDetectedGit":w==="agentbuddy"?"skills.sourceDetectedAgentbuddy":w==="local"?"skills.sourceDetectedLocal":"skills.sourceDetectedUnknown"),x=l(w==="agentbuddy"?"skills.sourcePreflightAgentbuddy":w==="github"||w==="git"?"skills.sourcePreflightGit":w==="local"?"skills.sourcePreflightLocal":"skills.sourcePreflightUnknown"),E=l(w==="agentbuddy"?"skills.installDiagnosticAgentbuddy":w==="github"||w==="git"?"skills.installDiagnosticGit":w==="local"?"skills.installDiagnosticLocal":"skills.installDiagnosticUnknown");return(0,c.useEffect)(()=>{let T=n.current;if(T)if(e.installSelectionOpen&&!T.open)try{T.showModal()}catch{}else!e.installSelectionOpen&&T.open&&T.close()},[e.installSelectionOpen,D.length]),(0,c.useEffect)(()=>{if(!S||typeof document>"u")return;let T=A=>{m.current?.contains(A.target)||o(!1)},L=A=>{A.key==="Escape"&&o(!1)};return document.addEventListener("pointerdown",T),document.addEventListener("keydown",L),()=>{document.removeEventListener("pointerdown",T),document.removeEventListener("keydown",L)}},[S]),(0,s.jsxs)("article",{className:"bd-card skills-install-panel",children:[e.showTitle===!1?null:(0,s.jsx)("div",{className:"skills-install-title",children:(0,s.jsx)("h3",{className:"bd-section-title",children:(0,s.jsx)(hl,{help:l("skills.installInfo"),helpLabel:l("skills.installInfoLabel"),children:l("skills.install")})})}),e.installTargetSkill?(0,s.jsxs)("div",{className:"skills-inline-target","data-install-target":e.installTargetSkill,children:[(0,s.jsx)("span",{children:l("skills.installTargetHint",{skill:e.installTargetSkill})}),(0,s.jsx)("button",{type:"button","data-action":"clear-install-target",onClick:()=>e.onClearInstallTarget?.(),children:l("skills.clearInstallTarget")})]}):null,(0,s.jsxs)("div",{className:"skills-install-grid",children:[(0,s.jsxs)("div",{className:"skills-source-label",children:[(0,s.jsxs)("div",{className:"skills-source-heading",ref:m,onKeyDown:T=>{T.key==="Escape"&&o(!1)},children:[(0,s.jsx)("label",{htmlFor:p,children:l("skills.source")}),(0,s.jsx)("button",{type:"button",className:"skills-source-help-trigger","data-action":"toggle-source-help","aria-label":l("skills.sourceHelpOpen"),"aria-expanded":S,"aria-controls":f,"aria-haspopup":"dialog",onClick:()=>o(T=>!T),children:"?"}),S?(0,s.jsxs)("aside",{className:"skills-source-help-popover",id:f,role:"dialog","aria-labelledby":g,"data-source-help-popover":!0,children:[(0,s.jsxs)("div",{className:"skills-source-help-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("strong",{id:g,children:l("skills.sourceHelpTitle")}),(0,s.jsx)("span",{children:l("skills.sourceHelpIntro")})]}),(0,s.jsx)("button",{type:"button",className:"skills-source-help-close","data-action":"close-source-help","aria-label":l("skills.sourceHelpClose"),onClick:()=>o(!1),children:"\xD7"})]}),(0,s.jsxs)("div",{className:"skills-source-help-list",children:[(0,s.jsxs)("section",{children:[(0,s.jsx)("strong",{children:l("skills.sourceHelpRemoteLabel")}),(0,s.jsx)("span",{children:l("skills.sourceHelpRemote")}),(0,s.jsx)("code",{children:l("skills.sourceHelpRemoteExample")})]}),(0,s.jsxs)("section",{children:[(0,s.jsx)("strong",{children:l("skills.sourceHelpLocalLabel")}),(0,s.jsx)("span",{children:l("skills.sourceHelpLocal")}),(0,s.jsx)("code",{children:l("skills.sourceHelpLocalExample")})]}),(0,s.jsxs)("section",{children:[(0,s.jsx)("strong",{children:l("skills.sourceHelpAgentbuddyLabel")}),(0,s.jsx)("span",{children:l("skills.sourceHelpAgentbuddy")}),(0,s.jsx)("code",{children:l("skills.sourceHelpAgentbuddyExample")})]})]})]}):null]}),(0,s.jsx)("div",{className:"skills-source-control",children:(0,s.jsx)("input",{id:p,type:"text","data-install":"source","aria-label":l("skills.source"),placeholder:l("skills.sourcePlaceholder"),value:e.installSource,onChange:T=>e.onInstallSourceChange(T.currentTarget.value)})}),e.installSource.trim()?(0,s.jsxs)("div",{className:`skills-source-feedback is-${w}`,"data-source-hint":w,children:[(0,s.jsx)("strong",{children:h}),(0,s.jsx)("span",{children:x})]}):null]}),(0,s.jsxs)("details",{className:"skills-install-advanced","data-install-advanced":!0,children:[(0,s.jsx)("summary",{children:l("skills.advancedOptions")}),(0,s.jsxs)("div",{className:"skills-install-advanced-body",children:[(0,s.jsxs)("label",{className:"skills-install-field",children:[(0,s.jsx)("span",{children:l("skills.path")}),(0,s.jsx)("input",{type:"text","data-install":"path",placeholder:l("skills.pathPlaceholder"),value:e.installPath,onChange:T=>e.onInstallPathChange(T.currentTarget.value)}),(0,s.jsx)("small",{children:l("skills.pathHelpInline")})]}),(0,s.jsxs)("label",{className:"skills-install-field",children:[(0,s.jsx)("span",{children:l("skills.ref")}),(0,s.jsx)("input",{type:"text","data-install":"ref",placeholder:l("skills.refPlaceholder"),value:e.installRef,onChange:T=>e.onInstallRefChange(T.currentTarget.value)}),(0,s.jsx)("small",{children:l("skills.refHelpInline")})]}),(0,s.jsxs)("label",{className:"skills-scan-toggle",children:[(0,s.jsx)("input",{type:"checkbox","data-install":"full-depth",checked:e.installFullDepth,disabled:C,onChange:T=>e.onInstallFullDepthChange(T.currentTarget.checked)}),(0,s.jsxs)("span",{children:[(0,s.jsx)("strong",{children:l("skills.deepScan")}),(0,s.jsx)("small",{children:l("skills.deepScanHelp")}),(0,s.jsx)("small",{className:"muted",children:l("skills.autoDeepScanHint")})]})]})]})]}),(0,s.jsxs)("div",{className:"skills-install-actions",children:[(0,s.jsx)("button",{type:"button",className:"skills-local-discovery-link","data-action":"open-native-skill-discovery",title:l("skills.localDiscoverHelp"),onClick:()=>e.onOpenNativeDiscovery(),children:l("skills.localDiscover")}),(0,s.jsx)("button",{type:"button",className:"primary","data-action":"install",disabled:C||!e.installSource.trim(),onClick:()=>e.onInstall(),children:e.installDiscovering?l("skills.scanning"):e.installBusy?l("skills.jobRunning"):l("skills.installSubmit")})]})]}),e.installStatus?(0,s.jsx)("div",{className:"actions skills-install-status-row",children:(0,s.jsx)("span",{className:tl(e.installStatus),"data-skills-status":!0,children:e.installStatus.text})}):null,e.installStatus&&!e.installStatus.ok?(0,s.jsxs)("div",{className:"skills-install-diagnostic","data-install-diagnostic":w,role:"alert",children:[(0,s.jsx)("strong",{children:l("skills.installDiagnosticTitle")}),(0,s.jsx)("span",{children:E})]}):null,(0,s.jsx)("dialog",{className:"skills-discovery-dialog skills-install-selection-dialog","data-install-selection-dialog":!0,ref:n,onClose:()=>e.onCloseInstallSelection?.(),children:(0,s.jsxs)("article",{children:[(0,s.jsxs)("header",{children:[(0,s.jsx)("h3",{children:l("skills.installSelectionTitle")}),(0,s.jsx)("p",{children:l("skills.installSelectionHelp",{count:D.length})})]}),(0,s.jsx)("div",{className:"skills-discovery-body skills-install-selection-body",children:(0,s.jsxs)("div",{className:"skills-candidate-list","data-install-candidates":!0,children:[(0,s.jsxs)("div",{className:"skills-candidate-list-head",children:[(0,s.jsx)("span",{children:l("skills.scanFound",{count:D.length})}),e.onSelectAllInstallSkills?(0,s.jsx)("button",{type:"button","data-action":"toggle-all-source-skills",disabled:e.installBusy,onClick:()=>e.onSelectAllInstallSkills?.(!v),children:l(v?"skills.discoverClearSelection":"skills.discoverSelectAll")}):null]}),D.map(T=>(0,s.jsxs)("label",{className:"skills-candidate-row",children:[(0,s.jsx)("input",{type:"checkbox",checked:B.has(T.name),disabled:e.installBusy,onChange:()=>e.onToggleInstallSkill?.(T.name)}),(0,s.jsxs)("span",{children:[(0,s.jsx)("strong",{children:T.name}),(0,s.jsxs)("small",{children:[T.path,T.description?` \xB7 ${T.description}`:""]})]})]},`${T.name}:${T.path}`))]})}),(0,s.jsxs)("footer",{className:"actions",children:[(0,s.jsx)("button",{type:"button","data-action":"close-install-selection",disabled:e.installBusy,onClick:()=>e.onCloseInstallSelection?.(),children:l("skills.installSelectionCancel")}),(0,s.jsx)("button",{type:"button",className:"primary","data-action":"confirm-install-selection",disabled:e.installBusy||B.size===0,onClick:()=>e.onConfirmInstallSelection?.(),children:e.installBusy?l("skills.jobRunning"):l("skills.installSelected")})]})]})})]})}function Ns(e){let l=Z(),n=(0,c.useRef)(null),m=(0,c.useRef)(new Set(e.skills.map(a=>a.name))),f=(0,c.useRef)(""),p=(0,c.useRef)(!1),g=(0,c.useRef)(null),[S,o]=(0,c.useState)(""),[D,B]=(0,c.useState)(!1),[v,C]=(0,c.useState)(()=>new Set),[w,h]=(0,c.useState)(null),[x,E]=(0,c.useState)(0),[T,L]=(0,c.useState)(()=>typeof window>"u"?1200:window.innerWidth),A=S.trim().toLocaleLowerCase();f.current=S,p.current=D;let $=(0,c.useMemo)(()=>{let a=w?e.skills.filter(M=>w.has(M.name)):e.skills;return A?a.filter(M=>[M.name,M.displayName,M.description,...M.tags??[],ll(M,l)].filter(Boolean).join(`
3
+ `).toLocaleLowerCase().includes(A)):a},[w,A,e.skills,l]),H=(0,c.useMemo)(()=>{if(!w)return[];let a=new Set(e.skills.map(M=>M.name));return[...w].filter(M=>!a.has(M)).sort()},[w,e.skills]),K=hs(T)*bs,F=Math.max(1,Math.ceil($.length/K)),y=$.slice(x*K,x*K+K),b=(0,c.useMemo)(()=>new Set($.map(a=>a.name)),[$]),I=$.filter(a=>v.has(a.name)).length,d=Math.max(0,v.size-I),U=$.length>0&&I===$.length;(0,c.useEffect)(()=>{if(typeof window>"u")return;let a=()=>L(window.innerWidth);return window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),(0,c.useEffect)(()=>{e.externalQuery!=null&&e.externalQuery!==""&&o(e.externalQuery)},[e.externalQuery]),(0,c.useEffect)(()=>{e.externalFilterNames&&e.externalFilterNames.length>0&&h(new Set(e.externalFilterNames))},[e.externalFilterNames]),(0,c.useEffect)(()=>E(0),[A,K,w]),(0,c.useEffect)(()=>{E(a=>Math.min(Math.max(0,a),F-1))},[F]),(0,c.useEffect)(()=>{let a=new Set(e.skills.map(P=>P.name)),M=[...m.current].some(P=>!a.has(P));C(P=>{let _=new Set([...P].filter(V=>a.has(V)));return _.size===P.size?P:_}),M&&(B(!1),C(new Set)),m.current=a},[e.skills]),(0,c.useEffect)(()=>{n.current&&(n.current.indeterminate=I>0&&!U)},[U,I]),(0,c.useEffect)(()=>{if(typeof document>"u")return;let a=P=>{if(P.key!=="Escape"||!p.current)return;let _=f.current;g.current=_,P.preventDefault(),P.stopPropagation(),B(!1),C(new Set),window.setTimeout(()=>{o(V=>V||_),g.current=null},50)},M=P=>{if(P.key!=="Escape"||g.current===null)return;let _=g.current;g.current=null,P.preventDefault(),P.stopPropagation(),o(_)};return document.addEventListener("keydown",a,!0),document.addEventListener("keyup",M,!0),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("keyup",M,!0)}},[]);function G(a){C(M=>{let P=new Set(M);return P.has(a)?P.delete(a):P.add(a),P})}function te(){C(a=>{let M=new Set(a);if(U)for(let P of b)M.delete(P);else for(let P of b)M.add(P);return M})}function r(a=!1){let M=S;B(!1),C(new Set),a&&typeof window<"u"&&window.setTimeout(()=>o(M),0)}return(0,s.jsxs)("section",{className:"skills-installed-block",children:[(0,s.jsx)(ue,{title:l("skills.installed"),count:l("skills.installedCount",{count:e.skills.length}),hint:l("skills.installedHelp"),children:(0,s.jsx)("div",{className:"skills-installed-header-actions",children:D?(0,s.jsx)("button",{type:"button","data-action":"cancel-installed-selection",onClick:()=>r(),children:l("skills.cancel")}):(0,s.jsx)("button",{type:"button","data-action":"select-installed-skills",disabled:e.skills.length===0,onClick:()=>B(!0),children:l("skills.select")})})}),(0,s.jsxs)("section",{className:"bd-card skills-installed-panel",children:[(0,s.jsxs)("div",{className:"skills-library-toolbar",children:[(0,s.jsxs)("label",{className:"skills-installed-search",children:[(0,s.jsx)("span",{className:"sr-only",children:l("skills.searchLabel")}),(0,s.jsx)("input",{type:"text",role:"searchbox",inputMode:"search","data-action":"search-installed-skills",placeholder:l("skills.searchPlaceholder"),value:S,onChange:a=>o(a.currentTarget.value),onKeyDown:a=>{a.key!=="Escape"||!D||(a.preventDefault(),a.stopPropagation(),r(!0))}}),S?(0,s.jsx)("button",{type:"button","data-action":"clear-installed-search","aria-label":l("skills.clearSearch"),onClick:()=>o(""),children:"\xD7"}):null]}),D?(0,s.jsxs)("label",{className:"skills-select-all-results",children:[(0,s.jsx)("input",{ref:n,type:"checkbox",checked:U,disabled:$.length===0||e.removingNames.size>0,onChange:te}),(0,s.jsx)("span",{children:A?l("skills.selectSearchResults",{count:$.length}):l("skills.selectAllSkills",{count:$.length})})]}):null,w?(0,s.jsxs)("button",{type:"button",className:"skills-library-filter-chip","data-action":"clear-library-filter",title:[...w].join(", "),"aria-label":l("skills.clearFilter"),onClick:()=>h(null),children:[l("skills.libraryFilterActive",{count:w.size})," \xD7"]}):null,A?(0,s.jsx)("span",{className:"skills-filter-count",children:l("skills.resultCount",{count:$.length})}):null,F>1?(0,s.jsxs)("div",{className:"skills-pager",children:[(0,s.jsx)("button",{type:"button",className:"skills-pager-button","data-action":"page-installed-skills","data-dir":"-1","aria-label":l("skills.prevPage"),title:l("skills.prevPage"),disabled:x===0,onClick:()=>E(a=>Math.max(0,a-1)),children:"\u2039"}),(0,s.jsx)("span",{children:l("skills.pageStatus",{page:x+1,pages:F})}),(0,s.jsx)("button",{type:"button",className:"skills-pager-button","data-action":"page-installed-skills","data-dir":"1","aria-label":l("skills.nextPage"),title:l("skills.nextPage"),disabled:x>=F-1,onClick:()=>E(a=>Math.min(F-1,a+1)),children:"\u203A"})]}):null]}),(0,s.jsx)("div",{className:"skills-installed-live",role:"status","aria-live":"polite",children:e.status?(0,s.jsx)("span",{className:tl(e.status),children:e.status.text}):null}),H.length>0&&(0,s.jsxs)("div",{className:"skills-missing-list","data-missing-skills":!0,children:[(0,s.jsx)("strong",{children:l("skills.missingFilteredTitle")}),H.map(a=>(0,s.jsxs)("div",{className:"skills-missing-row","data-missing-skill":a,children:[(0,s.jsx)("span",{className:"skills-missing-row-name",children:a}),(0,s.jsx)("small",{className:"muted",children:l("skills.dangling")}),(0,s.jsx)("button",{type:"button","data-action":"install-dangling-skill",disabled:!e.onInstallMissing,onClick:()=>e.onInstallMissing?.(a),children:l("skills.installNow")})]},a))]}),e.skills.length===0?(0,s.jsxs)("div",{className:"skills-library-empty",children:[(0,s.jsx)("strong",{children:l("skills.emptyTitle")}),(0,s.jsx)("p",{children:l("skills.emptyHelp")})]}):$.length===0&&H.length>0?null:$.length===0?(0,s.jsxs)("div",{className:"skills-library-empty","data-empty":"search",children:[(0,s.jsx)("strong",{children:l("skills.noResultsTitle",{query:S.trim()})}),(0,s.jsx)("p",{children:l("skills.noResultsHelp")}),(0,s.jsx)("button",{type:"button","data-action":"clear-installed-search-empty",onClick:()=>o(""),children:l("skills.clearSearch")})]}):(0,s.jsx)("div",{className:"skills-list",children:y.map(a=>{let M=v.has(a.name),P=e.removingNames.has(a.name);return(0,s.jsxs)("article",{className:`skills-row skills-installed-card${D?" is-selectable":""}${M?" is-selected":""}${P?" is-removing":""}`,"data-skill":a.name,"data-selection-mode":D?"true":void 0,"aria-busy":P||void 0,onClick:D?()=>G(a.name):void 0,children:[(0,s.jsxs)("div",{className:"skills-row-body",children:[(0,s.jsxs)("div",{className:"skills-row-title",children:[D?(0,s.jsx)("input",{type:"checkbox","aria-label":l("skills.selectNamed",{skill:a.displayName??a.name}),checked:M,disabled:P,onClick:_=>_.stopPropagation(),onChange:()=>G(a.name)}):null,(0,s.jsxs)("span",{children:[(0,s.jsx)("strong",{children:a.displayName??a.name}),a.displayName&&a.displayName!==a.name?(0,s.jsx)("small",{className:"skills-canonical-name",children:a.name}):null]})]}),a.description?(0,s.jsx)("p",{children:a.description}):null,(0,s.jsx)("small",{className:"skills-source-badge",children:ll(a,l)}),e.graph?(()=>{let _=e.graph.skills.get(a.name),V=e.packsKnown===!1,he=_?.packIds.length??0,fe=_?new Set([..._.directBotIds,..._.viaPackBotIds]).size:0,ye=V?l("skills.healthUnknown"):(_?.packIds??[]).map(le=>e.packNames?.find(se=>se.id===le)?.name??le).join(", ");return(0,s.jsxs)("span",{className:"skills-usage-chips",children:[(0,s.jsx)("button",{type:"button",className:"skills-usage-chip","data-action":"show-skill-packs",disabled:V||he===0||!e.onShowSkillPacks,title:ye||void 0,onClick:le=>{le.stopPropagation(),e.onShowSkillPacks?.(a.name)},children:V?l("skills.usedInPacksUnknown"):l("skills.usedInPacks",{count:he})}),(0,s.jsx)("button",{type:"button",className:"skills-usage-chip","data-action":"show-skill-bots",disabled:fe===0||!e.onShowSkillBots,onClick:le=>{le.stopPropagation(),e.onShowSkillBots?.(a.name)},children:l("skills.usedByBots",{count:fe})})]})})():null,P?(0,s.jsx)("span",{className:"skills-removing-label",children:l("skills.removing")}):null]}),D?null:(0,s.jsxs)("div",{className:"skills-card-actions",children:[(0,s.jsx)("button",{type:"button","data-action":"update-skill",disabled:e.busySkill===`${a.name}:update`||P,onClick:()=>e.onUpdate(a.name),children:l("skills.update")}),(0,s.jsx)("button",{type:"button","data-action":"remove-skill",disabled:P,onClick:()=>e.onRequestRemove([a.name]),children:l("skills.remove")})]})]},a.name)})})]}),D?(0,s.jsxs)("div",{className:"skills-bulk-action-bar",role:"toolbar","aria-label":l("skills.bulkActions"),children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("strong",{children:l("skills.selectedCount",{count:v.size})}),d>0?(0,s.jsx)("small",{children:l("skills.selectedHidden",{count:d})}):null]}),(0,s.jsx)("button",{type:"button",className:"danger","data-action":"remove-selected-skills",disabled:v.size===0||e.removingNames.size>0,onClick:()=>e.onRequestRemove([...v]),children:l("skills.removeSelected",{count:v.size})})]}):null]})}function ws(e){let l=Z(),n=(0,c.useRef)(null),m=e.names??[],f=e.references.length>0,p=m.slice(0,3),g=new Set(e.references.flatMap(o=>o.bots)).size,S=new Set(e.references.flatMap(o=>o.packs)).size;return(0,c.useEffect)(()=>{let o=n.current;if(o)if(e.names&&!o.open)try{o.showModal()}catch{}else!e.names&&o.open&&o.close()},[e.names]),(0,s.jsx)("dialog",{className:"skills-remove-dialog","data-remove-skills-dialog":!0,ref:n,onCancel:o=>{o.preventDefault(),e.busy||e.onCancel()},onClick:o=>{o.target===o.currentTarget&&!e.busy&&e.onCancel()},children:(0,s.jsxs)("article",{children:[(0,s.jsxs)("header",{children:[(0,s.jsx)("h3",{children:f?m.length===1?l("skills.removeInUseOneTitle",{skill:m[0]}):l("skills.removeInUseManyTitle",{count:m.length}):m.length===1?l("skills.removeOneTitle",{skill:m[0]}):l("skills.removeManyTitle",{count:m.length})}),(0,s.jsx)("p",{children:f?m.length===1?S>0?l("skills.removeInUseOneHelpWithPacks",{botCount:g,packCount:S}):l("skills.removeInUseOneHelp",{count:g}):S>0?l("skills.removeInUseManyHelpWithPacks",{botCount:g,packCount:S}):l("skills.removeInUseManyHelp",{count:g}):m.length===1?l("skills.removeOnePermanentHelp"):l("skills.removePermanentHelp")})]}),(0,s.jsxs)("div",{className:"skills-remove-dialog-body",children:[m.length>1?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("ul",{children:p.map(o=>(0,s.jsx)("li",{children:o},o))}),m.length>p.length?(0,s.jsx)("p",{children:l("skills.removeMore",{count:m.length-p.length})}):null]}):null,e.references.length>0?(0,s.jsxs)("div",{className:"skills-remove-reference-warning",role:"alert",children:[(0,s.jsx)("strong",{children:l("skills.removeReferencesDetail")}),(0,s.jsx)("ul",{children:e.references.map(o=>(0,s.jsxs)("li",{children:[(0,s.jsx)("strong",{children:o.name}),(0,s.jsxs)("span",{children:[o.bots.join(", "),o.bots.length>0&&o.packs.length>0?" \xB7 ":"",o.packs.length>0?`${l("skills.packChips")}: ${o.packs.join(", ")}`:""]})]},o.name))})]}):null,e.error?(0,s.jsx)("p",{className:"hint-warn",role:"alert",children:e.error}):null]}),(0,s.jsxs)("footer",{className:"actions",children:[(0,s.jsx)("button",{type:"button",autoFocus:!0,disabled:e.busy,onClick:e.onCancel,children:l("skills.cancel")}),(0,s.jsx)("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>e.onConfirm(f),children:e.busy?l("skills.removing"):f?l("skills.removeAnyway"):m.length===1?l("skills.removeOneConfirm"):l("skills.removeSelected",{count:m.length})})]})]})})}function Is(){let e=Z(),l=(0,c.useRef)(!0),n=(0,c.useRef)(new Set),m=(0,c.useRef)(null),{skills:f,nativeSkillGroups:p,bots:g,packs:S,trustProjectSkills:o,delivery:D,loading:B,loadError:v,packsError:C,packsKnown:w,refresh:h,setSkills:x,setBots:E,setTrustProjectSkills:T,setDelivery:L}=Al({apiUnavailableText:e("skills.apiUnavailable")}),[A,$]=(0,c.useState)("library"),[H,K]=(0,c.useState)(null),[F,y]=(0,c.useState)(null),b=(0,c.useCallback)(t=>{K(t),y(t.installTargetSkill??null),$(t.tab)},[]),I=(0,c.useCallback)(()=>K(null),[]),[d,U]=(0,c.useState)(""),[G,te]=(0,c.useState)(""),[r,a]=(0,c.useState)(""),[M,P]=(0,c.useState)(null),[_,V]=(0,c.useState)(!1),[he,fe]=(0,c.useState)(!1),[ye,le]=(0,c.useState)(!1),[se,W]=(0,c.useState)([]),[Y,we]=(0,c.useState)(!1),[xe,Se]=(0,c.useState)(!1),[ze,Me]=(0,c.useState)(()=>new Set),[Ke,Ie]=(0,c.useState)(!1),[xl,nl]=(0,c.useState)(!1),[_e,Ml]=(0,c.useState)(null),[We,qe]=(0,c.useState)(()=>new Set),[El,Ee]=(0,c.useState)(null),[$l,al]=(0,c.useState)(null),[Ll,il]=(0,c.useState)(()=>new Set),[ol,Ne]=(0,c.useState)({}),[Je,Ce]=(0,c.useState)(null),[rl,Qe]=(0,c.useState)(null),[Hl,Pe]=(0,c.useState)(!1),[Ol,$e]=(0,c.useState)([]),[jl,Le]=(0,c.useState)(null),[He,cl]=(0,c.useState)(()=>new Set),Re=(0,c.useRef)(g),Oe=(0,c.useRef)(new Map);(0,c.useEffect)(()=>{Re.current=g},[g]);let je=(0,c.useMemo)(()=>new Set(f.map(t=>t.name)),[f]),ve=(0,c.useMemo)(()=>p.length===0?void 0:(_e?p.find(i=>Be(i)===_e):void 0)??p.find(i=>i.skills.length>0)??p[0],[_e,p]),Xe=ve?Be(ve):"",De=(0,c.useMemo)(()=>ve?ve.skills.filter(t=>!je.has(t.name)).map(t=>t.rootDir??t.source?.root??"").filter(Boolean):[],[ve,je]),dl=De.length>0&&De.every(t=>We.has(t)),ul=(0,c.useCallback)(()=>{for(let t of n.current)window.clearTimeout(t);n.current.clear()},[]),Fl=(0,c.useCallback)(t=>new Promise(i=>{let N=window.setTimeout(()=>{n.current.delete(N),i()},t);n.current.add(N)}),[]);(0,c.useEffect)(()=>(l.current=!0,()=>{l.current=!1,ul()}),[ul]),(0,c.useEffect)(()=>{qe(t=>{let i=new Set,N=new Set(f.map(R=>R.name));for(let R of p)for(let z of R.skills){let j=z.rootDir??z.source?.root??"";j&&!N.has(z.name)&&t.has(j)&&i.add(j)}return i.size===t.size?t:i})},[f,p]),(0,c.useEffect)(()=>{if(!Je||He.size>0)return;let t=window.setTimeout(()=>{l.current&&Ce(null)},6e3);return()=>window.clearTimeout(t)},[Je,He]),(0,c.useEffect)(()=>{let t=m.current;if(t)if(Ke&&!t.open)try{t.showModal()}catch{}else!Ke&&t.open&&t.close()},[Ke,Xe]);async function kl(t,i,N=!0){let R=t;for(i({text:e("skills.jobRunning"),ok:!0});;){if(!l.current)return null;if(R.status==="succeeded")return i({text:e("skills.saved"),ok:!0}),N&&await h(),R;if(R.status==="failed")throw new Error(R.error??"job_failed");if(await Fl(800),!l.current)return null;let z=await re(`/api/skills/jobs/${encodeURIComponent(R.id)}`,{method:"GET"});if(!l.current)return null;R=z.job}}function Ul(t){return g.filter(i=>ke(i.skills).includes(t)).map(i=>i.botName??i.larkAppId)}function Te(){W([]),Me(new Set),le(!1),Se(!1)}function ml(){return{source:d.trim(),path:G.trim()||void 0,ref:r.trim()||void 0,...Y?{fullDepth:!0}:{}}}function Gl(t,i=Y||xe){let N=t??[...ze];return{...ml(),skillNames:N.length>0?N:void 0,...i?{fullDepth:!0}:{}}}async function zl(){fe(!0),P({text:e("skills.scanning"),ok:!0});try{let t=await re("/api/skills/discover",{method:"POST",body:JSON.stringify(ml())});if(!l.current)return{skills:[],directInstall:!1,fullDepth:Y};let i=t.discovery?.directInstall===!0,N=Array.isArray(t.discovery?.skills)?t.discovery.skills:[],R=t.discovery?.deepScanned===!0;return Se(R),W(N),Me(sl(N,F).selected),{skills:N,directInstall:i,fullDepth:Y||R}}finally{l.current&&fe(!1)}}function me(t){let i=t||"";return i.startsWith("skill_git_command_failed")&&/authentication failed|could not read username|repository not found|unauthor|\b401\b|\b403\b/i.test(i)?e("skills.gitNeedsAuth"):i.startsWith("agentbuddy_not_found")?e("skills.agentbuddyNotFound"):i.startsWith("agentbuddy_login_required")?e("skills.agentbuddyNeedsLogin"):i.startsWith("agentbuddy_command_failed")?/login|credential|unauthor|not logged|401|403/i.test(i)?e("skills.agentbuddyNeedsLogin"):e("skills.agentbuddyCommandFailed"):i.startsWith("agentbuddy_clear_telemetry_failed")||i.startsWith("agentbuddy_telemetry_not_stripped")?e("skills.agentbuddyTelemetryFailed"):i.startsWith("agentbuddy_no_skill_produced")?e("skills.agentbuddyNoSkill"):i.startsWith("invalid_agentbuddy")?e("skills.agentbuddyInvalid"):i}async function Ze(t,i=Y||xe){V(!0);try{let N=await re("/api/skills/install",{method:"POST",body:JSON.stringify(Gl(t,i))});if(!l.current)return null;let R=await kl(N.job,P);if(!l.current||!R)return null;let z=(R.skills??(R.skill?[R.skill]:[])).map(j=>j.name).filter(Boolean);return Te(),y(null),[...new Set(z.length>0?z:t??[])]}catch(N){return l.current&&P({text:`${e("skills.failed")}: ${me(N?.message??String(N))}`,ok:!1}),null}finally{l.current&&V(!1)}}function Kl(t){Me(i=>{let N=new Set(i);return N.has(t)?N.delete(t):N.add(t),N})}function _l(t){Me(t?new Set(se.map(i=>i.name)):new Set)}async function Wl(){if(!d.trim())return P({text:e("skills.sourceRequired"),ok:!1}),null;try{le(!1);let{skills:t,directInstall:i,fullDepth:N}=await zl();if(!l.current)return null;if(i)return await Ze(void 0,N);if(t.length===0)return P({text:e("skills.scanEmpty"),ok:!1}),null;let{targetMissing:R}=sl(t,F);return t.length===1&&!R?await Ze([t[0].name],N):(P(R?{text:e("skills.installTargetNotFound",{skill:F}),ok:!1}:{text:e("skills.scanFound",{count:t.length}),ok:!0}),le(!0),null)}catch(t){return l.current&&P({text:`${e("skills.failed")}: ${me(t?.message??String(t))}`,ok:!1}),null}}async function ql(){let t=[...ze];return t.length===0?(P({text:e("skills.discoverNothingSelected"),ok:!1}),null):await Ze(t)}async function Jl(t){await re("/api/skill-packs",{method:"POST",body:JSON.stringify({id:t.id,name:t.name,include:t.skillNames.map(i=>`skill:${i}`)})}),l.current&&(await h(),l.current&&$("packs"))}async function Ql(){let t=[...We].filter(Boolean);if(t.length===0){P({text:e("skills.discoverNothingSelected"),ok:!1});return}nl(!0);try{if(P({text:e("skills.discoverRegisteringBatch",{total:t.length}),ok:!0}),await re("/api/skills/install-local-links",{method:"POST",body:JSON.stringify({sources:t})}),!l.current)return;Ie(!1),await h(),l.current&&P({text:e("skills.saved"),ok:!0})}catch(i){l.current&&P({text:`${e("skills.failed")}: ${me(i?.message??String(i))}`,ok:!1})}finally{l.current&&nl(!1)}}async function Xl(t){if(o!==t){Ee("project");try{let i=await re("/api/skills/global",{method:"PUT",body:JSON.stringify({trustProjectSkills:t})});if(!l.current)return;T(i.trustProjectSkills==="all"?"all":t)}catch(i){l.current&&window.alert(`${e("skills.failed")}: ${me(i?.message??String(i))}`)}finally{l.current&&Ee(null)}}}async function Zl(t){if(D!==t){Ee("delivery");try{let i=await re("/api/skills/global",{method:"PUT",body:JSON.stringify({delivery:t})});if(!l.current)return;L(i.delivery==="prompt"||i.delivery==="native"?i.delivery:t)}catch(i){l.current&&window.alert(`${e("skills.failed")}: ${me(i?.message??String(i))}`)}finally{l.current&&Ee(null)}}}async function Vl(t){al(`${t}:update`);try{let i=await re(`/api/skills/${encodeURIComponent(t)}/update`,{method:"POST",body:"{}"});if(!l.current)return;await kl(i.job,P)}catch(i){l.current&&window.alert(`${e("skills.failed")}: ${me(i?.message??String(i))}`)}finally{l.current&&al(null)}}function Yl(t){let i=[...new Set(t.filter(N=>je.has(N)))];i.length!==0&&(Qe(i),Pe(!0),$e([]),Le(null))}function es(){He.size>0||(Pe(!1),Qe(null),$e([]),Le(null))}async function ls(t){let i=rl??[];if(i.length!==0){cl(new Set(i)),Pe(!1),Le(null),Ce({text:e("skills.removingCount",{count:i.length}),ok:!0});try{let N=await re("/api/skills",{method:"DELETE",body:JSON.stringify({names:i,force:t})});if(!l.current)return;let R=Array.isArray(N.removed)?N.removed.filter(j=>typeof j=="string"):i,z=new Set(R);x(j=>j.filter(ne=>!z.has(ne.name))),Ce({text:R.length===1?e("skills.removedOne",{skill:R[0]}):e("skills.removedMany",{count:R.length}),ok:!0}),Qe(null),$e([])}catch(N){if(!l.current)return;if(N?.status===409&&N?.body?.error==="skills_in_use"){let z=Array.isArray(N.body.affectedSkills)?N.body.affectedSkills.map(j=>{let ne=typeof j?.name=="string"?j.name:"",ie=Array.isArray(j?.affectedBots)?j.affectedBots.map(ae=>ae?.botName||ae?.larkAppId||"").filter(Boolean):Ul(ne),ce=Array.isArray(j?.affectedPacks)?j.affectedPacks.filter(ae=>typeof ae=="string"):[];return ne?{name:ne,bots:ie,packs:ce}:null}).filter(j=>j!==null):[];$e(z),Pe(!0),Ce(null);return}let R=e("skills.removeFailed",{detail:me(N?.message??String(N))});Le(R),Pe(!0),Ce({text:R,ok:!1})}finally{l.current&&cl(new Set)}}}function gl(t,i){let N=Oe.current.get(t)??Promise.resolve();il(z=>new Set(z).add(t));let R=N.catch(()=>{}).then(i);return Oe.current.set(t,R),R.finally(()=>{Oe.current.get(t)===R&&(Oe.current.delete(t),l.current&&il(z=>{let j=new Set(z);return j.delete(t),j}))})}async function pl(t,i,N){Ne(R=>({...R,[t]:null}));try{let R=Re.current.find(ie=>ie.larkAppId===t),z=Cl(R?.skills,i,N),j=await re(`/api/bots/${encodeURIComponent(t)}/skills`,{method:"PUT",body:JSON.stringify({action:"set",policy:z.length>0?{include:z}:null})});if(!l.current)return;let ne=ie=>ie.map(ce=>ce.larkAppId===t?{...ce,skills:j.skills??null}:ce);Re.current=ne(Re.current),E(ne),Ne(ie=>({...ie,[t]:{text:e("skills.policySaved"),ok:!0}}))}catch(R){throw l.current&&Ne(z=>({...z,[t]:{text:`${e("skills.failed")}: ${me(R?.message??String(R))}`,ok:!1}})),R}}function ss(t,i,N){return gl(t,()=>pl(t,i,N))}function ts(t,i,N){return gl(t,async()=>{let R=Re.current.find(ae=>ae.larkAppId===t),z=ke(R?.skills),j=be(R?.skills),[ne,ie]=i.split(":",2),ce=ae=>N?[...new Set([...ae,ie])]:ae.filter(cs=>cs!==ie);await pl(t,ne==="skill"?ce(z):z,ne==="pack"?ce(j):j)})}async function ns(t,i){Ne(N=>({...N,[t]:null}));try{if(await re(`/api/bots/${encodeURIComponent(t)}/skill-injection`,{method:"PUT",body:JSON.stringify({skillInjection:i})}),!l.current)return;E(N=>N.map(R=>R.larkAppId===t?{...R,skillInjection:i}:R)),Ne(N=>({...N,[t]:{text:e("skills.saved"),ok:!0}}))}catch(N){l.current&&Ne(R=>({...R,[t]:{text:`${e("skills.failed")}: ${N?.message??N}`,ok:!1}}))}}let as=g.filter(t=>Pl(t.skills)).length,is=g.reduce((t,i)=>t+(i.skills?.include?.length??0),0),ge=(0,c.useMemo)(()=>Ge(f,S,g,{packsKnown:w}),[f,S,g,w]),pe=(0,c.useMemo)(()=>Rl(ge),[ge]),Fe=(0,c.useMemo)(()=>[...ge.packs.values()].filter(t=>t.botIds.length===0).map(t=>t.id),[ge]),Ue=(0,c.useMemo)(()=>[...ge.bots.values()].filter(t=>t.health==="missing"||t.health==="pack_missing").map(t=>t.larkAppId),[ge]),os=(0,s.jsxs)("div",{className:"page-heading-actions skills-heading-actions",children:[(0,s.jsxs)("div",{className:"skills-metric-strip",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:e("skills.metricInstalled")}),(0,s.jsx)("strong",{children:f.length})]}),(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:e("skills.metricPacks")}),(0,s.jsx)("strong",{children:w?S.length:"\u2014"})]}),(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:e("skills.metricBots")}),(0,s.jsxs)("strong",{children:[as,"/",g.length]})]}),(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:e("skills.metricAttached")}),(0,s.jsx)("strong",{children:is})]})]}),(0,s.jsxs)("div",{className:"skills-issue-strip",role:"group","aria-label":e("skills.issuesLabel"),children:[pe.length>0&&(0,s.jsx)("button",{type:"button",className:"skills-issue-badge skills-issue-warn","data-action":"issue-dangling-skills",title:pe.join(", "),onClick:()=>b(pe.length===1?{tab:"library",librarySearch:pe[0],openInstallWizard:!0,installTargetSkill:pe[0]}:{tab:"library",libraryFilterSkills:pe}),children:e("skills.issueDangling",{count:pe.length})}),Fe.length>0&&(0,s.jsx)("button",{type:"button",className:"skills-issue-badge skills-issue-info","data-action":"issue-unassigned-packs",onClick:()=>b({tab:"packs",focusPackIds:Fe}),children:e("skills.issueUnassignedPacks",{count:Fe.length})}),Ue.length>0&&(0,s.jsx)("button",{type:"button",className:"skills-issue-badge skills-issue-warn","data-action":"issue-bots-missing",onClick:()=>b({tab:"bots",focusBotIds:Ue}),children:e("skills.issueBotsMissing",{count:Ue.length})}),!B&&w&&pe.length===0&&Fe.length===0&&Ue.length===0&&(0,s.jsx)("span",{className:"skills-issue-badge skills-issue-ok","data-skills-healthy":!0,children:e("skills.issueNone")})]}),(0,s.jsx)(bl,{id:"skills-refresh",label:e("skills.refresh"),busy:B,disabled:B,onClick:()=>{h()}})]}),rs=(0,s.jsx)("div",{className:"skills-page-stack",children:B?(0,s.jsx)(vl,{label:e("common.loading")}):v?(0,s.jsx)("p",{className:"hint-warn",children:v}):(0,s.jsxs)(s.Fragment,{children:[C&&(0,s.jsx)("p",{className:"hint-warn","data-packs-error":!0,role:"alert",children:e(w?"skills.packsLoadError":"skills.packsLoadErrorFirst",{error:C})}),(0,s.jsxs)("div",{className:"skills-tabs",role:"tablist",children:[(0,s.jsx)("button",{role:"tab","aria-selected":A==="library",className:A==="library"?"active":"",onClick:()=>$("library"),children:e("skills.tabLibrary")}),(0,s.jsx)("button",{role:"tab","aria-selected":A==="packs",className:A==="packs"?"active":"",onClick:()=>$("packs"),children:e("skills.tabPacks")}),(0,s.jsx)("button",{role:"tab","aria-selected":A==="bots",className:A==="bots"?"active":"",onClick:()=>$("bots"),children:e("skills.tabBots")}),(0,s.jsx)("button",{role:"tab","aria-selected":A==="delivery",className:A==="delivery"?"active":"",onClick:()=>$("delivery"),children:e("skills.tabDelivery")})]}),A==="packs"&&(0,s.jsx)(yl,{skills:f,packs:S,packsKnown:w,onRefresh:()=>{h()},focusPackId:H?.tab==="packs"?H.focusPackId??null:null,focusPackIds:H?.tab==="packs"?H.focusPackIds??null:null,onFocusConsumed:I,onOpenBot:t=>b({tab:"bots",focusBotIds:[t]}),onInstallMissingSkill:t=>b({tab:"library",librarySearch:t,openInstallWizard:!0,installTargetSkill:t})}),A==="library"&&(0,s.jsx)(Il,{skills:f,nativeSkillGroups:p,installSource:d,installPath:G,installRef:r,installFullDepth:Y,installStatus:M,installBusy:_,installDiscovering:he,installSelectionOpen:ye,installCandidates:se,selectedInstallSkills:ze,onInstallSourceChange:t=>{U(t),Te()},onInstallPathChange:t=>{te(t),Te()},onInstallRefChange:t=>{a(t),Te()},onInstallFullDepthChange:t=>{we(t),Te()},onToggleInstallSkill:Kl,onSelectAllInstallSkills:_l,onConfirmInstallSelection:ql,onCloseInstallSelection:()=>le(!1),onInstall:Wl,onOpenNativeDiscovery:()=>Ie(!0),onCreatePack:Jl,InstallPanel:Ss,InstalledLibrary:Ns,RemoveDialog:ws,removingNames:He,removalDialogOpen:Hl,pendingRemoval:rl,removalReferences:Ol,removalError:jl,skillBusy:$l,installedStatus:Je,onUpdateSkill:t=>{Vl(t)},onRequestRemove:Yl,onCancelRemoval:es,onConfirmRemoval:t=>{ls(t)},navIntent:H?.tab==="library"?H:null,onNavIntentConsumed:I,installTargetSkill:F,onClearInstallTarget:()=>y(null),packsKnown:w,onInstallMissing:t=>b({tab:"library",openInstallWizard:!0,installTargetSkill:t}),graph:ge,packNames:S.map(t=>({id:t.id,name:t.name})),onShowSkillPacks:t=>{let i=ge.skills.get(t)?.packIds??[];b(i.length===1?{tab:"packs",focusPackId:i[0]}:{tab:"packs",focusPackIds:i})},onShowSkillBots:t=>b({tab:"bots",focusSkill:t})}),A==="bots"&&(0,s.jsx)(Dl,{bots:g,skills:f,statuses:ol,onSave:ss,onMutate:ts,busyBotIds:Ll,packs:S,packsKnown:w,focusBotIds:H?.tab==="bots"?H.focusBotIds??null:null,focusSkill:H?.tab==="bots"?H.focusSkill??null:null,onFocusConsumed:I,onOpenPack:t=>b({tab:"packs",focusPackId:t}),onOpenSkill:t=>b({tab:"library",librarySearch:t})}),A==="delivery"&&(0,s.jsx)(Tl,{trustProjectSkills:o,delivery:D,globalBusy:El,onUpdateProject:t=>{Xl(t)},onUpdateDelivery:t=>{Zl(t)},bots:g,onUpdateBotInjection:ns,botStatuses:ol,SkillSegmented:ys}),(0,s.jsx)("dialog",{className:"skills-discovery-dialog",id:"skills-discovery-dialog",ref:m,onClose:()=>Ie(!1),onClick:t=>{t.target===t.currentTarget&&Ie(!1)},children:(0,s.jsxs)("article",{children:[(0,s.jsxs)("header",{children:[(0,s.jsx)("h3",{children:e("skills.discoverTitle")}),(0,s.jsx)("p",{children:e("skills.discoverHelp")}),(0,s.jsx)("button",{type:"button",className:"skills-discovery-close","data-action":"close-discovery","aria-label":e("skills.discoverClose"),title:e("skills.discoverClose"),onClick:()=>Ie(!1)})]}),(0,s.jsx)("div",{className:"skills-discovery-body",children:ve?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"skills-discovery-layout",children:[(0,s.jsx)("div",{className:"skills-discovery-tabs",role:"tablist","aria-label":e("skills.discoverTitle"),children:p.map(t=>{let i=Be(t),N=i===Xe;return(0,s.jsxs)("button",{type:"button",role:"tab","data-discovery-tab":i,className:N?"selected":"","aria-selected":N?"true":"false",onClick:()=>Ml(i),children:[(0,s.jsx)("strong",{children:t.label??t.cliId}),(0,s.jsx)("small",{children:e("skills.skillCount",{count:t.skills.length})})]},i)})}),(0,s.jsxs)("div",{className:"skills-discovery-main",children:[(0,s.jsx)("div",{className:"skills-discovery-path",children:(0,s.jsx)("code",{children:ve.rootDir})}),p.map(t=>{let i=Be(t);return(0,s.jsx)("section",{className:"skills-discovery-group","data-discovery-panel":i,hidden:!(i===Xe),children:t.skills.length===0?(0,s.jsx)("p",{className:"empty",children:e("skills.discoverGroupEmpty")}):(0,s.jsx)("div",{className:"skills-discovery-list",children:t.skills.map(R=>{let z=je.has(R.name),j=R.rootDir??R.source?.root??"";return(0,s.jsxs)("label",{className:`skills-discovery-row${z?" installed":""}`,children:[(0,s.jsx)("input",{type:"checkbox","data-discovered-skill":!0,value:j,disabled:z,checked:!z&&We.has(j),onChange:ne=>{let ie=ne.currentTarget.checked;qe(ce=>{let ae=new Set(ce);return ie?ae.add(j):ae.delete(j),ae})}}),(0,s.jsxs)("span",{children:[(0,s.jsx)("strong",{children:R.name}),R.description?(0,s.jsx)("small",{children:R.description}):null]}),z?(0,s.jsx)("em",{children:e("skills.discoverRegistered")}):null]},`${R.name}:${j}`)})})},i)})]})]})}):(0,s.jsx)("p",{className:"empty",children:e("skills.discoverEmpty")})}),(0,s.jsxs)("footer",{className:"actions",children:[(0,s.jsx)("button",{type:"button","data-action":"toggle-discovered-skills",disabled:De.length===0,onClick:()=>{qe(t=>{let i=new Set(t);return dl?De.forEach(N=>i.delete(N)):De.forEach(N=>i.add(N)),i})},children:e(dl?"skills.discoverClearSelection":"skills.discoverSelectAll")}),(0,s.jsx)("button",{type:"button",className:"primary","data-action":"register-discovered-skills",disabled:xl,onClick:()=>{Ql()},children:e("skills.discoverRegister")})]})]})})]})});return(0,s.jsxs)("section",{className:"page skills-page",children:[(0,s.jsxs)("div",{className:"page-heading",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"eyebrow",children:e("nav.skills")}),(0,s.jsx)("h1",{children:e("skills.title")})]}),os]}),(0,s.jsx)("div",{id:"skills-body",children:rs})]})}function Cs(e,l){return e.size===l.length&&l.every(n=>e.has(n))}function Ps(e){let l=Z(),n=(0,c.useRef)(null),m=(0,c.useRef)(null),f=(0,c.useRef)(null),[p,g]=(0,c.useState)(!1),[S,o]=(0,c.useState)(""),[D,B]=(0,c.useState)(()=>new Set(e.names)),[v,C]=(0,c.useState)(null),w=e.names.join(`
4
+ `),h=S.trim().toLocaleLowerCase(),x=(0,c.useMemo)(()=>{let b=new Map(e.skills.map(I=>[I.name,I]));for(let I of e.names)b.has(I)||b.set(I,{name:I});return[...b.values()].sort((I,d)=>I.name.localeCompare(d.name))},[e.names,e.skills]),E=(0,c.useMemo)(()=>h?x.filter(b=>`${b.name} ${b.description||""}`.toLocaleLowerCase().includes(h)):x,[h,x]),T=!Cs(D,e.names),L=(0,c.useCallback)(()=>{let b=m.current;if(!b||typeof window>"u")return;let I=b.getBoundingClientRect(),d=12,U=7,G=Math.min(370,Math.max(260,window.innerWidth-d*2)),te=Math.min(Math.max(d,I.left),Math.max(d,window.innerWidth-G-d)),r=Math.max(0,I.top-U-d),a=Math.max(0,window.innerHeight-I.bottom-U-d),M=r>a,P=M?r:a,_=118+Math.min(x.length,5)*42,V=Math.max(180,Math.min(_,P));C({left:te,top:M?Math.max(d,I.top-U-V):I.bottom+U,width:G,height:V})},[x.length]);(0,c.useEffect)(()=>{p||B(new Set(e.names))},[w,p]),(0,c.useEffect)(()=>{if(!p||typeof document>"u")return;let b=I=>{n.current?.contains(I.target)||f.current?.contains(I.target)||(g(!1),o(""),B(new Set(e.names)))};return document.addEventListener("pointerdown",b),window.addEventListener("resize",L),window.addEventListener("scroll",L,!0),L(),()=>{document.removeEventListener("pointerdown",b),window.removeEventListener("resize",L),window.removeEventListener("scroll",L,!0)}},[w,p,L]);function A(){B(new Set(e.names)),o(""),L(),g(!0)}function $(){B(new Set(e.names)),o(""),g(!1)}function H(b){B(I=>{let d=new Set(I);return d.has(b)?d.delete(b):d.add(b),d})}async function K(){let b=[...D].sort((I,d)=>I.localeCompare(d));try{await e.onSave(b),o(""),g(!1)}catch{}}let F=e.names.length===0?l("skills.pickerPlaceholder"):e.names.length===1?e.names[0]:l("skills.pickerSelectedCount",{count:e.names.length}),y=p?(0,s.jsxs)("div",{ref:f,className:"skills-multi-picker-popover",style:v?{left:v.left,top:v.top,width:v.width,height:v.height}:void 0,children:[(0,s.jsxs)("div",{className:"skills-multi-picker-head",children:[(0,s.jsxs)("label",{className:"skills-multi-picker-search",children:[(0,s.jsx)("span",{className:"skills-multi-picker-search-icon","aria-hidden":"true"}),(0,s.jsx)("input",{type:"search","data-action":"search-skills",autoFocus:!0,autoComplete:"off",value:S,placeholder:l("skills.pickerSearchPlaceholder"),onChange:b=>o(b.currentTarget.value),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),$())}})]}),(0,s.jsxs)("div",{className:"skills-multi-picker-meta",children:[(0,s.jsx)("span",{children:l("skills.pickerSelectionMeta",{selected:D.size,total:x.length})}),D.size>0?(0,s.jsx)("button",{type:"button",className:"skills-multi-picker-clear","data-action":"clear-skill-selection",onClick:()=>B(new Set),children:l("skills.pickerClear")}):null]})]}),(0,s.jsxs)("div",{className:"skills-multi-picker-options",role:"listbox","aria-label":l("skills.priority"),"aria-multiselectable":"true",children:[E.map(b=>{let I=D.has(b.name),d=!e.installedNames.has(b.name);return(0,s.jsxs)("button",{type:"button",className:`skills-multi-picker-option${I?" selected":""}${d?" dangling":""}`,role:"option","aria-selected":I,"data-skill-name":b.name,onClick:()=>H(b.name),children:[(0,s.jsx)("span",{className:"skills-multi-picker-check","aria-hidden":"true"}),(0,s.jsxs)("span",{className:"skills-multi-picker-option-copy",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("b",{children:b.name}),d?(0,s.jsx)("em",{children:l("skills.dangling")}):null]}),b.description?(0,s.jsx)("small",{children:b.description}):null]})]},b.name)}),E.length===0?(0,s.jsx)("p",{className:"skills-multi-picker-empty",children:l("skills.pickerNoResults")}):null]}),(0,s.jsxs)("footer",{className:"skills-multi-picker-actions",children:[(0,s.jsx)("button",{type:"button",className:"ghost","data-action":"cancel-skill-selection",disabled:e.busy,onClick:$,children:l("skills.cancel")}),(0,s.jsx)("button",{type:"button",className:"primary","data-action":"save-skill-selection",disabled:!T||e.busy,onClick:()=>{K()},children:e.busy?l("skills.saving"):l("skills.saveSelection")})]})]}):null;return(0,s.jsxs)("div",{ref:n,className:`skills-multi-picker${p?" open":""}`,"data-skill-picker":e.botId,children:[(0,s.jsxs)("button",{ref:m,type:"button",className:"skills-multi-picker-trigger","data-action":"open-skill-picker","aria-haspopup":"listbox","aria-expanded":p,disabled:e.busy,onClick:()=>p?$():A(),children:[(0,s.jsxs)("span",{className:"skills-multi-picker-trigger-copy",children:[(0,s.jsx)("b",{children:F}),(0,s.jsx)("small",{children:l("skills.pickerTriggerHint")})]}),(0,s.jsx)("span",{className:"skills-multi-picker-chevron","aria-hidden":"true"})]}),y&&typeof document<"u"?(0,Bl.createPortal)(y,document.body):y]})}function Ys(e){let l=Z(),{bot:n,installedNames:m,skills:f,status:p,busyKey:g,onSave:S}=e,o=n.botName??n.larkAppId,D=ke(n.skills);return n.error?(0,s.jsxs)("article",{className:"bd-card skills-bot-card","data-appid":n.larkAppId,children:[(0,s.jsxs)("header",{children:[(0,s.jsx)(Ye,{html:Ve({name:o,larkAppId:n.larkAppId,size:"sm"})}),(0,s.jsx)("strong",{children:o})]}),(0,s.jsx)("p",{className:"hint-warn-inline",children:n.error})]}):(0,s.jsxs)("article",{className:"bd-card skills-bot-card","data-appid":n.larkAppId,children:[(0,s.jsxs)("header",{className:"skills-bot-head",children:[(0,s.jsx)(Ye,{html:Ve({name:o,larkAppId:n.larkAppId,size:"sm",dot:"ok"})}),(0,s.jsxs)("div",{className:"skills-bot-title-line",children:[(0,s.jsx)("strong",{children:o}),(0,s.jsx)("span",{className:"skills-count-pill",children:l("skills.skillCount",{count:D.length})})]})]}),(0,s.jsxs)("section",{className:"skills-policy-panel",children:[(0,s.jsx)("div",{className:"skills-priority-head",children:(0,s.jsx)("h3",{className:"skills-priority-title",children:l("skills.priority")})}),(0,s.jsx)(Ps,{botId:n.larkAppId,names:D,installedNames:m,skills:f,busy:g===`${n.larkAppId}:set`,onSave:B=>S(n.larkAppId,B)})]}),(0,s.jsx)("span",{className:tl(p),"data-bot-status":!0,children:p?.text??""})]})}function et(e){return fl(e,(0,s.jsx)(Is,{}))}export{Ys as BotPolicyCard,Ns as InstalledSkillsLibrary,ws as RemoveSkillsDialog,Ps as SkillMultiPicker,ys as SkillSegmented,Ss as SkillsInstallPanel,Is as SkillsPage,et as renderSkillsPage};