adam-agent-server 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +8 -0
  2. package/dist/App-5QZKMPRM.js +13 -0
  3. package/dist/adam-tools-FSI5XKDL.js +1 -0
  4. package/dist/{approval-handler-PB7PSLUS.js → approval-handler-JYCGXQUE.js} +1 -1
  5. package/dist/audit-manager-CLKTJPLM.js +1 -0
  6. package/dist/bree-engine-XJR5TKVC.js +1 -0
  7. package/dist/channels-DY2OW7YQ.js +1 -0
  8. package/dist/{channels-ULFUCUUZ.js → channels-ZNMTMMCY.js} +1 -1
  9. package/dist/{chunk-BQ3ZAYHC.js → chunk-3HZE5DQZ.js} +1 -1
  10. package/dist/chunk-3IQADR6L.js +144 -0
  11. package/dist/{chunk-NASJH4NT.js → chunk-3N7MGASP.js} +1 -1
  12. package/dist/{chunk-TAF2DBBC.js → chunk-56QP5ZHF.js} +7 -7
  13. package/dist/{chunk-PG6LMSX6.js → chunk-5AUQIK3Q.js} +1 -1
  14. package/dist/{chunk-NUITL62I.js → chunk-6M2QCKAS.js} +1 -1
  15. package/dist/{chunk-WMB7P64J.js → chunk-6XVWIRR2.js} +1 -1
  16. package/dist/{chunk-5EPG2US5.js → chunk-7F4SZXI2.js} +39 -10
  17. package/dist/{chunk-JJH2RCVC.js → chunk-7WJF65TQ.js} +1 -1
  18. package/dist/{chunk-RZ7LCZVK.js → chunk-ARQF52V6.js} +1 -1
  19. package/dist/{chunk-NWMOV23A.js → chunk-C2SD2NMZ.js} +1 -1
  20. package/dist/{chunk-2L2347UQ.js → chunk-DKMF4B33.js} +1 -1
  21. package/dist/{chunk-EQZFOBAJ.js → chunk-EJBGJLA2.js} +1 -1
  22. package/dist/{chunk-T33BLZV2.js → chunk-HSEP6LNQ.js} +1 -1
  23. package/dist/{chunk-GSFLLRS7.js → chunk-IZ3WZHCM.js} +1 -1
  24. package/dist/chunk-J4Y54LIC.js +50 -0
  25. package/dist/{chunk-AQ3ASS4B.js → chunk-KO7XBNPV.js} +1 -1
  26. package/dist/{chunk-RI3V72RP.js → chunk-KUJFQDT5.js} +2 -2
  27. package/dist/{chunk-DVN3BFPP.js → chunk-LV4XLPCD.js} +1 -1
  28. package/dist/chunk-MYVYH4PQ.js +77 -0
  29. package/dist/chunk-OFTIPZTH.js +1 -0
  30. package/dist/{chunk-K4C43YDD.js → chunk-OY2KVSIX.js} +1 -1
  31. package/dist/{chunk-IKPYPZ64.js → chunk-PFYYS7CI.js} +1 -1
  32. package/dist/chunk-QMW7VEPC.js +0 -0
  33. package/dist/{chunk-A5OCDYTW.js → chunk-QPIWPQWM.js} +1 -1
  34. package/dist/chunk-S6OV7Z6K.js +1 -0
  35. package/dist/{chunk-2YTDCR6A.js → chunk-TTP7QRAQ.js} +1 -1
  36. package/dist/{chunk-B6LOT5CG.js → chunk-UQDC3X6O.js} +1 -1
  37. package/dist/{chunk-M4YI4WVX.js → chunk-UYOLAFUR.js} +1 -1
  38. package/dist/chunk-VPZSOYE5.js +6 -0
  39. package/dist/{chunk-5QZXYKMS.js → chunk-W7U3ASGR.js} +1 -1
  40. package/dist/chunk-XIQVXRZH.js +27 -0
  41. package/dist/{chunk-FPZEZYUB.js → chunk-XTOOD44S.js} +1 -1
  42. package/dist/{chunk-6KF7OO2B.js → chunk-YKMWAVUH.js} +1 -1
  43. package/dist/{chunk-UQJZU3R5.js → chunk-YVVKUPGL.js} +1 -1
  44. package/dist/{chunk-HQRUJQN7.js → chunk-YWUX3ZTO.js} +4 -4
  45. package/dist/cli.js +2 -2
  46. package/dist/{config-HBQPBIWL.js → config-CILWJYZB.js} +1 -1
  47. package/dist/config-W2OD7PXZ.js +1 -0
  48. package/dist/{db-QEWTZGU3.js → db-JO24ZLIN.js} +1 -1
  49. package/dist/{delivery-log-AC476GX7.js → delivery-log-QPQM5YU7.js} +1 -1
  50. package/dist/engine-ZAPYG7G4.js +1 -0
  51. package/dist/{evolution-audit-XMBDUN3T.js → evolution-audit-ZLYQ3ZYV.js} +1 -1
  52. package/dist/{external-api-V74YTLBY.js → external-api-QKRNGSYS.js} +1 -1
  53. package/dist/index.js +20 -16
  54. package/dist/{learner-VCS3Q7BR.js → learner-ACHENH6R.js} +1 -1
  55. package/dist/{memories-VMOGFVPU.js → memories-LXH4VHCH.js} +1 -1
  56. package/dist/{memory-extractor-4WJNHYWR.js → memory-extractor-URH4YHK3.js} +2 -2
  57. package/dist/memory-service-23P6VNKZ.js +1 -0
  58. package/dist/outbound-gateway-Y3P3T3VH.js +1 -0
  59. package/dist/presets-XR2OBXUP.js +1 -0
  60. package/dist/role-presets-DYWDEQYU.js +1 -0
  61. package/dist/role-workspace-LHW7AWPF.js +1 -0
  62. package/dist/{roles-ZYCFQMAY.js → roles-DRPLO4LY.js} +1 -1
  63. package/dist/{runtime-VDBZZ4KG.js → runtime-YPBWWMXW.js} +1 -1
  64. package/dist/session-manager-Z6K4U5X7.js +1 -0
  65. package/dist/{task-templates-4KCZOUN5.js → task-templates-4DWXHLFZ.js} +1 -1
  66. package/dist/workflow-executor-6ZMNL34C.js +1 -0
  67. package/package.json +2 -1
  68. package/web/dist/assets/{AlertDialog-B1zj0Qs3.js → AlertDialog-DhA65f_0.js} +1 -1
  69. package/web/dist/assets/{Button-BehrGSvy.js → Button-CYDgoTTo.js} +1 -1
  70. package/web/dist/assets/{Card-B5E56u94.js → Card-DDGXsHus.js} +1 -1
  71. package/web/dist/assets/{ChannelDetail-BaSlX2yb.js → ChannelDetail-Bb8P8It_.js} +1 -1
  72. package/web/dist/assets/{Channels-CLhgGEmS.js → Channels-8j28oydE.js} +2 -2
  73. package/web/dist/assets/{Chat-BZpf1DSF.js → Chat-BZwLDoYO.js} +2 -2
  74. package/web/dist/assets/{Dashboard-HR4Qmdwg.js → Dashboard-Cv0AtO-o.js} +1 -1
  75. package/web/dist/assets/{EmptyState-tTclFq_B.js → EmptyState-EuQHAv5Y.js} +1 -1
  76. package/web/dist/assets/{EnvVarEditor-BzJNsDt0.js → EnvVarEditor-r-l-u4V7.js} +1 -1
  77. package/web/dist/assets/{EventDefDetail-CjoqsH0e.js → EventDefDetail-asUFrbQE.js} +1 -1
  78. package/web/dist/assets/Events-DtkHL-r2.js +1 -0
  79. package/web/dist/assets/{Evolution-CUn8g34X.js → Evolution-DIqYOSb8.js} +1 -1
  80. package/web/dist/assets/FeatureRequests-BxPqLR1x.js +1 -0
  81. package/web/dist/assets/{GoalDetail-DgPvXb6z.js → GoalDetail-Bkvgg6uI.js} +1 -1
  82. package/web/dist/assets/Goals-CkKJDCiU.js +1 -0
  83. package/web/dist/assets/{Logs-CvFC-GbD.js → Logs-DnaaHV0Y.js} +1 -1
  84. package/web/dist/assets/{Memories-B5pvI6Oj.js → Memories-Dq9S-Tsi.js} +1 -1
  85. package/web/dist/assets/Mistakes-D5lW31Co.js +1 -0
  86. package/web/dist/assets/{NotFound-D-OII_Lp.js → NotFound-gJVrOtER.js} +1 -1
  87. package/web/dist/assets/{PageHeader-B2CgcZ-t.js → PageHeader-CugYeCci.js} +1 -1
  88. package/web/dist/assets/Plugins-CoRmK2UG.js +1 -0
  89. package/web/dist/assets/{RoleDetail-BBJxaZip.js → RoleDetail-BHJA_PAn.js} +2 -2
  90. package/web/dist/assets/Roles-EBUueS_P.js +1 -0
  91. package/web/dist/assets/{SectionHeader-CmXz6PM3.js → SectionHeader-DihC0CnO.js} +1 -1
  92. package/web/dist/assets/Settings-DZHAGazz.js +1 -0
  93. package/web/dist/assets/{Strategies-Ddb5HiUS.js → Strategies-3IV9eueQ.js} +1 -1
  94. package/web/dist/assets/{Switch-yrTepsdl.js → Switch-B3w5KMMc.js} +1 -1
  95. package/web/dist/assets/{Table-CXAcZ8Ru.js → Table-Cf6m8zLu.js} +1 -1
  96. package/web/dist/assets/{TaskDetail-CHwHgfZq.js → TaskDetail-BmXaH3sx.js} +2 -2
  97. package/web/dist/assets/Work-CvQrOKtL.js +1 -0
  98. package/web/dist/assets/api-D-UzHSDq.js +1 -0
  99. package/web/dist/assets/index-BsKlGx3x.js +2 -0
  100. package/web/dist/assets/index-EqsPGp9a.css +2 -0
  101. package/web/dist/assets/{useIsMobileLayout-dYzXP1EC.js → useIsMobileLayout-2GbB90oO.js} +1 -1
  102. package/web/dist/assets/{vendor-icons-Dk0hMuJz.js → vendor-icons-PF9RcPJx.js} +1 -1
  103. package/web/dist/assets/{vendor-react-C6faO6LO.js → vendor-react-Cxy4EVtR.js} +1 -1
  104. package/web/dist/assets/{vendor-state-DahK0J-G.js → vendor-state-aQJ7d4tA.js} +1 -1
  105. package/web/dist/index.html +8 -8
  106. package/dist/App-ZRCRM7WR.js +0 -13
  107. package/dist/adam-automator-skills-EZGBICHT.js +0 -18
  108. package/dist/adam-tools-V5LPU47X.js +0 -1
  109. package/dist/audit-manager-BSBBDUER.js +0 -1
  110. package/dist/bree-engine-7S33CWS7.js +0 -1
  111. package/dist/channels-SITUUC4J.js +0 -1
  112. package/dist/chunk-4PQHGLZH.js +0 -99
  113. package/dist/chunk-5XOTPEAK.js +0 -6
  114. package/dist/chunk-BCH2HAIM.js +0 -23
  115. package/dist/chunk-GSMC3VUM.js +0 -1
  116. package/dist/chunk-IZNEOYRP.js +0 -1
  117. package/dist/chunk-QGYDGZSC.js +0 -49
  118. package/dist/chunk-ULTK7RD6.js +0 -27
  119. package/dist/config-ZBNGRASI.js +0 -1
  120. package/dist/engine-6K4RG644.js +0 -1
  121. package/dist/memory-service-ZS6MBUIC.js +0 -1
  122. package/dist/outbound-gateway-H7RFG6D2.js +0 -1
  123. package/dist/role-presets-XAEOYEAW.js +0 -1
  124. package/dist/role-workspace-NKGAH6J6.js +0 -1
  125. package/dist/session-manager-COLCNIB7.js +0 -1
  126. package/dist/workflow-executor-Z7JFMR56.js +0 -1
  127. package/web/dist/assets/Events-IeznRpCj.js +0 -1
  128. package/web/dist/assets/Goals-DYrggK-M.js +0 -1
  129. package/web/dist/assets/Plugins-BuE7GImW.js +0 -1
  130. package/web/dist/assets/Roles-C5eVA6LM.js +0 -1
  131. package/web/dist/assets/Settings-BblOdOih.js +0 -1
  132. package/web/dist/assets/Work-Corw0ITh.js +0 -1
  133. package/web/dist/assets/api-Bux34u4-.js +0 -1
  134. package/web/dist/assets/index-B3_4_qY6.js +0 -2
  135. package/web/dist/assets/index-Cu5neZGw.css +0 -2
@@ -1,49 +0,0 @@
1
- import{e as J}from"./chunk-ULTK7RD6.js";import{i as x,j as v,q as b}from"./chunk-6KF7OO2B.js";import{b as y}from"./chunk-K4C43YDD.js";import{a as u}from"./chunk-L7JP7DUO.js";import{p as C}from"./chunk-DVN3BFPP.js";import{c as _,d as l,f as g,h as A}from"./chunk-5XOTPEAK.js";import{d as k}from"./chunk-PG6LMSX6.js";import{o as I,r as W}from"./chunk-HQRUJQN7.js";import{c as p,h as T}from"./chunk-MRTJFYPR.js";T();W();import{v4 as m}from"uuid";import{CronExpressionParser as S}from"cron-parser";T();import{v4 as D}from"uuid";var d=p("scheduler"),R=new J;async function O(n,t={}){let e=t.executionId??D();if(d.info({templateName:n.name,executionId:e,trigger:t.triggerContext},"Dispatching template"),n.goalIds&&n.goalIds.length>0){for(let r of n.goalIds){let o=v(r);if(!o){d.warn({goalId:r,templateId:n.id},"Goal reference not found, skipping");continue}let c=D();x({id:c,name:o.name,description:o.description,roleId:o.roleId,metricType:o.metricType,targetValue:o.targetValue,currentValue:0,deadline:o.deadline,budgetUsd:o.budgetUsd,status:"active",createdAt:Date.now(),sourceSessionId:n.sourceSessionId,deliverTo:n.deliverTo,reportTo:n.reportTo});let a=await b({prompt:`Decompose and execute goal: ${o.name}. ${o.description??""}`,roleId:n.rolePreference??o.roleId,config:{...k()},deliverTo:n.deliverTo,reportTo:n.reportTo,sourceSessionId:n.sourceSessionId,parentId:c,templateId:n.id});if(!a.ok){d.error({templateId:n.id,sourceGoalId:r,newGoalId:c,code:a.code,reason:a.reason},"Decomposition task admission failed");continue}d.info({templateId:n.id,sourceGoalId:r,newGoalId:c,taskId:a.taskId},"Goal reference triggered, dispatched decomposition task")}return}let s=await R.execute(n,e,{eventId:t.triggerContext?.eventId});d.info({templateName:n.name,executionId:e,status:s.status,steps:s.stepResults.size},"Workflow execution finished")}var i=p("scheduler"),f="ai-hourly-digest";function E(){if(l(f)){i.debug({templateId:f},"Built-in template already exists");return}let t={id:f,name:"AI Hourly Digest",description:"\u6BCF\u5C0F\u65F6\u641C\u7D22 AI \u524D\u6CBF\u6587\u7AE0\uFF0C\u603B\u7ED3\u540E\u4FDD\u5B58\u5230 Omnifocus",trigger:{type:"cron",cron:"0 * * * *"},enabled:!0,steps:[{id:"search_ai_news",autoSelectRole:!0,requirements:{},prompt:`\u641C\u7D22\u8FC7\u53BB 24 \u5C0F\u65F6\u5185\u5173\u4E8E AI/\u4EBA\u5DE5\u667A\u80FD\u7684\u6700\u65B0\u524D\u6CBF\u6587\u7AE0\u3002
2
-
3
- \u641C\u7D22\u6765\u6E90:
4
- 1. Hacker News AI \u677F\u5757 (https://news.ycombinator.com/front?day=1)
5
- 2. ArXiv cs.AI \u6700\u65B0\u8BBA\u6587 (https://arxiv.org/list/cs.AI/recent)
6
- 3. Reddit r/MachineLearning \u70ED\u95E8\u5E16\u5B50
7
-
8
- \u627E\u51FA\u4E00\u7BC7\u6700\u6709\u4EF7\u503C\u3001\u6700\u6709\u6280\u672F\u6DF1\u5EA6\u7684\u6587\u7AE0\u3002
9
-
10
- \u8F93\u51FA\u683C\u5F0F:
11
- - \u6807\u9898\uFF1A[\u6587\u7AE0\u6807\u9898]
12
- - \u6765\u6E90\uFF1A[\u7F51\u7AD9/\u5E73\u53F0\u540D\u79F0]
13
- - \u94FE\u63A5\uFF1A[\u5B8C\u6574 URL]
14
- - \u6838\u5FC3\u4EF7\u503C\uFF1A[1-2 \u53E5\u8BDD\u8BF4\u660E\u4E3A\u4EC0\u4E48\u8FD9\u7BC7\u6587\u7AE0\u503C\u5F97\u770B]`},{id:"summarize_article",dependsOn:["search_ai_news"],autoSelectRole:!0,requirements:{},prompt:`\u9605\u8BFB\u5E76\u603B\u7ED3\u8FD9\u7BC7\u6587\u7AE0\u3002
15
-
16
- \u6587\u7AE0\u4FE1\u606F:
17
- {{search_ai_news.result}}
18
-
19
- \u8BF7:
20
- 1. \u7528 WebFetch \u83B7\u53D6\u6587\u7AE0\u5B8C\u6574\u5185\u5BB9
21
- 2. \u63D0\u53D6\u6838\u5FC3\u89C2\u70B9\u548C\u6280\u672F\u7EC6\u8282
22
- 3. \u7528\u4E2D\u6587\u5199\u51FA 300-500 \u5B57\u7684\u603B\u7ED3
23
-
24
- \u603B\u7ED3\u7ED3\u6784:
25
- ## \u6838\u5FC3\u53D1\u73B0
26
- [\u6587\u7AE0\u6700\u91CD\u8981\u7684\u53D1\u73B0/\u521B\u65B0\u70B9]
27
-
28
- ## \u6280\u672F\u7EC6\u8282
29
- [\u5173\u952E\u7684\u6280\u672F\u65B9\u6CD5/\u5B9E\u73B0\u7EC6\u8282]
30
-
31
- ## \u5F71\u54CD/\u610F\u4E49
32
- [\u8FD9\u9879\u5DE5\u4F5C\u7684\u610F\u4E49\u6216\u5BF9\u884C\u4E1A\u7684\u5F71\u54CD]
33
-
34
- ## \u539F\u6587\u94FE\u63A5
35
- [\u6587\u7AE0 URL]`},{id:"save_to_omnifocus",dependsOn:["summarize_article"],autoSelectRole:!0,requirements:{},prompt:`\u5C06\u6587\u7AE0\u603B\u7ED3\u4FDD\u5B58\u5230 Omnifocus\u3002
36
-
37
- \u603B\u7ED3\u5185\u5BB9:
38
- {{summarize_article.result}}
39
-
40
- \u63D0\u53D6\u6587\u7AE0\u6807\u9898\u548C\u5B8C\u6574\u603B\u7ED3\uFF0C\u7136\u540E\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u6DFB\u52A0\u5230 Omnifocus Inbox\uFF1A
41
-
42
- osascript /Users/norvyn/Code/Projects/Adam/scripts/add-to-omnifocus.applescript "[\u6587\u7AE0\u6807\u9898] AI \u524D\u6CBF\u901F\u9012" "[\u5B8C\u6574\u603B\u7ED3\u5185\u5BB9]"
43
-
44
- \u6CE8\u610F\uFF1A
45
- - \u5C06 [\u6587\u7AE0\u6807\u9898] \u66FF\u6362\u4E3A\u5B9E\u9645\u6807\u9898
46
- - \u5C06 [\u5B8C\u6574\u603B\u7ED3\u5185\u5BB9] \u66FF\u6362\u4E3A\u5B8C\u6574\u7684\u603B\u7ED3\u6587\u672C\uFF08\u5305\u542B\u6838\u5FC3\u53D1\u73B0\u3001\u6280\u672F\u7EC6\u8282\u3001\u5F71\u54CD/\u610F\u4E49\u548C\u539F\u6587\u94FE\u63A5\uFF09
47
- - \u603B\u7ED3\u5185\u5BB9\u4F7F\u7528\u6362\u884C\u7B26\u5206\u9694\u5404\u90E8\u5206
48
-
49
- \u5B8C\u6210\u540E\u8F93\u51FA\uFF1A\u5DF2\u4FDD\u5B58\u5230 Omnifocus\uFF1A[\u4EFB\u52A1\u6807\u9898]`}],config:{timeout:300},tags:["ai","digest","hourly","automation"],createdAt:Date.now()};_(t),i.info({templateId:f,cron:"0 * * * *"},"Registered built-in AI Hourly Digest template")}var P=class{cronJobs=new Map;started=!1;taskCompletionHandler=null;workflowCompletionHandler=null;async start(){if(this.started)return;this.started=!0,E();let t=g(!0),e=0;for(let r of t)r.trigger.type==="cron"&&r.trigger.cron&&(this.scheduleCronJob(r),e++);let s=0;for(let r of t)r.trigger.type==="once"&&r.trigger.runAt&&(this.scheduleOnceJob(r.id),s++);this.taskCompletionHandler=r=>{r.newStatus==="completed"&&this.checkTemplateCompleteTriggers(r.taskId).catch(o=>{i.error({taskId:r.taskId,error:o},"Template-complete trigger check failed")})},u.on("task_status_change",this.taskCompletionHandler),this.workflowCompletionHandler=r=>{(r.status==="completed"||r.status==="partial")&&this.checkWorkflowCompleteTriggers(r.templateId).catch(o=>{i.error({templateId:r.templateId,error:o},"Workflow-complete trigger check failed")})},u.on("workflow_status_change",this.workflowCompletionHandler),this.cronJobs.set("memory-cleanup",setInterval(()=>{this.runMemoryCleanup()},36e5)),i.info({cronCount:e,onceCount:s},"Bree engine started with cron jobs + memory cleanup")}runMemoryCleanup(){try{let t=I(void 0,1e3,0),e=0;for(let s of t)e+=C(s.id);e>0&&i.info({totalCleaned:e},"Memory cleanup completed")}catch(t){i.warn({error:t},"Memory cleanup failed")}}async stop(){for(let[,t]of this.cronJobs)clearTimeout(t),clearInterval(t);this.cronJobs.clear(),this.taskCompletionHandler&&(u.off("task_status_change",this.taskCompletionHandler),this.taskCompletionHandler=null),this.workflowCompletionHandler&&(u.off("workflow_status_change",this.workflowCompletionHandler),this.workflowCompletionHandler=null),this.started=!1,i.info("Bree engine stopped")}scheduleCronJob(t){let e=`template-${t.id}`;this.cronJobs.has(e)&&(clearTimeout(this.cronJobs.get(e)),this.cronJobs.delete(e));let s;try{s=S.parse(t.trigger.cron)}catch{i.warn({templateId:t.id,cron:t.trigger.cron},"Invalid cron expression");return}let r=()=>{let h=s.next().getTime()-Date.now();return Math.max(h,1e3)},o=()=>{this.executeCronTrigger(t.id).catch(h=>{i.error({templateId:t.id,error:h},"Cron trigger failed")});let w=setTimeout(o,r());this.cronJobs.set(e,w)},c=r(),a=setTimeout(o,c);this.cronJobs.set(e,a),i.debug({jobName:e,nextRun:new Date(Date.now()+c).toISOString()},"Scheduled cron job")}async executeCronTrigger(t){let e=l(t);!e||!e.enabled||(i.info({templateName:e.name},"Cron triggered"),await this.executeWorkflow(e,m()))}async scheduleJob(t){let e=l(t);e&&e.trigger.type==="cron"&&e.trigger.cron&&this.scheduleCronJob(e)}async unscheduleJob(t){let e=`template-${t}`,s=this.cronJobs.get(e);s&&(clearTimeout(s),this.cronJobs.delete(e))}async runNow(t){let e=l(t);if(!e)throw new Error(`Template ${t} not found`);let s=m();return this.executeWorkflow(e,s).catch(r=>{i.error({templateId:t,error:r},"Workflow execution failed")}),s}async checkTemplateCompleteTriggers(t){let e=y(t);if(!e||!e.templateId)return;let r=g(!0).filter(o=>o.trigger.type!=="template_complete"||!o.trigger.event?!1:o.trigger.event===`template_complete:${e.templateId}`);for(let o of r)i.info({templateName:o.name,sourceTemplateId:e.templateId},"Template-complete trigger matched"),await this.executeWorkflow(o,m())}async executeWorkflow(t,e){await O(t,{executionId:e,triggerContext:{source:"bree"}})}async checkWorkflowCompleteTriggers(t){let s=g(!0).filter(r=>r.trigger.type!=="workflow_complete"||!r.trigger.event?!1:r.trigger.event===`workflow_complete:${t}`);for(let r of s)i.info({templateName:r.name,sourceTemplateId:t},"Workflow-complete trigger matched"),await this.executeWorkflow(r,m())}scheduleOnceJob(t){let e=l(t);if(!e||!e.enabled||e.trigger.type!=="once")return;let r=(e.trigger.runAt?new Date(e.trigger.runAt).getTime():0)-Date.now();if(r<=0){i.info({templateId:t,runAt:e.trigger.runAt},"Once-shot template past due, executing immediately"),this.executeOnceTrigger(t).catch(a=>{i.error({templateId:t,error:a},"Once trigger execution failed")});return}let o=`template-${t}`;this.cronJobs.has(o)&&clearTimeout(this.cronJobs.get(o));let c=setTimeout(()=>{this.cronJobs.delete(o),this.executeOnceTrigger(t).catch(a=>{i.error({templateId:t,error:a},"Once trigger execution failed")})},r);this.cronJobs.set(o,c),i.info({templateId:t,runAt:e.trigger.runAt,delayMs:r},"Scheduled once-shot job")}async executeOnceTrigger(t){let e=l(t);!e||!e.enabled||(i.info({templateName:e.name},"Once-shot triggered"),await this.executeWorkflow(e,m()),A(t),i.info({templateId:t},"Once-shot template auto-disabled after execution"))}},H=null;function ee(){return H}function te(n){H=n}export{O as a,P as b,ee as c,te as d};
@@ -1,27 +0,0 @@
1
- import{q as C}from"./chunk-6KF7OO2B.js";import{a as D}from"./chunk-N4ES7TCL.js";import{b as v}from"./chunk-K4C43YDD.js";import{b as A}from"./chunk-RI3V72RP.js";import{b as T}from"./chunk-GSFLLRS7.js";import{a as S}from"./chunk-L7JP7DUO.js";import{d as E}from"./chunk-PG6LMSX6.js";import{l as x,r as F}from"./chunk-HQRUJQN7.js";import{b as w,d as $}from"./chunk-5EPG2US5.js";import{c as b,h as N}from"./chunk-MRTJFYPR.js";N();F();$();function O(u){return{id:u.id,templateId:u.template_id,status:u.status,stepStatuses:JSON.parse(u.step_statuses),startedAt:u.started_at,completedAt:u.completed_at??void 0,error:u.error??void 0,eventId:u.event_id??void 0}}function M(u,e,t){w().prepare(`
2
- INSERT INTO workflow_executions (id, template_id, status, step_statuses, started_at, event_id)
3
- VALUES (?, ?, 'running', '{}', ?, ?)
4
- `).run(u,e,Date.now(),t??null)}function h(u){let t=w().prepare("SELECT * FROM workflow_executions WHERE id = ?").get(u);return t?O(t):void 0}function R(u,e){let t=w(),n=[],s=[];e.status!==void 0&&(n.push("status = ?"),s.push(e.status)),e.stepStatuses!==void 0&&(n.push("step_statuses = ?"),s.push(JSON.stringify(e.stepStatuses))),e.completedAt!==void 0&&(n.push("completed_at = ?"),s.push(e.completedAt)),e.error!==void 0&&(n.push("error = ?"),s.push(e.error)),n.length!==0&&(s.push(u),t.prepare(`UPDATE workflow_executions SET ${n.join(", ")} WHERE id = ?`).run(...s))}function L(u,e=50,t=0){let n=w(),s="SELECT * FROM workflow_executions",a=[];return u&&(s+=" WHERE template_id = ?",a.push(u)),s+=" ORDER BY started_at DESC LIMIT ? OFFSET ?",a.push(e,t),n.prepare(s).all(...a).map(O)}function B(u,e=20,t=0){return w().prepare(`
5
- SELECT we.id AS execution_id,
6
- we.template_id,
7
- tt.name AS template_name,
8
- we.status,
9
- we.started_at,
10
- we.completed_at,
11
- we.error,
12
- we.event_id,
13
- e.occurred_at AS event_occurred_at,
14
- e.payload AS event_payload
15
- FROM workflow_executions we
16
- LEFT JOIN task_templates tt ON tt.id = we.template_id
17
- INNER JOIN events e ON e.id = we.event_id
18
- WHERE e.event_def_id = ?
19
- ORDER BY we.started_at DESC
20
- LIMIT ? OFFSET ?
21
- `).all(u,e,t).map(a=>({executionId:a.execution_id,templateId:a.template_id,templateName:a.template_name,status:a.status,startedAt:a.started_at,completedAt:a.completed_at,error:a.error,eventId:a.event_id,eventOccurredAt:a.event_occurred_at,eventPayload:a.event_payload?JSON.parse(a.event_payload):null}))}var f=b("scheduler"),P=class{maxRetries;baseDelayMs;constructor(e){this.maxRetries=e?.maxRetries??3,this.baseDelayMs=e?.baseDelayMs??1e3}async execute(e,t,n){let s=E(),a={timeout:e.config?.timeout??s.timeout,approvalRequired:s.approvalRequired,approvalTimeout:s.approvalTimeout,plugins:e.config?.plugins,mcpServers:e.config?.mcpServers,model:e.config?.model??s.model,maxTurns:e.config?.maxTurns??s.maxTurns,maxBudgetUsd:e.config?.maxBudgetUsd??s.maxBudgetUsd,env:{...s.env,...e.config?.env},claudeCodePath:s.claudeCodePath},r={templateId:e.id,executionId:t,stepResults:new Map,stepStatuses:{},config:a,continueOnError:e.config?.continueOnError??!1,failedStepIds:new Set,rolePreference:e.rolePreference,deliverTo:e.deliverTo,reportTo:e.reportTo};M(t,e.id,n?.eventId),D(t),S.emit({type:"workflow_status_change",executionId:t,templateId:e.id,status:"running"});let i=this.groupIntoLayers(e.steps);for(let m of i){if(this.syncExternalState(r)==="cancelled")return this.finalizeCancelledWorkflow(e,r);let g=m.filter(l=>!this.shouldSkip(l,r)),_=m.filter(l=>this.shouldSkip(l,r));for(let l of _){let p={stepId:l.id,taskId:"",status:"skipped",error:"Skipped: dependency failed"};r.stepResults.set(l.id,p),r.stepStatuses[l.id]={taskId:"",status:"skipped",error:"Skipped: dependency failed"},f.info({stepId:l.id,executionId:t},"Step skipped due to failed dependency")}if(g.length===0)continue;let W=await Promise.allSettled(g.map(l=>this.executeStep(l,r)));if(this.syncExternalState(r)==="cancelled")return this.finalizeCancelledWorkflow(e,r);for(let l=0;l<g.length;l++){let p=g[l],k=W[l];if(k.status==="rejected"){f.error({stepId:p.id,error:k.reason},"Workflow step threw");let I={stepId:p.id,taskId:"",status:"failed",error:String(k.reason)};r.stepResults.set(p.id,I),r.failedStepIds.add(p.id),r.stepStatuses[p.id]={taskId:"",status:"failed",error:String(k.reason)}}let y=r.stepResults.get(p.id);if(y?.status==="failed"&&(r.failedStepIds.add(p.id),!r.continueOnError)){if(this.isWorkflowCancelled(r.executionId))return this.finalizeCancelledWorkflow(e,r);let I="failed";return R(t,{status:I,stepStatuses:r.stepStatuses,completedAt:Date.now(),error:y.error}),S.emit({type:"workflow_status_change",executionId:t,templateId:e.id,status:I}),f.warn({stepId:p.id,executionId:t},"Workflow step failed, workflow aborted"),{executionId:t,status:I,stepResults:r.stepResults}}}if(this.isWorkflowCancelled(r.executionId))return this.finalizeCancelledWorkflow(e,r);R(t,{stepStatuses:r.stepStatuses})}if(this.isWorkflowCancelled(r.executionId))return this.finalizeCancelledWorkflow(e,r);let d=r.failedStepIds.size>0,o=[...r.stepResults.values()].some(m=>m.status==="skipped"||m.status==="cancelled"),c=d||o?"partial":"completed";return R(t,{status:c,stepStatuses:r.stepStatuses,completedAt:Date.now()}),S.emit({type:"workflow_status_change",executionId:t,templateId:e.id,status:c}),f.info({executionId:t,status:c,completedSteps:r.stepResults.size,totalSteps:e.steps.length,failedSteps:r.failedStepIds.size},"Workflow completed"),await this.deliverWorkflowResult(r,c),{executionId:t,status:c,stepResults:r.stepResults}}groupIntoLayers(e){let t=new Map(e.map(i=>[i.id,i])),n=new Map,s=new Map;for(let i of e)n.set(i.id,0),s.set(i.id,[]);for(let i of e)if(i.dependsOn)for(let d of i.dependsOn)t.has(d)&&(n.set(i.id,(n.get(i.id)??0)+1),s.get(d)?.push(i.id));let a=[],r=new Set(e.map(i=>i.id));for(;r.size>0;){let i=[];for(let d of r)if((n.get(d)??0)===0){let o=t.get(d);o&&i.push(o)}if(i.length===0){f.warn({remaining:[...r]},"Cycle detected in step dependencies");for(let d of r){let o=t.get(d);o&&a.push([o])}break}a.push(i);for(let d of i){r.delete(d.id);for(let o of s.get(d.id)??[])n.set(o,(n.get(o)??0)-1)}}return a}syncExternalState(e){let t=h(e.executionId);if(t){for(let[n,s]of Object.entries(t.stepStatuses))(s.status==="skipped"||s.status==="failed"||s.status==="cancelled")&&!e.stepResults.has(n)&&!e.failedStepIds.has(n)&&(s.status==="skipped"?e.stepResults.set(n,{stepId:n,taskId:s.taskId,status:"skipped",error:s.error??"Manually skipped via API"}):s.status==="cancelled"?e.stepResults.set(n,{stepId:n,taskId:s.taskId,status:"cancelled",error:s.error??"Cancelled"}):(e.failedStepIds.add(n),e.stepResults.set(n,{stepId:n,taskId:s.taskId,status:"failed",error:s.error})),e.stepStatuses[n]=s,f.info({stepId:n,status:s.status,executionId:e.executionId},"Synced external step status from DB"));return t.status==="cancelled"?"cancelled":void 0}}shouldSkip(e,t){return e.dependsOn?e.dependsOn.some(n=>t.failedStepIds.has(n)?!0:t.stepResults.get(n)?.status==="skipped"):!1}async executeStep(e,t){let n=this.resolveVariables(e.prompt,t.stepResults),s=e.roleId??t.rolePreference,a=s?x(s):void 0,r=(e.config?.timeout??t.config?.timeout??600)*1e3,i="",d="failed",o;for(let l=1;l<=this.maxRetries;l++){let p=await C({prompt:n,roleId:s,requirements:e.requirements,autoSelectRole:e.autoSelectRole,config:{...t.config,...e.config?.timeout!==void 0?{timeout:e.config.timeout}:{},...e.config?.maxTurns!==void 0?{maxTurns:e.config.maxTurns}:{}},sourceSessionId:t.templateId,parentId:t.executionId,templateId:t.templateId,stepId:e.id});if(!p.ok){o=p;break}if(i=p.taskId,t.stepStatuses[e.id]={taskId:i,status:"running",roleId:s},f.debug({stepId:e.id,taskId:i,roleId:s,attempt:l},"Workflow step task created via admission"),d=await this.waitForTaskCompletion(i,r),d==="completed"||d==="cancelled")break;if(l<this.maxRetries){let k=this.baseDelayMs*Math.pow(2,l-1);f.info({stepId:e.id,attempt:l,maxRetries:this.maxRetries,delayMs:k},"Workflow step failed, retrying"),await this.sleep(k)}}if(o&&!o.ok){let l={stepId:e.id,taskId:"",status:"failed",roleId:s,roleName:a?.name,error:`Admission failed: ${o.reason}`,admissionError:{code:o.code,reason:o.reason,candidates:o.candidates?.map(p=>({roleId:p.roleId,name:p.name,fitScore:p.fitScore}))}};t.stepResults.set(e.id,l),t.stepStatuses[e.id]={taskId:"",status:"failed",roleId:s,error:o.reason},f.warn({stepId:e.id,admissionCode:o.code,reason:o.reason},"Workflow step admission failed");return}let c=v(i),m=h(t.executionId),g=m?.stepStatuses[e.id],_=d==="completed"?"completed":g?.status==="skipped"?"skipped":g?.status==="cancelled"||m?.status==="cancelled"?"cancelled":"failed",W={stepId:e.id,taskId:i,status:_,roleId:s,roleName:a?.name,result:c?.result,error:c?.error};t.stepResults.set(e.id,W),t.stepStatuses[e.id]={taskId:i,status:W.status,roleId:s,result:c?.result,error:c?.error}}async deliverWorkflowResult(e,t){let n=A();if(e.deliverTo&&e.deliverTo.length>0){let s=this.assembleWorkflowSummary(e);for(let a of e.deliverTo)if(a.type==="channel"){let r=T(a.channelId);try{await n.send({taskId:e.executionId,channelId:a.channelId,chatId:a.chatId,platform:r?.platform,content:s,messageType:"deliver"})}catch(i){f.error({executionId:e.executionId,channelId:a.channelId,error:i},"Workflow delivery failed")}}}if(e.reportTo&&e.reportTo.length>0){let s=[...e.stepResults.values()].filter(o=>o.status==="completed").length,a=e.failedStepIds.size,r=[...e.stepResults.values()].filter(o=>o.status==="skipped").length,i=e.stepResults.size,d=`Workflow ${t}: ${s}/${i} steps completed${a>0?`, ${a} failed`:""}${r>0?`, ${r} skipped`:""}`;for(let o of e.reportTo)if(o.type==="channel"){let c=T(o.channelId);try{await n.send({taskId:e.executionId,channelId:o.channelId,chatId:o.chatId,platform:c?.platform,content:d,messageType:"report"})}catch(m){f.error({executionId:e.executionId,channelId:o.channelId,error:m},"Workflow report delivery failed")}}}}assembleWorkflowSummary(e){let t=[];for(let[n,s]of e.stepResults){let a=s.status==="completed"?"OK":s.status==="skipped"?"SKIP":"FAIL",r=s.roleName?` (${s.roleName})`:"",i=s.result??s.error??"No output";t.push(`## [${a}] Step: ${n}${r}
22
-
23
- ${i}`)}return t.join(`
24
-
25
- ---
26
-
27
- `)}resolveVariables(e,t){return e.replace(/\{\{([^}]+)\.result\}\}/g,(n,s)=>t.get(s)?.result??`[no result from ${s}]`)}waitForTaskCompletion(e,t=6e5){return new Promise(n=>{let s=!1,a=Date.now(),r=()=>{s=!0,S.off("task_status_change",i)},i=o=>{s||o.taskId!==e||(o.newStatus==="completed"?(r(),n("completed")):o.newStatus==="failed"?(r(),n("failed")):o.newStatus==="cancelled"?(r(),n("cancelled")):o.newStatus==="blocked"&&(r(),n("blocked")))};S.on("task_status_change",i);let d=()=>{if(s)return;if(Date.now()-a>t){r(),n("failed");return}let o=v(e);if(!o){r(),n("failed");return}if(o.status==="completed"){r(),n("completed");return}if(o.status==="failed"){r(),n("failed");return}if(o.status==="cancelled"){r(),n("cancelled");return}if(o.status==="blocked"){r(),n("blocked");return}setTimeout(d,5e3)};setTimeout(d,100)})}sleep(e){return new Promise(t=>setTimeout(t,e))}isWorkflowCancelled(e){return h(e)?.status==="cancelled"}finalizeCancelledWorkflow(e,t){let n=h(t.executionId);return R(t.executionId,{status:"cancelled",stepStatuses:n?.stepStatuses??t.stepStatuses,completedAt:n?.completedAt??Date.now(),error:n?.error}),f.info({executionId:t.executionId,templateId:e.id},"Workflow cancelled"),{executionId:t.executionId,status:"cancelled",stepResults:t.stepResults}}};export{h as a,R as b,L as c,B as d,P as e};
@@ -1 +0,0 @@
1
- import{a as b,b as c,d,e}from"./chunk-PG6LMSX6.js";import{a}from"./chunk-UQJZU3R5.js";import"./chunk-7IFLU3CY.js";import"./chunk-GSMC3VUM.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{a as DEFAULT_CONFIG,e as getChatConfig,d as getDefaults,b as loadConfig,c as loadDefaultConfig};
@@ -1 +0,0 @@
1
- import{a,b,c,d}from"./chunk-EQZFOBAJ.js";import"./chunk-5QZXYKMS.js";import"./chunk-2YTDCR6A.js";import"./chunk-BQ3ZAYHC.js";import"./chunk-B6LOT5CG.js";import"./chunk-K4C43YDD.js";import"./chunk-RI3V72RP.js";import"./chunk-GSFLLRS7.js";import"./chunk-L7JP7DUO.js";import"./chunk-RZ7LCZVK.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{a as DeliveryEngine,b as getDeliveryEngine,c as initDeliveryEngine,d as stopDeliveryEngine};
@@ -1 +0,0 @@
1
- import{a,b,c}from"./chunk-IKPYPZ64.js";import"./chunk-SWP2JC54.js";import"./chunk-DVN3BFPP.js";import"./chunk-HQRUJQN7.js";import"./chunk-FPZEZYUB.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{b as getRelevantMemoryContext,a as queryMemory,c as queryMemoryByTier};
@@ -1 +0,0 @@
1
- import{a,b,c}from"./chunk-RI3V72RP.js";import"./chunk-GSFLLRS7.js";import"./chunk-L7JP7DUO.js";import"./chunk-RZ7LCZVK.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{a as OutboundGateway,b as getOutboundGateway,c as isRecentlySent};
@@ -1 +0,0 @@
1
- import{a,b,c,d,e}from"./chunk-BCH2HAIM.js";import"./chunk-WMB7P64J.js";import"./chunk-HQRUJQN7.js";import"./chunk-FPZEZYUB.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{a as CHAT_MANAGER_ROLE_ID,b as PRESET_ROLE_NAMES,e as ensureAdamAutomatorRole,d as initializeDefaultRoles,c as isPresetRole};
@@ -1 +0,0 @@
1
- import{e as a,f as b,g as c,h as d,j as e}from"./chunk-WMB7P64J.js";import"./chunk-HQRUJQN7.js";import"./chunk-FPZEZYUB.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";e();export{b as ensureRoleWorkspace,a as getRoleWorkspacePath,d as syncRoleSettings,c as writeRoleCLAUDEmd};
@@ -1 +0,0 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"./chunk-M4YI4WVX.js";import"./chunk-2YTDCR6A.js";import"./chunk-SWP2JC54.js";import"./chunk-B6LOT5CG.js";import"./chunk-L7JP7DUO.js";import"./chunk-DVN3BFPP.js";import"./chunk-PG6LMSX6.js";import"./chunk-UQJZU3R5.js";import"./chunk-7IFLU3CY.js";import"./chunk-GSMC3VUM.js";import"./chunk-HQRUJQN7.js";import"./chunk-FPZEZYUB.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{p as _resetForTest,e as archiveSession,b as createSession,g as deleteSession,c as getActiveSession,d as getSession,m as getTimeoutPollerInterval,i as incrementMessageCount,n as initSessionManager,j as listSessions,f as restoreSession,o as shutdownSessionManager,k as startTimeoutPoller,l as stopTimeoutPoller,h as touchSession,a as warmCache};
@@ -1 +0,0 @@
1
- import{e as a}from"./chunk-ULTK7RD6.js";import"./chunk-6KF7OO2B.js";import"./chunk-IZNEOYRP.js";import"./chunk-N4ES7TCL.js";import"./chunk-NWMOV23A.js";import"./chunk-2L2347UQ.js";import"./chunk-K4C43YDD.js";import"./chunk-RI3V72RP.js";import"./chunk-GSFLLRS7.js";import"./chunk-WMB7P64J.js";import"./chunk-L7JP7DUO.js";import"./chunk-RZ7LCZVK.js";import"./chunk-PG6LMSX6.js";import"./chunk-UQJZU3R5.js";import"./chunk-7IFLU3CY.js";import"./chunk-GSMC3VUM.js";import"./chunk-HQRUJQN7.js";import"./chunk-FPZEZYUB.js";import"./chunk-5EPG2US5.js";import"./chunk-WBAPIPST.js";import"./chunk-MRTJFYPR.js";import"./chunk-FCV2DPZQ.js";export{a as WorkflowExecutor};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{E as t,S as n,T as ee,ct as r,s as te,t as ne,y as re}from"./vendor-icons-Dk0hMuJz.js";import{d as ie,t as i}from"./vendor-react-C6faO6LO.js";import{a,c as ae,i as o,n as s,o as c,r as l,s as u,t as oe}from"./AlertDialog-B1zj0Qs3.js";import{t as d}from"./Button-BehrGSvy.js";import{t as f}from"./api-Bux34u4-.js";import{i as p,t as se}from"./index-B3_4_qY6.js";import{t as m}from"./Card-B5E56u94.js";import{t as ce}from"./SectionHeader-CmXz6PM3.js";import{a as le}from"./format-BUYXZqDw.js";import{t as ue}from"./EmptyState-tTclFq_B.js";import{a as de,i as h,n as fe,o as g,r as _,t as pe}from"./Table-CXAcZ8Ru.js";import{t as me}from"./Switch-yrTepsdl.js";var v=e(r(),1),y=i(),he={webhook:`info`,directory_watch:`warning`,cron:`success`,manual:`muted`};function b(e){let t=e.trim().split(/\s+/);return t.length===5?t.every(e=>/^(\*|(\*\/)?\d+(-\d+)?(,\d+(-\d+)?)*)$/.test(e)):!1}function ge(){let e=ie(),[r,i]=(0,v.useState)([]),[ge,_e]=(0,v.useState)(!0),[ve,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(``),[w,ye]=(0,v.useState)(`webhook`),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(``),[j,M]=(0,v.useState)(``),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(null),[L,R]=(0,v.useState)(``),[z,B]=(0,v.useState)(``),[V,be]=(0,v.useState)(`webhook`),[H,U]=(0,v.useState)(``),[W,G]=(0,v.useState)(``),[xe,K]=(0,v.useState)(``),[Se,q]=(0,v.useState)(!1),[J,Y]=(0,v.useState)(null),[X,Z]=(0,v.useState)(null),[Q,Ce]=(0,v.useState)(``),[we,Te]=(0,v.useState)(!1),$=(0,v.useCallback)(async()=>{_e(!0);try{i(await f(`/event-defs`))}catch{p.error(`Failed to load events`)}finally{_e(!1)}},[]);(0,v.useEffect)(()=>{$()},[$]);let Ee=async()=>{if(S.trim()){if(w===`cron`&&!b(k)){M(`Invalid cron expression (expected 5 fields: minute hour day month weekday)`);return}P(!0);try{let e={name:S.trim(),sourceType:w,description:T.trim()||void 0,enabled:!0};w===`directory_watch`&&D.trim()?e.sourceConfig={path:D.trim(),stability_delay_ms:5e3}:w===`cron`&&k.trim()&&(e.sourceConfig={cron:k.trim()}),await f(`/event-defs`,{method:`POST`,body:JSON.stringify(e)}),C(``),E(``),O(``),A(``),M(``),x(!1),$(),p.success(`Event created`)}catch(e){let t=e instanceof Error?e.message:`Failed to create event`;p.error(t)}finally{P(!1)}}},De=e=>{I(e.id),R(e.name),B(e.description??``),be(e.sourceType),U(e.sourceConfig?.path??``),G(e.sourceConfig?.cron??``),K(``)},Oe=async()=>{if(!(!F||!L.trim())){if(V===`cron`&&!b(W)){K(`Invalid cron expression`);return}q(!0);try{let e={name:L.trim(),description:z.trim()||void 0};V===`directory_watch`?e.sourceConfig={path:H.trim(),stability_delay_ms:5e3}:V===`cron`&&(e.sourceConfig={cron:W.trim()}),await f(`/event-defs/${F}`,{method:`PATCH`,body:JSON.stringify(e)}),I(null),$(),p.success(`Event updated`)}catch(e){let t=e instanceof Error?e.message:`Failed to update event`;p.error(t)}finally{q(!1)}}},ke=async e=>{try{await f(`/event-defs/${e.id}`,{method:`PATCH`,body:JSON.stringify({enabled:!e.enabled})}),$()}catch(e){let t=e instanceof Error?e.message:`Failed to toggle`;p.error(t)}},Ae=async e=>{try{await f(`/event-defs/${e}`,{method:`DELETE`}),Y(null),$(),p.success(`Event deleted`)}catch(e){let t=e instanceof Error?e.message:`Failed to delete`;p.error(t)}},je=async e=>{Te(!0);try{let t={};if(Q.trim())try{t.payload=JSON.parse(Q)}catch{t.payload={raw:Q}}await f(`/event-defs/${e}/fire`,{method:`POST`,body:JSON.stringify(t)}),Z(null),Ce(``),p.success(`Event fired`)}catch(e){let t=e instanceof Error?e.message:`Failed to fire event`;p.error(t)}finally{Te(!1)}},Me=r.find(e=>e.id===J);return(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsx)(ce,{title:`Events`,description:`Event definitions that trigger automations. Configure webhooks, schedules, or file watchers.`,compact:!0,action:(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(d,{variant:`ghost`,size:`sm`,onClick:()=>void $(),children:(0,y.jsx)(re,{size:14})}),(0,y.jsxs)(d,{size:`sm`,onClick:()=>x(!ve),children:[(0,y.jsx)(n,{size:14}),`New Event`]})]})}),ve&&(0,y.jsxs)(m,{className:`space-y-3`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium text-[var(--app-text)]`,children:`New Event`}),(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Event name`,value:S,onChange:e=>C(e.target.value)}),(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Description (optional)`,value:T,onChange:e=>E(e.target.value)}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Source:`}),(0,y.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:w,onChange:e=>ye(e.target.value),children:[(0,y.jsx)(`option`,{value:`webhook`,children:`Webhook (HTTP)`}),(0,y.jsx)(`option`,{value:`cron`,children:`Schedule (Cron)`}),(0,y.jsx)(`option`,{value:`directory_watch`,children:`File Watcher`}),(0,y.jsx)(`option`,{value:`manual`,children:`Manual`})]})]}),w===`directory_watch`&&(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Watch directory path (absolute)`,value:D,onChange:e=>O(e.target.value)}),w===`cron`&&(0,y.jsxs)(`div`,{className:`space-y-1`,children:[(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Cron expression (minute hour day month weekday)`,value:k,onChange:e=>{A(e.target.value),M(``)}}),j&&(0,y.jsx)(`p`,{className:`text-xs text-[var(--app-danger)]`,children:j})]}),(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(d,{onClick:()=>void Ee(),disabled:N||!S.trim()||w===`directory_watch`&&!D.trim(),children:N?`Creating...`:`Create`}),(0,y.jsx)(d,{variant:`ghost`,onClick:()=>x(!1),children:`Cancel`})]})]}),F!==null&&(r.find(e=>e.id===F)?(0,y.jsxs)(m,{className:`space-y-3`,children:[(0,y.jsx)(`span`,{className:`text-sm font-medium text-[var(--app-text)]`,children:`Edit Event`}),(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Event name`,value:L,onChange:e=>R(e.target.value)}),(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)]`,placeholder:`Description (optional)`,value:z,onChange:e=>B(e.target.value)}),V===`directory_watch`&&(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)]`,placeholder:`Watch directory path`,value:H,onChange:e=>U(e.target.value)}),V===`cron`&&(0,y.jsxs)(`div`,{className:`space-y-1`,children:[(0,y.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)]`,placeholder:`Cron expression`,value:W,onChange:e=>{G(e.target.value),K(``)}}),xe&&(0,y.jsx)(`p`,{className:`text-xs text-[var(--app-danger)]`,children:xe})]}),(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(d,{onClick:()=>void Oe(),disabled:Se||!L.trim(),children:Se?`Saving...`:`Save`}),(0,y.jsx)(d,{variant:`ghost`,onClick:()=>I(null),children:`Cancel`})]})]}):null),(0,y.jsx)(m,{padding:!1,children:ge?(0,y.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,y.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-[var(--app-border)] border-t-[var(--app-accent)]`})}):r.length===0?(0,y.jsx)(ue,{icon:(0,y.jsx)(ne,{size:32}),title:`No events`,description:`Events are triggered by webhooks, schedules, or file changes and can start automations.`}):(0,y.jsxs)(pe,{children:[(0,y.jsx)(de,{children:(0,y.jsxs)(g,{children:[(0,y.jsx)(h,{children:`Name`}),(0,y.jsx)(h,{children:`Source`}),(0,y.jsx)(h,{children:`Enabled`}),(0,y.jsx)(h,{children:`Last Fired`}),(0,y.jsx)(h,{children:`Actions`})]})}),(0,y.jsx)(fe,{children:r.map(n=>(0,y.jsxs)(g,{children:[(0,y.jsxs)(_,{children:[(0,y.jsx)(`button`,{type:`button`,onClick:()=>e(`/events/${n.id}`),className:`font-medium text-[var(--app-text)] hover:text-[var(--app-accent)] transition-colors text-left`,children:n.name}),n.description&&(0,y.jsx)(`div`,{className:`text-xs text-[var(--app-text-muted)] truncate max-w-[200px]`,children:n.description})]}),(0,y.jsx)(_,{children:(0,y.jsx)(se,{variant:he[n.sourceType],children:n.sourceType===`directory_watch`?`file watcher`:n.sourceType})}),(0,y.jsx)(_,{children:(0,y.jsx)(me,{checked:n.enabled,onCheckedChange:()=>void ke(n),"aria-label":`Toggle ${n.name}`})}),(0,y.jsx)(_,{className:`text-xs text-[var(--app-text-muted)]`,children:n.lastFiredAt?le(n.lastFiredAt):`—`}),(0,y.jsx)(_,{children:(0,y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,y.jsx)(d,{variant:`ghost`,size:`sm`,onClick:()=>De(n),title:`Edit`,children:(0,y.jsx)(t,{size:12})}),n.sourceType===`manual`&&n.enabled&&(0,y.jsx)(d,{variant:`ghost`,size:`sm`,onClick:()=>Z(n.id),title:`Fire now`,children:(0,y.jsx)(ee,{size:12})}),(0,y.jsx)(d,{variant:`ghost`,size:`sm`,className:`text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,onClick:()=>Y(n.id),title:`Delete`,children:(0,y.jsx)(te,{size:12})})]})})]},n.id))})]})}),(0,y.jsx)(oe,{open:X!==null,onOpenChange:e=>{e||Z(null)},children:(0,y.jsxs)(o,{children:[(0,y.jsxs)(u,{children:[(0,y.jsx)(ae,{children:`Fire Event`}),(0,y.jsx)(a,{children:`Fire the manual event immediately. Optionally provide a JSON payload.`})]}),(0,y.jsx)(`textarea`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-2 text-sm text-[var(--app-text)] placeholder='{}' focus:border-[var(--app-accent)] focus:outline-none font-mono`,rows:4,placeholder:`{"key": "value"}`,value:Q,onChange:e=>Ce(e.target.value)}),(0,y.jsxs)(c,{children:[(0,y.jsx)(l,{children:`Cancel`}),(0,y.jsx)(s,{onClick:()=>{X&&je(X),Z(null)},disabled:we,children:we?`Firing...`:`Fire Event`})]})]})}),(0,y.jsx)(oe,{open:J!==null,onOpenChange:e=>{e||Y(null)},children:(0,y.jsxs)(o,{children:[(0,y.jsxs)(u,{children:[(0,y.jsx)(ae,{children:`Delete Event`}),(0,y.jsxs)(a,{children:[`Delete “`,Me?.name,`”? This action cannot be undone.`]})]}),(0,y.jsxs)(c,{children:[(0,y.jsx)(l,{children:`Cancel`}),(0,y.jsx)(s,{className:`bg-[var(--app-danger)] hover:bg-[var(--app-danger)]`,onClick:()=>{J&&Ae(J)},children:`Delete`})]})]})})]})}export{ge as Events};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{D as t,E as n,S as r,T as i,ct as a,l as o,n as s,s as c,y as l}from"./vendor-icons-Dk0hMuJz.js";import{t as u}from"./vendor-react-C6faO6LO.js";import{a as d,c as f,i as p,l as m,n as h,o as ee,r as g,s as _,t as v}from"./AlertDialog-B1zj0Qs3.js";import{t as y}from"./Button-BehrGSvy.js";import{t as b}from"./api-Bux34u4-.js";import{i as x,n as te,r as S,t as C}from"./index-B3_4_qY6.js";import{i as ne,r as re,t as w}from"./Card-B5E56u94.js";import{t as T}from"./PageHeader-B2CgcZ-t.js";import{n as E,t as D}from"./format-BUYXZqDw.js";import{t as O}from"./EmptyState-tTclFq_B.js";var k=e(a(),1),A=u();function j({value:e,onChange:t,label:n=`Delivery Targets`}){let[r,i]=(0,k.useState)([]),[a,o]=(0,k.useState)(!1);(0,k.useEffect)(()=>{let e=!1;return Promise.all([b(`/channels`).catch(()=>({channels:[]})),b(`/chat/sessions`).catch(()=>({sessions:[]}))]).then(([t,n])=>{if(e)return;let r=new Map(t.channels.map(e=>[e.id,e])),a=[];for(let e of n.sessions)if(e.source.type===`channel`&&e.source.channelId&&e.source.chatId){let t=r.get(e.source.channelId);a.push({id:e.id,channelId:e.source.channelId,channelName:t?.name??e.source.channelId.slice(0,8),platform:t?.platform??`unknown`,chatId:e.source.chatId})}let o=new Set;i(a.filter(e=>{let t=`${e.channelId}:${e.chatId}`;return o.has(t)?!1:(o.add(t),!0)}))}),()=>{e=!0}},[]);let s=(t,n)=>e.some(e=>e.type===`channel`&&e.channelId===t&&e.chatId===n),c=(n,r)=>{s(n,r)?t(e.filter(e=>!(e.type===`channel`&&e.channelId===n&&e.chatId===r))):t([...e,{type:`channel`,channelId:n,chatId:r}])},l=e.filter(e=>e.type===`channel`).length;return(0,A.jsxs)(`div`,{className:`relative`,children:[(0,A.jsx)(`label`,{className:`text-xs text-[var(--app-text-muted)]`,children:n}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o(!a),className:`mt-1 w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-left text-sm text-[var(--app-text)] hover:border-[var(--app-border-strong)] focus:border-[var(--app-accent)] focus:outline-none`,children:l===0?`Default (current session)`:`${l} channel${l>1?`s`:``} selected`}),a&&(0,A.jsxs)(`div`,{className:`absolute z-10 mt-1 w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] py-1 shadow-lg`,children:[r.length===0?(0,A.jsx)(`div`,{className:`px-3 py-2 text-xs text-[var(--app-text-subtle)]`,children:`No active channel conversations. Start a chat on WeChat/Telegram first.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`px-3 py-1 text-xs text-[var(--app-text-subtle)]`,children:`Channel conversations`}),r.map(e=>(0,A.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 px-3 py-1.5 text-xs text-[var(--app-text)] hover:bg-[var(--app-panel-muted)]`,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:s(e.channelId,e.chatId),onChange:()=>c(e.channelId,e.chatId),className:`rounded border-[var(--app-border-strong)] bg-[var(--app-panel-muted)]`}),(0,A.jsx)(`span`,{className:`truncate font-medium`,children:e.channelName}),(0,A.jsxs)(`span`,{className:`text-[var(--app-text-subtle)]`,children:[`(`,e.platform,`)`]})]},`${e.channelId}:${e.chatId}`))]}),l>0&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>{t([]),o(!1)},className:`mt-1 w-full border-t border-[var(--app-border)] px-3 py-1 text-left text-xs text-[var(--app-danger)] hover:bg-[var(--app-panel-muted)]`,children:`Clear all`}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`w-full border-t border-[var(--app-border)] px-3 py-1 text-left text-xs text-[var(--app-text-subtle)] hover:bg-[var(--app-panel-muted)]`,children:`Done`})]})]})}var M={active:`paused`,paused:`active`,completed:`active`,failed:`active`},N={active:(0,A.jsx)(t,{size:12}),paused:(0,A.jsx)(i,{size:12}),completed:(0,A.jsx)(l,{size:12}),failed:(0,A.jsx)(l,{size:12})};function P(){let e=S(e=>e.goals),t=S(e=>e.fetchGoals),a=S(e=>e.updateGoal),u=S(e=>e.deleteGoal),[P,F]=(0,k.useState)(!1),[I,L]=(0,k.useState)(``),[R,z]=(0,k.useState)(!1),[B,V]=(0,k.useState)(null),[H,U]=(0,k.useState)(null),[W,G]=(0,k.useState)(``),[K,q]=(0,k.useState)(``),[J,Y]=(0,k.useState)([]),[X,Z]=(0,k.useState)([]),[Q,ie]=(0,k.useState)([]),[$,ae]=(0,k.useState)([]),oe=e.filter(e=>e.status===`active`).length,se=e.filter(e=>e.status===`paused`).length,ce=e.filter(e=>e.status===`completed`).length;(0,k.useEffect)(()=>{t();let e=setInterval(()=>void t(),1e4);return()=>clearInterval(e)},[t]);let le=async()=>{if(I.trim()){z(!0),V(null);try{await b(`/goals`,{method:`POST`,body:JSON.stringify({input:I.trim(),deliverTo:Q.length>0?Q:void 0,reportTo:$.length>0?$:void 0})}),L(``),F(!1),t()}catch(e){V(e instanceof Error?e.message:`Failed to create goal`)}finally{z(!1)}}};return(0,A.jsxs)(`div`,{className:`space-y-4`,children:[(0,A.jsx)(T,{eyebrow:`Operations`,title:`Goals`,compact:!0,description:`Long-running outcomes, budgets, and delivery targets.`,metrics:[{label:`Active`,value:oe},{label:`Paused`,value:se},{label:`Completed`,value:ce}],actions:(0,A.jsxs)(`div`,{className:`flex gap-2`,children:[(0,A.jsx)(y,{variant:`ghost`,size:`sm`,onClick:()=>void t(),children:(0,A.jsx)(l,{size:14})}),(0,A.jsxs)(y,{size:`sm`,onClick:()=>F(!P),children:[(0,A.jsx)(r,{size:14}),`New Goal`]})]})}),P&&(0,A.jsxs)(w,{className:`space-y-3`,children:[(0,A.jsx)(`textarea`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-2 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Describe your goal in natural language...`,rows:3,value:I,onChange:e=>L(e.target.value)}),(0,A.jsx)(j,{value:Q,onChange:ie,label:`Deliver To (results)`}),(0,A.jsx)(j,{value:$,onChange:ae,label:`Report To (status)`}),B&&(0,A.jsx)(`p`,{className:`text-xs text-[var(--app-danger)]`,children:B}),(0,A.jsxs)(`div`,{className:`flex gap-2`,children:[(0,A.jsx)(y,{onClick:()=>void le(),disabled:R||!I.trim(),children:R?`Creating...`:`Create`}),(0,A.jsx)(y,{variant:`ghost`,onClick:()=>F(!1),children:`Cancel`})]})]}),e.length===0?(0,A.jsx)(O,{icon:(0,A.jsx)(o,{size:32}),title:`No goals`,description:`Create a goal to start goal-driven task orchestration`}):(0,A.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>{let t=e.targetValue>0?Math.min(100,Math.round(e.currentValue/e.targetValue*100)):0,r=new Date(e.deadline).getTime()<Date.now()&&e.status!==`completed`,o=H===e.id;return(0,A.jsxs)(w,{children:[(0,A.jsxs)(re,{children:[o?(0,A.jsx)(`input`,{className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:W,onChange:e=>G(e.target.value),autoFocus:!0}):(0,A.jsx)(ne,{className:`max-w-full text-[var(--app-text)] text-sm font-medium truncate sm:max-w-[180px]`,children:e.name}),(0,A.jsx)(C,{variant:te(e.status),children:e.status})]}),o?(0,A.jsx)(`textarea`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1 text-xs text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none mb-3`,placeholder:`Description...`,rows:2,value:K,onChange:e=>q(e.target.value)}):e.description?(0,A.jsx)(`p`,{className:`text-xs text-[var(--app-text-muted)] mb-3 line-clamp-2`,children:e.description}):null,o&&(0,A.jsxs)(`div`,{className:`mb-3 space-y-2`,children:[(0,A.jsx)(j,{value:J,onChange:Y,label:`Deliver To (results)`}),(0,A.jsx)(j,{value:X,onChange:Z,label:`Report To (status)`})]}),(0,A.jsxs)(`div`,{className:`mb-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,A.jsx)(`span`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`Progress`}),(0,A.jsxs)(`span`,{className:`font-mono text-xs text-[var(--app-text)]`,children:[t,`%`]})]}),(0,A.jsx)(`div`,{className:`h-1.5 rounded-full bg-[var(--app-panel-elevated)]`,children:(0,A.jsx)(`div`,{className:`h-full rounded-full transition-[width] ${t>=100?`bg-[var(--app-success)]`:`bg-[var(--app-accent)]`}`,style:{width:`${t}%`}})}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,A.jsxs)(`span`,{className:`font-mono text-[10px] text-[var(--app-text-subtle)]`,children:[e.currentValue,` / `,e.targetValue]}),(0,A.jsx)(`span`,{className:`font-mono text-[10px] text-[var(--app-text-subtle)]`,children:e.metricType})]})]}),(0,A.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-[var(--app-text-subtle)]`,children:`Role`}),(0,A.jsx)(C,{variant:`muted`,className:`text-[10px]`,children:e.roleId})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-[var(--app-text-subtle)]`,children:`Budget`}),(0,A.jsx)(`span`,{className:`font-mono text-[var(--app-text)]`,children:D(e.budgetUsd)})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-[var(--app-text-subtle)] ${r?`text-[var(--app-danger)]`:``}`,children:`Deadline`}),(0,A.jsx)(`span`,{className:`text-[var(--app-text)] ${r?`text-[var(--app-danger)]`:``}`,children:E(e.deadline)})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-[var(--app-text-subtle)]`,children:`Created`}),(0,A.jsx)(`span`,{className:`text-[var(--app-text-muted)]`,children:E(e.createdAt)})]})]}),(0,A.jsx)(`div`,{className:`flex items-center gap-1 mt-3 pt-3 border-t border-[var(--app-border)]`,children:o?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(y,{size:`sm`,variant:`ghost`,onClick:async()=>{try{await a(e.id,{name:W,description:K,deliverTo:J,reportTo:X}),U(null),x.success(`Goal updated`)}catch(e){x.error(e instanceof Error?e.message:`Failed to update`)}},children:`Save`}),(0,A.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>U(null),children:(0,A.jsx)(s,{size:14})})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(y,{size:`sm`,variant:`ghost`,title:`Edit`,onClick:()=>{U(e.id),G(e.name),q(e.description??``),Y(e.deliverTo??[]),Z(e.reportTo??[])},children:(0,A.jsx)(n,{size:14})}),(0,A.jsxs)(y,{size:`sm`,variant:`ghost`,title:`Change to ${M[e.status]}`,onClick:async()=>{try{await a(e.id,{status:M[e.status]}),x.success(`Status changed to ${M[e.status]}`)}catch(e){x.error(e instanceof Error?e.message:`Failed to update status`)}},children:[N[e.status]??(0,A.jsx)(i,{size:12}),(0,A.jsx)(`span`,{className:`text-xs`,children:M[e.status]})]}),(0,A.jsx)(`div`,{className:`ml-auto`,children:(0,A.jsxs)(v,{children:[(0,A.jsx)(m,{asChild:!0,children:(0,A.jsx)(y,{size:`sm`,variant:`ghost`,title:`Delete`,className:`text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,children:(0,A.jsx)(c,{size:14})})}),(0,A.jsxs)(p,{children:[(0,A.jsxs)(_,{children:[(0,A.jsx)(f,{children:`Delete goal`}),(0,A.jsxs)(d,{children:[`This will permanently delete "`,e.name,`". This action cannot be undone.`]})]}),(0,A.jsxs)(ee,{children:[(0,A.jsx)(g,{children:`Cancel`}),(0,A.jsx)(h,{className:`bg-[var(--app-danger)] hover:bg-[var(--app-danger-strong)]`,onClick:async()=>{try{await u(e.id),x.success(`Goal deleted`)}catch(e){x.error(e instanceof Error?e.message:`Failed to delete`)}},children:`Delete`})]})]})]})})]})})]},e.id)})})]})}export{P as Goals,j as t};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{$ as t,G as n,M as r,R as i,S as a,ct as o,et as s,g as c,n as ee,nt as te,s as l,u as ne,x as re,y as ie}from"./vendor-icons-Dk0hMuJz.js";import{t as u}from"./vendor-react-C6faO6LO.js";import{t as d}from"./Button-BehrGSvy.js";import{t as f}from"./api-Bux34u4-.js";import{i as p,t as m}from"./index-B3_4_qY6.js";import{t as h}from"./Card-B5E56u94.js";import{t as ae}from"./PageHeader-B2CgcZ-t.js";import{t as oe}from"./SectionHeader-CmXz6PM3.js";import{a as se}from"./format-BUYXZqDw.js";import{t as ce}from"./EmptyState-tTclFq_B.js";import{t as g}from"./ui-CerQw0jA.js";import{t as le}from"./useIsMobileLayout-dYzXP1EC.js";import{a as _,i as v,n as y,o as b,r as x,t as S}from"./Table-CXAcZ8Ru.js";var C=e(o(),1),w=u();function T({manifest:e}){if(!e)return null;let t=[];return e.skills.length>0&&t.push({label:`Skill(${e.skills.length})`,variant:`info`}),e.agents.length>0&&t.push({label:`Agent(${e.agents.length})`,variant:`success`}),e.mcpServers.length>0&&t.push({label:`MCP(${e.mcpServers.length})`,variant:`warning`}),e.hooks.length>0&&t.push({label:`Hook(${e.hooks.length})`,variant:`default`}),e.lspServers.length>0&&t.push({label:`LSP(${e.lspServers.length})`,variant:`default`}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,w.jsx)(m,{variant:e.variant,children:e.label},e.label))})}function E({label:e,value:t}){return(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 px-3 py-2`,children:[(0,w.jsx)(`p`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:e}),(0,w.jsx)(`p`,{className:`mt-1 text-sm font-medium text-[var(--app-text)]`,children:t})]})}function D({plugin:e,roles:t,operatingId:n,onInstallToRole:r}){return e.manifest?(0,w.jsxs)(`div`,{className:`space-y-4 text-xs`,children:[e.manifest.description?(0,w.jsx)(`p`,{className:`text-[var(--app-text-muted)]`,children:e.manifest.description}):null,(0,w.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-4`,children:[(0,w.jsx)(E,{label:`Version`,value:e.version?`v${e.version}`:`—`}),(0,w.jsx)(E,{label:`Scope`,value:e.scope}),(0,w.jsx)(E,{label:`Capability Count`,value:e.manifest.skills.length+e.manifest.agents.length+e.manifest.mcpServers.length+e.manifest.hooks.length+e.manifest.lspServers.length}),(0,w.jsx)(E,{label:`Activation`,value:e.globalEnabled?`User On`:`User Off`})]}),(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 px-3 py-2`,children:[(0,w.jsx)(`p`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Install Path`}),(0,w.jsx)(`p`,{className:`mt-1 truncate font-mono text-[11px] text-[var(--app-text-muted)]`,title:e.installPath,children:e.installPath})]}),(0,w.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[e.manifest.skills.length>0&&(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`div`,{className:`mb-2 font-semibold text-[var(--app-text)]`,children:`Skills`}),e.manifest.skills.map(e=>(0,w.jsxs)(`div`,{className:`inline-flex items-baseline gap-1 text-[var(--app-text-muted)]`,children:[(0,w.jsx)(`span`,{className:`text-[var(--app-text)]`,children:e.name}),e.description?(0,w.jsxs)(`span`,{className:`text-[var(--app-text-subtle)]`,children:[`; `,e.description]}):null]},e.name))]}),e.manifest.agents.length>0&&(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`div`,{className:`mb-2 font-semibold text-[var(--app-text)]`,children:`Agents`}),e.manifest.agents.map(e=>(0,w.jsxs)(`div`,{className:`inline-flex items-baseline gap-1 text-[var(--app-text-muted)]`,children:[(0,w.jsx)(`span`,{className:`text-[var(--app-text)]`,children:e.name}),e.description?(0,w.jsxs)(`span`,{className:`text-[var(--app-text-subtle)]`,children:[`; `,e.description]}):null]},e.name))]}),e.manifest.mcpServers.length>0&&(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`div`,{className:`mb-2 font-semibold text-[var(--app-text)]`,children:`MCP Servers`}),e.manifest.mcpServers.map(e=>(0,w.jsx)(`div`,{className:`text-[var(--app-text-muted)]`,children:e},e))]}),e.manifest.hooks.length>0&&(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`div`,{className:`mb-2 font-semibold text-[var(--app-text)]`,children:`Hooks`}),e.manifest.hooks.map(e=>(0,w.jsx)(`div`,{className:`text-[var(--app-text-muted)]`,children:e},e))]}),e.manifest.lspServers.length>0&&(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`div`,{className:`mb-2 font-semibold text-[var(--app-text)]`,children:`LSP Servers`}),e.manifest.lspServers.map(e=>(0,w.jsx)(`div`,{className:`text-[var(--app-text-muted)]`,children:e},e))]})]}),t.length>0&&e.scope===`user`?(0,w.jsxs)(`div`,{className:`rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:[(0,w.jsx)(`p`,{className:`mb-2 text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Install to Role`}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-[10px]`,disabled:n===e.id,onClick:()=>void r(e.id,t.id,t.workspacePath),children:t.name},t.id))})]}):null]}):(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`Loading manifest...`})}function O(){let[e,o]=(0,C.useState)([]),[u,E]=(0,C.useState)([]),[O,ue]=(0,C.useState)([]),[de,fe]=(0,C.useState)(new Set),[pe,k]=(0,C.useState)(!0),[A,j]=(0,C.useState)(!1),[M,N]=(0,C.useState)(null),[P,me]=(0,C.useState)(!1),[F,he]=(0,C.useState)(``),[I,L]=(0,C.useState)(null),[R,z]=(0,C.useState)(!1),[B,V]=(0,C.useState)(``),[H,ge]=(0,C.useState)([]),[U,_e]=(0,C.useState)(!1),[W,ve]=(0,C.useState)(new Set),[G,K]=(0,C.useState)(`all`),[q,ye]=(0,C.useState)([]),be=le(),J=(0,C.useCallback)(async()=>{k(!0);try{o((await f(`/plugins`)).plugins)}catch(e){p.error(e instanceof Error?e.message:`Failed to load plugins`)}finally{k(!1)}},[]),Y=(0,C.useCallback)(async()=>{j(!0),N(null);try{let[e,t]=await Promise.all([f(`/plugins/marketplace`).catch(()=>({available:[],installed:[]})),f(`/plugins/marketplaces`)]);ue(e.available),fe(new Set(e.installed.map(e=>e.id))),E(t.sources)}catch(e){N(e instanceof Error?e.message:`Failed to load marketplace`)}finally{j(!1)}},[]),xe=(0,C.useCallback)(async()=>{try{ge((await f(`/plugins/stats?limit=20`)).stats)}catch{}},[]),X=(0,C.useCallback)(async()=>{try{ye((await f(`/roles`)).roles)}catch{}},[]);(0,C.useEffect)(()=>{J(),Y(),X()},[J,Y,X]);let Se=async(e,t)=>{L(e);try{await f(`/plugins/${encodeURIComponent(e)}/${t?`enable`:`disable`}`,{method:`POST`}),p.success(`${e} ${t?`enabled`:`disabled`} globally`),o(n=>n.map(n=>n.id===e?{...n,globalEnabled:t}:n))}catch(e){p.error(e instanceof Error?e.message:`Failed to ${t?`enable`:`disable`} plugin`)}finally{L(null)}},Ce=async e=>{L(e);try{await f(`/plugins/uninstall/${encodeURIComponent(e)}`,{method:`POST`}),p.success(`Plugin uninstalled`),await Promise.all([J(),Y()])}catch(e){p.error(e instanceof Error?e.message:`Uninstall failed`)}finally{L(null)}},we=async(e,t,n)=>{L(e);try{await f(`/plugins/install/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify({scope:`project`,cwd:n})});let r=q.find(e=>e.id===t)?.name??t;p.success(`Installed ${e.split(`@`)[0]} for ${r}`),await J()}catch(e){p.error(e instanceof Error?e.message:`Install to role failed`)}finally{L(null)}},Te=async()=>{if(B.trim())try{await f(`/plugins/install/${encodeURIComponent(B.trim())}`,{method:`POST`,body:JSON.stringify({})}),p.success(`Source added`),V(``),z(!1),await Y()}catch(e){p.error(e instanceof Error?e.message:`Failed to add source`)}},Z=async(e,t=`user`,n)=>{L(e);try{await f(`/plugins/install/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify({scope:t,cwd:n})});let r=t===`project`&&n?`${e.split(`@`)[0]} for ${n.split(`/`).pop()}`:e.split(`@`)[0];p.success(`Installed ${r}`),await Promise.all([J(),Y()])}catch(e){p.error(e instanceof Error?e.message:`Install failed`)}finally{L(null)}},Ee=e=>{ve(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Q=G===`all`?e:e.filter(e=>e.scope===G),$=F?O.filter(e=>e.name.toLowerCase().includes(F.toLowerCase())||e.description.toLowerCase().includes(F.toLowerCase())):O;return(0,w.jsxs)(`div`,{className:`space-y-5`,children:[(0,w.jsx)(ae,{eyebrow:`Capabilities`,title:`Plugins`,compact:!0,description:`Installed capabilities, scope, and activation.`,metrics:[{label:`Total`,value:e.length},{label:`Project Scope`,value:e.filter(e=>e.scope===`project`).length},{label:`Catalog`,value:O.length}],actions:(0,w.jsx)(d,{variant:`ghost`,size:`sm`,onClick:()=>void J(),children:(0,w.jsx)(ie,{size:14})})}),(0,w.jsx)(oe,{title:`Installed Plugins`,compact:!0,description:`Filter by scope, inspect manifests, and keep every activation path reachable from one place.`}),(0,w.jsxs)(h,{children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsx)(i,{size:14,className:`text-[var(--app-text-muted)] flex-shrink-0`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`all`?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-muted)] hover:bg-[var(--app-panel-muted)]`}`,onClick:()=>K(`all`),children:`All`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`user`?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-muted)] hover:bg-[var(--app-panel-muted)]`}`,onClick:()=>K(`user`),children:`User`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`project`?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-muted)] hover:bg-[var(--app-panel-muted)]`}`,onClick:()=>K(`project`),children:`Project`}),(0,w.jsx)(`span`,{className:`h-4 w-px bg-[var(--app-panel-muted)] mx-1`}),u.map(e=>(0,w.jsx)(m,{variant:`muted`,className:`text-xs`,children:e.name},e.name)),(0,w.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[A&&(0,w.jsx)(r,{size:12,className:`animate-spin text-[var(--app-text-subtle)]`}),A?null:(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>z(!R),children:R?(0,w.jsx)(ee,{size:12}):(0,w.jsx)(a,{size:12})})]})]}),R&&(0,w.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,w.jsx)(`input`,{className:`flex-1 rounded border border-[var(--app-border)] bg-[var(--app-panel)] px-2 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:B,onChange:e=>V(e.target.value),placeholder:`https://github.com/org/marketplace-repo`,onKeyDown:e=>{e.key===`Enter`&&Te()}}),(0,w.jsx)(d,{size:`sm`,onClick:()=>void Te(),disabled:!B.trim(),children:`Add`})]})]}),pe?(0,w.jsx)(h,{children:(0,w.jsx)(`div`,{className:`py-8 text-center text-sm text-[var(--app-text-subtle)]`,children:`Loading...`})}):Q.length===0?(0,w.jsx)(h,{children:(0,w.jsx)(ce,{icon:(0,w.jsx)(re,{size:32}),title:`No plugins`,description:G===`all`?`No plugins installed. Browse the marketplace or install from a URL.`:`No ${G}-scope plugins installed.`,className:`py-8`})}):be?(0,w.jsx)(`div`,{className:`space-y-3`,children:Q.map((e,n)=>{let i=W.has(e.id),a=e.id.split(`@`)[0],o=I===e.id,c=e.projectPath?`${e.id}:${e.projectPath}`:`${e.id}:${n}`;return(0,w.jsxs)(h,{children:[(0,w.jsx)(`div`,{className:`flex items-start justify-between gap-3`,children:(0,w.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`button`,{onClick:()=>Ee(e.id),className:`text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`,children:i?(0,w.jsx)(s,{size:14}):(0,w.jsx)(t,{size:14})}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`truncate text-sm font-medium text-[var(--app-text)]`,children:a}),(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-muted)]`,children:e.version?`v${e.version}`:`—`})]})]}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,w.jsx)(m,{variant:e.scope===`user`?`info`:`warning`,children:e.scope}),(0,w.jsx)(m,{variant:e.globalEnabled?`success`:`destructive`,children:e.globalEnabled?`User On`:`User Off`})]}),e.scope===`project`&&e.projectPath?(0,w.jsx)(`p`,{className:`truncate text-[11px] text-[var(--app-text-subtle)]`,title:e.projectPath,children:e.projectPath}):null,(0,w.jsx)(T,{manifest:e.manifest})]})}),(0,w.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs`,disabled:o,onClick:()=>void Se(e.id,!e.globalEnabled),children:o?(0,w.jsx)(r,{size:g.xs,className:`animate-spin`}):e.globalEnabled?`Disable`:`Enable`}),(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-[var(--app-danger)]`,disabled:o,onClick:()=>void Ce(e.id),children:(0,w.jsx)(l,{size:g.xs})})]}),i?(0,w.jsx)(`div`,{className:`mt-4 rounded-xl border border-[var(--app-border)] bg-black/10 p-3`,children:(0,w.jsx)(D,{plugin:e,roles:q,operatingId:I,onInstallToRole:we})}):null]},c)})}):(0,w.jsx)(h,{padding:!1,children:(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{className:`w-8`}),(0,w.jsx)(v,{children:`Name`}),(0,w.jsx)(v,{children:`Version`}),(0,w.jsx)(v,{children:`Scope`}),(0,w.jsx)(v,{children:`Type`}),(0,w.jsx)(v,{children:`Activation`}),(0,w.jsx)(v,{children:`Actions`})]})}),(0,w.jsx)(y,{children:Q.map((e,n)=>{let i=W.has(e.id),a=e.id.split(`@`)[0],o=I===e.id,c=e.projectPath?`${e.id}:${e.projectPath}`:`${e.id}:${n}`;return(0,w.jsxs)(C.Fragment,{children:[(0,w.jsxs)(b,{className:`group`,children:[(0,w.jsx)(x,{children:(0,w.jsx)(`button`,{onClick:()=>Ee(e.id),className:`text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`,children:i?(0,w.jsx)(s,{size:g.xs}):(0,w.jsx)(t,{size:g.xs})})}),(0,w.jsx)(x,{className:`font-medium text-[var(--app-text)]`,children:a}),(0,w.jsx)(x,{className:`text-xs text-[var(--app-text-muted)]`,children:e.version?`v${e.version}`:`—`}),(0,w.jsxs)(x,{children:[(0,w.jsx)(m,{variant:e.scope===`user`?`info`:`warning`,children:e.scope}),e.scope===`project`&&e.projectPath&&(0,w.jsx)(`div`,{className:`text-[10px] text-[var(--app-text-subtle)] truncate max-w-[120px]`,title:e.projectPath,children:e.projectPath.split(`/`).pop()})]}),(0,w.jsx)(x,{children:(0,w.jsx)(T,{manifest:e.manifest})}),(0,w.jsx)(x,{children:(0,w.jsx)(m,{variant:e.globalEnabled?`success`:`destructive`,children:e.globalEnabled?`User On`:`User Off`})}),(0,w.jsx)(x,{children:(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:o,onClick:()=>void Se(e.id,!e.globalEnabled),children:o?(0,w.jsx)(r,{size:g.xs,className:`animate-spin`}):e.globalEnabled?`Disable`:`Enable`}),(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs text-[var(--app-danger)]`,disabled:o,onClick:()=>void Ce(e.id),children:(0,w.jsx)(l,{size:g.xs})})]})})]}),i&&(0,w.jsx)(b,{className:`bg-[var(--app-panel)]/50`,children:(0,w.jsx)(x,{colSpan:7,className:`px-6 py-3`,children:(0,w.jsx)(D,{plugin:e,roles:q,operatingId:I,onInstallToRole:we})})},`${e.id}-detail`)]},c)})})]})}),(0,w.jsxs)(h,{children:[(0,w.jsxs)(`button`,{className:`flex w-full items-center gap-2 text-sm font-semibold text-[var(--app-text)]`,onClick:()=>me(!P),children:[(0,w.jsx)(ne,{size:g.sm,className:`text-[var(--app-text-muted)]`}),`Marketplace (`,O.length,`)`,P?(0,w.jsx)(s,{size:g.xs,className:`ml-auto`}):(0,w.jsx)(t,{size:g.xs,className:`ml-auto`})]}),P&&(0,w.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(c,{size:g.sm,className:`absolute left-2.5 top-2 text-[var(--app-text-subtle)]`}),(0,w.jsx)(`input`,{className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel)] pl-8 pr-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,value:F,onChange:e=>he(e.target.value),placeholder:`Search available plugins...`})]}),A?(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)] text-center py-2`,children:`Loading marketplace...`}):M?(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-danger)] text-center py-2`,children:M}):$.length===0?(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)] text-center py-2`,children:F?`No plugins match your search`:`No marketplace plugins available`}):(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{children:`Name`}),(0,w.jsx)(v,{children:`Description`}),(0,w.jsx)(v,{children:`Source`}),(0,w.jsx)(v,{children:`Action`})]})}),(0,w.jsx)(y,{children:$.map(e=>{let t=de.has(e.pluginId),i=I===e.pluginId;return(0,w.jsxs)(b,{children:[(0,w.jsx)(x,{className:`font-medium text-[var(--app-text)] text-xs`,children:e.name}),(0,w.jsx)(x,{className:`text-xs text-[var(--app-text-muted)] max-w-[300px] truncate`,title:e.description,children:e.description}),(0,w.jsx)(x,{children:(0,w.jsx)(m,{variant:`muted`,className:`text-[10px]`,children:e.marketplaceName})}),(0,w.jsx)(x,{children:t?(0,w.jsx)(m,{variant:`success`,className:`text-[10px]`,children:`Installed`}):(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,disabled:i,onClick:()=>void Z(e.pluginId),children:i?(0,w.jsx)(r,{size:g.xs,className:`animate-spin`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(n,{size:g.xs}),` Install`]})}),q.length>0&&(0,w.jsxs)(`div`,{className:`relative group/install`,children:[(0,w.jsx)(d,{variant:`ghost`,size:`sm`,className:`h-6 px-1 text-xs text-[var(--app-text-subtle)]`,children:(0,w.jsx)(s,{size:g.xs})}),(0,w.jsx)(`div`,{className:`absolute right-0 top-full mt-1 z-10 hidden group-hover/install:block bg-[var(--app-panel-elevated)] border border-[var(--app-border)] rounded shadow-lg py-1 min-w-[140px]`,children:q.map(t=>(0,w.jsx)(`button`,{className:`block w-full text-left px-3 py-1 text-xs text-[var(--app-text)] hover:bg-[var(--app-panel-muted)]`,disabled:i,onClick:()=>void Z(e.pluginId,`project`,t.workspacePath),children:t.name},t.id))})]})]})})]},e.pluginId)})})]})]})]}),(0,w.jsxs)(h,{children:[(0,w.jsxs)(`button`,{className:`flex w-full items-center gap-2 text-sm font-semibold text-[var(--app-text)]`,onClick:()=>{!U&&H.length===0&&xe(),_e(!U)},children:[(0,w.jsx)(te,{size:14,className:`text-[var(--app-text-muted)]`}),`Usage Stats`,U?(0,w.jsx)(s,{size:12,className:`ml-auto`}):(0,w.jsx)(t,{size:12,className:`ml-auto`})]}),U&&(0,w.jsx)(`div`,{className:`mt-3`,children:H.length===0?(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)] text-center py-2`,children:`No usage data yet`}):(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{children:`Plugin`}),(0,w.jsx)(v,{children:`Usage Count`}),(0,w.jsx)(v,{children:`Last Used`})]})}),(0,w.jsx)(y,{children:H.map(e=>(0,w.jsxs)(b,{children:[(0,w.jsx)(x,{className:`font-medium text-[var(--app-text)] text-xs`,children:e.pluginName}),(0,w.jsx)(x,{className:`font-mono text-xs text-[var(--app-text-muted)]`,children:e.usageCount}),(0,w.jsx)(x,{className:`text-xs text-[var(--app-text-muted)]`,children:e.lastUsed?se(e.lastUsed):`—`})]},e.pluginPath))})]})})]})]})}export{O as Plugins};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{S as t,ct as n,n as r,y as i}from"./vendor-icons-Dk0hMuJz.js";import{r as a,t as o}from"./vendor-react-C6faO6LO.js";import{t as s}from"./Button-BehrGSvy.js";import{i as c,r as l,t as u}from"./index-B3_4_qY6.js";import{t as d}from"./Card-B5E56u94.js";import{t as f}from"./PageHeader-B2CgcZ-t.js";import{t as p}from"./SectionHeader-CmXz6PM3.js";import{a as m}from"./format-BUYXZqDw.js";import{t as h}from"./EmptyState-tTclFq_B.js";import{t as g}from"./useIsMobileLayout-dYzXP1EC.js";import{a as _,i as v,n as y,o as b,r as x,t as S}from"./Table-CXAcZ8Ru.js";var C=e(n(),1),w=o();function T(){let e=l(e=>e.roles),n=l(e=>e.fetchRoles),o=l(e=>e.createRole),[T,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(``),[j,M]=(0,C.useState)(``),[N,P]=(0,C.useState)(!1),[F,I]=(0,C.useState)(null),L=g(),R=(0,C.useCallback)(async()=>{E(!0),await n(),E(!1)},[n]),z=()=>{A(``),M(``),I(null),P(!1)},B=async()=>{let e=k.trim();if(!e){I(`Name is required.`);return}P(!0),I(null);try{await o({name:e,cagPrompt:j.trim()}),await n(),O(!1),z(),c.success(`Role created`)}catch(e){I(e instanceof Error?e.message:`Failed to create role`)}finally{P(!1)}};(0,C.useEffect)(()=>{R()},[R]);let V=e=>e===`active`?`success`:e===`inactive`?`secondary`:e===`retired`?`destructive`:e===`probation`?`warning`:`secondary`,H=e.filter(e=>e.status===`active`).length,U=e.filter(e=>e.status===`probation`).length,W=e.filter(e=>e.memoryStreamId).length;return(0,w.jsxs)(`div`,{className:`space-y-5`,children:[(0,w.jsx)(f,{eyebrow:`Identities`,title:`Roles`,description:`Registry for role status, memory linkage, and edit actions.`,metrics:[{label:`Active`,value:H},{label:`Probation`,value:U},{label:`Linked Memory`,value:W}],compact:!0,actions:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{variant:`ghost`,size:`sm`,onClick:()=>void R(),disabled:T,children:(0,w.jsx)(i,{size:14,className:T?`animate-spin`:``})}),(0,w.jsxs)(s,{size:`sm`,onClick:()=>O(!0),children:[(0,w.jsx)(t,{size:14}),`New Role`]})]})}),(0,w.jsx)(p,{title:`Registry`,description:`Open a role to inspect prompts, performance, and bindings.`,compact:!0,action:(0,w.jsxs)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:[e.length,` role`,e.length===1?``:`s`]})}),e.length===0&&!T?(0,w.jsx)(d,{children:(0,w.jsx)(h,{title:`No roles yet`,description:`Create a role to define agent behavior and bind plugins.`})}):L?(0,w.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,w.jsxs)(d,{children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,w.jsx)(a,{to:`/roles/${e.id}`,className:`font-medium text-[var(--app-accent)] hover:text-[var(--app-accent)]`,children:e.name}),(0,w.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)]`,children:m(e.createdAt)})]}),(0,w.jsx)(u,{variant:V(e.status),children:e.status})]}),(0,w.jsxs)(`div`,{className:`mt-4 grid gap-2 text-xs text-[var(--app-text-subtle)] sm:grid-cols-2`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Score`}),(0,w.jsx)(`div`,{className:`mt-1 font-mono text-[var(--app-text)]`,children:e.performanceScore==null?`—`:`${(e.performanceScore*100).toFixed(0)}%`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Memory`}),(0,w.jsx)(`div`,{className:`mt-1 text-[var(--app-text)]`,children:e.memoryStreamId?e.memoryStreamId.slice(0,8):`—`})]})]})]},e.id))}):(0,w.jsx)(d,{padding:!1,children:(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{children:`Name`}),(0,w.jsx)(v,{children:`Status`}),(0,w.jsx)(v,{children:`Score`}),(0,w.jsx)(v,{children:`Memories`}),(0,w.jsx)(v,{children:`Created`})]})}),(0,w.jsx)(y,{children:e.map(e=>(0,w.jsxs)(b,{children:[(0,w.jsx)(x,{children:(0,w.jsx)(a,{to:`/roles/${e.id}`,className:`font-medium text-[var(--app-accent)] hover:text-[var(--app-accent)]`,children:e.name})}),(0,w.jsx)(x,{children:(0,w.jsx)(u,{variant:V(e.status),children:e.status})}),(0,w.jsx)(x,{children:e.performanceScore==null?(0,w.jsx)(`span`,{className:`text-[var(--app-text-subtle)]`,children:`—`}):(0,w.jsxs)(`span`,{className:`font-mono text-xs text-[var(--app-text)]`,children:[(e.performanceScore*100).toFixed(0),`%`]})}),(0,w.jsx)(x,{children:(0,w.jsx)(`span`,{className:`text-sm text-[var(--app-text-muted)]`,children:e.memoryStreamId?e.memoryStreamId.slice(0,8):`—`})}),(0,w.jsx)(x,{className:`text-xs text-[var(--app-text-subtle)]`,children:m(e.createdAt)})]},e.id))})]})}),D&&(0,w.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:e=>{e.target===e.currentTarget&&(O(!1),z())},children:(0,w.jsxs)(`div`,{className:`w-full max-w-md rounded-lg border border-[var(--app-border)] bg-[var(--app-panel)] p-6 shadow-lg`,children:[(0,w.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-[var(--app-text)]`,children:`Create Role`}),(0,w.jsx)(`button`,{className:`text-[var(--app-text-muted)] hover:text-[var(--app-text)]`,onClick:()=>{O(!1),z()},children:(0,w.jsx)(r,{size:16})})]}),(0,w.jsxs)(`div`,{className:`space-y-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`label`,{className:`mb-1 block text-sm font-medium text-[var(--app-text)]`,htmlFor:`role-name`,children:[`Name `,(0,w.jsx)(`span`,{className:`text-[var(--app-danger)]`,children:`*`})]}),(0,w.jsx)(`input`,{id:`role-name`,className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-2 text-sm text-[var(--app-text)] placeholder-slate-500 focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`e.g. Engineer, Reviewer`,value:k,onChange:e=>A(e.target.value),onKeyDown:e=>{e.key===`Enter`&&B()},autoFocus:!0})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-[var(--app-text)]`,htmlFor:`role-cag-prompt`,children:`CAG Prompt`}),(0,w.jsx)(`textarea`,{id:`role-cag-prompt`,className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-2 text-sm text-[var(--app-text)] placeholder-slate-500 focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Character and Guidance prompt for this role...`,rows:5,value:j,onChange:e=>M(e.target.value)})]}),F&&(0,w.jsx)(`p`,{className:`text-sm text-[var(--app-danger)]`,children:F}),(0,w.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,w.jsx)(s,{variant:`ghost`,size:`sm`,onClick:()=>{O(!1),z()},children:`Cancel`}),(0,w.jsx)(s,{size:`sm`,onClick:()=>void B(),disabled:N,children:N?`Creating...`:`Create`})]})]})]})})]})}export{T as Roles};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{_ as t,ct as n,j as r,m as i,n as a,y as o}from"./vendor-icons-Dk0hMuJz.js";import{l as s,t as c}from"./vendor-react-C6faO6LO.js";import{a as l,c as u,i as d,n as f,o as p,r as m,s as h,t as g}from"./AlertDialog-B1zj0Qs3.js";import{t as _}from"./Button-BehrGSvy.js";import{a as v,c as y,o as b,r as x,s as S,t as C}from"./api-Bux34u4-.js";import{r as w}from"./index-B3_4_qY6.js";import{t as T}from"./Card-B5E56u94.js";import{t as E}from"./PageHeader-B2CgcZ-t.js";import{t as D}from"./SectionHeader-CmXz6PM3.js";import{i as O}from"./format-BUYXZqDw.js";import{t as k}from"./EmptyState-tTclFq_B.js";import{t as A}from"./ui-CerQw0jA.js";import{t as j}from"./EnvVarEditor-BzJNsDt0.js";var M=e(n(),1),N=c(),P={anthropic:{label:`Anthropic`,paths:[`anthropic.apiKey`,`anthropic.baseUrl`,`anthropic.model`,`anthropic.defaultOpusModel`,`anthropic.defaultSonnetModel`,`anthropic.defaultHaikuModel`,`anthropic.smallFastModel`]},defaults:{label:`Defaults`,paths:[`defaults.model`,`defaults.effort`,`defaults.maxTurns`,`defaults.maxBudgetUsd`,`defaults.timeout`,`defaults.approvalTimeout`]},server:{label:`Server`,paths:[`server.port`,`server.host`],mutablePaths:[`server.timezone`]},logging:{label:`Logging`,paths:[`logging.level`]},evolution:{label:`Evolution`,paths:[`roles.evolution.triggerEvery`,`roles.evolution.reflectionThreshold`]},chat:{label:`Chat`,paths:[`chat.sessionTimeoutMinutes`,`chat.maxSessionTurns`,`chat.autoTitle`,`chat.archiveExtractMemory`]},workflow:{label:`Workflow`,paths:[`watchdog.rules.artifactCleanup.enabled`,`watchdog.rules.artifactCleanup.ttlDays`,`watchdog.rules.artifactCleanup.orphanGcMinAgeHours`]}},F={anthropic:`Model endpoints and provider-specific defaults.`,defaults:`Global execution defaults applied when a role does not override them.`,server:`Network surface and host-level configuration.`,logging:`Verbosity and runtime observability controls.`,evolution:`Thresholds that govern role adaptation over time.`,chat:`Session lifecycle and archive behavior for chat mode.`,workflow:`Cleanup rules and artifact retention for background work.`},I=[`defaults.deniedReadPaths`,`defaults.approvalRequired`],L=new Set([`anthropic.apiKey`,`server.apiKey`]),R={"anthropic.apiKey":`API Key`,"anthropic.baseUrl":`Base URL`,"anthropic.model":`Model`,"anthropic.defaultOpusModel":`Default Opus Model`,"anthropic.defaultSonnetModel":`Default Sonnet Model`,"anthropic.defaultHaikuModel":`Default Haiku Model`,"anthropic.smallFastModel":`Small Fast Model`,"defaults.model":`Default Model`,"defaults.effort":`Effort Level`,"defaults.maxTurns":`Max Turns`,"defaults.maxBudgetUsd":`Max Budget (USD)`,"defaults.timeout":`Timeout (seconds)`,"defaults.approvalTimeout":`Approval Timeout (seconds)`,"server.port":`Port`,"server.host":`Host`,"server.apiKey":`API Key (server auth)`,"server.timezone":`Timezone`,"logging.level":`Log Level`,"roles.evolution.triggerEvery":`Evolution Trigger Every (tasks)`,"roles.evolution.reflectionThreshold":`Reflection Threshold (tokens)`,"chat.sessionTimeoutMinutes":`Session Timeout (minutes)`,"chat.maxSessionTurns":`Max Session Turns`,"chat.autoTitle":`Auto-generate Session Title`,"chat.archiveExtractMemory":`Extract Memory on Archive`,"watchdog.rules.artifactCleanup.enabled":`Workflow Artifact Cleanup Enabled`,"watchdog.rules.artifactCleanup.ttlDays":`Artifact Retention (days)`,"watchdog.rules.artifactCleanup.orphanGcMinAgeHours":`Orphan File GC Min Age (hours)`},z={"defaults.effort":[`low`,`medium`,`high`,`max`],"logging.level":[`debug`,`info`,`warn`,`error`],"server.timezone":[`system`,`Asia/Shanghai`,`Asia/Tokyo`,`Asia/Singapore`,`America/New_York`,`America/Los_Angeles`,`America/Chicago`,`Europe/London`,`Europe/Berlin`,`Europe/Paris`,`UTC`]};function B(){let[e,n]=(0,M.useState)({}),[a,c]=(0,M.useState)([]),[v,y]=(0,M.useState)({}),[b,x]=(0,M.useState)(new Set),[S,A]=(0,M.useState)(!1),[B,U]=(0,M.useState)(null),[ee,te]=(0,M.useState)(!0),[W,G]=(0,M.useState)(null),[K,q]=(0,M.useState)({}),[J,Y]=(0,M.useState)(new Set),[ne,re]=(0,M.useState)({}),X=w(e=>e.configVersion);(0,M.useEffect)(()=>{if(b.size===0)return;let e=e=>{e.preventDefault()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[b.size]);let Z=s(({currentLocation:e,nextLocation:t})=>b.size>0&&e.pathname!==t.pathname),Q=(0,M.useCallback)(async()=>{try{let e=await C(`/config`);n(e.config),c(e.mutable);let t={};for(let[n,r]of Object.entries(e.config))t[n]=String(r.value??``);y(t),x(new Set);let r=e.config[`server.timezone`]?.value;r&&O(r);let i={};for(let t of I){let n=e.config[t];n&&(i[t]=Array.isArray(n.value)?n.value:[])}q(i),Y(new Set),G(await C(`/config/env-diff`)),re((await C(`/config/env`)).env)}catch(e){U({type:`error`,text:e instanceof Error?e.message:`Failed to load config`})}finally{te(!1)}},[]);(0,M.useEffect)(()=>{Q()},[Q]),(0,M.useEffect)(()=>{X>0&&Q()},[X,Q]);let ie=async()=>{await C(`/config/sync-to-env`,{method:`POST`}),U({type:`success`,text:`Synced DB values to .env`}),G(null)},ae=async()=>{await C(`/config/load-from-env`,{method:`POST`}),U({type:`success`,text:`Loaded .env values to DB`}),Q()},$=(e,t)=>{y(n=>({...n,[e]:t})),x(t=>new Set(t).add(e)),U(null)},oe=async()=>{if(b.size!==0){A(!0),U(null);try{let t={};for(let n of b){let r=e[n],i=v[n];if(r&&typeof r.value==`number`&&(i=Number(i),isNaN(i))){U({type:`error`,text:`"${R[n]??n}" must be a number`}),A(!1);return}t[n]=i}let n=await C(`/config`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,...Object.fromEntries(Array.from(J).map(e=>[e,K[e]??[]]))})});if(n.updated.length>0&&(U({type:`success`,text:`Updated ${n.updated.length} setting(s)`}),n.updated.includes(`server.timezone`))){let e=v[`server.timezone`];O(e)}n.errors.length>0&&U({type:`error`,text:n.errors.join(`; `)}),x(new Set),Q()}catch(e){U({type:`error`,text:e instanceof Error?e.message:`Save failed`})}finally{A(!1)}}};return ee?(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,N.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-[var(--app-border)] border-t-[var(--app-accent)]`})}):Object.keys(e).length===0?(0,N.jsx)(k,{icon:(0,N.jsx)(i,{size:32}),title:`No configuration`,description:`Config API not available`}):(0,N.jsxs)(`div`,{className:`space-y-5`,children:[(0,N.jsx)(E,{eyebrow:`Configuration`,title:`Settings`,compact:!0,description:`Mutable fields, pending edits, and environment drift.`,metrics:[{label:`Editable`,value:a.length},{label:`Pending`,value:b.size+J.size},{label:`Env Drift`,value:W?.diffs.length??0}],actions:(0,N.jsxs)(`div`,{className:`flex w-full justify-end gap-2`,children:[(0,N.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>void Q(),children:(0,N.jsx)(o,{size:14})}),b.size>0&&(0,N.jsxs)(_,{size:`sm`,onClick:()=>void oe(),disabled:S,children:[(0,N.jsx)(t,{size:14}),S?`Saving...`:`Save (${b.size})`]})]})}),(0,N.jsx)(D,{title:`Configuration Groups`,compact:!0,description:`Fields stay in place while changeable, restart-required, and pending state are clarified.`}),B&&(0,N.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${B.type===`success`?`border-[var(--app-success-soft-border)] bg-[var(--app-success-soft-bg)] text-[var(--app-success-soft-text)]`:`border-[var(--app-danger-soft-border)] bg-[var(--app-danger-soft-bg)] text-[var(--app-danger-soft-text)]`}`,children:B.text}),W&&W.diffs.length>0&&(0,N.jsx)(T,{className:`surface-accent`,children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`p`,{className:`text-sm font-medium text-[var(--app-text)]`,children:[`.env and DB have `,W.diffs.length,` different value(s)`]}),(0,N.jsx)(`p`,{className:`mt-1 text-xs text-[var(--app-text-muted)]`,children:W.diffs.map(e=>e.envKey).join(`, `)})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap gap-2 md:justify-end`,children:[(0,N.jsx)(_,{variant:`ghost`,size:`sm`,onClick:ie,children:`Sync DB → .env`}),(0,N.jsx)(_,{variant:`ghost`,size:`sm`,onClick:ae,children:`Load .env → DB`})]})]})}),Object.entries(P).map(([t,{label:n,paths:i,mutablePaths:o}])=>{let s=[...i,...o??[]],c=s.filter(e=>a.includes(e)).length;return(0,N.jsxs)(T,{children:[(0,N.jsxs)(`div`,{className:`mb-4 flex items-start justify-between gap-4`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-[var(--app-text)]`,children:n}),(0,N.jsx)(`p`,{className:`mt-1 text-sm text-[var(--app-text-muted)]`,children:F[t]??`Configuration values for this system area.`})]}),(0,N.jsxs)(`div`,{className:`rounded-full border border-[var(--app-border)] bg-black/10 px-3 py-1.5 text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:[c,`/`,s.length,` editable`]})]}),(0,N.jsx)(`div`,{className:`space-y-3`,children:s.map(t=>{let n=e[t];if(!n)return null;let i=a.includes(t),o=R[t]??t,s=v[t]??String(n.value??``),c=b.has(t),l=z[t];return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-[var(--app-border)] bg-black/10 px-3 py-3 md:flex-row md:items-center md:gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 md:w-56 md:shrink-0`,children:[!i&&(0,N.jsx)(r,{size:12,className:`text-[var(--app-text-subtle)]`}),(0,N.jsx)(`label`,{className:`text-sm text-[var(--app-text-muted)]`,children:o}),!i&&(0,N.jsx)(`span`,{className:`text-[10px] text-[var(--app-text-subtle)]`,children:`restart required`})]}),(0,N.jsx)(`div`,{className:`min-w-0 flex-1`,children:l?(0,N.jsx)(`select`,{className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel)] px-2 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none disabled:opacity-50`,value:s,onChange:e=>$(t,e.target.value),disabled:!i,children:l.map(e=>(0,N.jsx)(`option`,{value:e,children:e},e))}):(0,N.jsx)(`input`,{className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel)] px-2 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none disabled:opacity-50`,type:L.has(t)?`password`:`text`,value:s,onChange:e=>$(t,e.target.value),disabled:!i,placeholder:L.has(t)?`Enter to update`:void 0})}),(0,N.jsx)(`div`,{className:`text-left md:w-16 md:text-right`,children:c&&i&&(0,N.jsx)(`span`,{className:`text-[10px] text-[var(--app-warning)]`,children:`modified`})})]},t)})})]},t)}),(0,N.jsx)(j,{envVars:ne,onSave:()=>void Q(),mode:`global`,title:`Environment Variables`}),(0,N.jsx)(H,{}),(0,N.jsx)(V,{mutablePaths:a,listValues:K,listDirty:J,setListValues:q,setListDirty:e=>Y(e),dirty:b}),(0,N.jsx)(g,{open:Z.state===`blocked`,children:(0,N.jsxs)(d,{children:[(0,N.jsxs)(h,{children:[(0,N.jsx)(u,{children:`Unsaved Changes`}),(0,N.jsxs)(l,{children:[`You have `,b.size+J.size,` unsaved change(s). Discard and leave?`]})]}),(0,N.jsxs)(p,{children:[(0,N.jsx)(m,{onClick:()=>Z.reset?.(),children:`Stay`}),(0,N.jsx)(f,{onClick:()=>Z.proceed?.(),children:`Discard`})]})]})})]})}function V({mutablePaths:e,listValues:t,listDirty:n,setListValues:i,setListDirty:o,dirty:s}){let[c,l]=(0,M.useState)(``),[u,d]=(0,M.useState)(``),f=e.includes(`defaults.deniedReadPaths`),p=e.includes(`defaults.approvalRequired`),m=t[`defaults.deniedReadPaths`]??[],h=t[`defaults.approvalRequired`]??[],g=[`~/.ssh`,`~/.aws`,`~/.gnupg`,`/etc/shadow`],v=[`rm -rf *`,`git push*`,`git reset*`,`curl * -X POST*`,`curl * --request POST*`],y=e=>g.some(t=>e===(t.startsWith(`~/`),t)||e===t),b=e=>v.includes(e),x=()=>{let e=c.trim();!e||m.includes(e)||(i(t=>({...t,"defaults.deniedReadPaths":[...m,e]})),o(e=>new Set(e).add(`defaults.deniedReadPaths`)),l(``))},S=e=>{y(e)||(i(t=>({...t,"defaults.deniedReadPaths":m.filter(t=>t!==e)})),o(e=>new Set(e).add(`defaults.deniedReadPaths`)))},C=()=>{let e=u.trim();!e||h.includes(e)||(i(t=>({...t,"defaults.approvalRequired":[...h,e]})),o(e=>new Set(e).add(`defaults.approvalRequired`)),d(``))},w=e=>{b(e)||(i(t=>({...t,"defaults.approvalRequired":h.filter(t=>t!==e)})),o(e=>new Set(e).add(`defaults.approvalRequired`)))},E=s.size+n.size;return(0,N.jsxs)(T,{children:[(0,N.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-[var(--app-text)]`,children:`Advanced`}),E>0&&(0,N.jsxs)(`span`,{className:`text-[10px] text-[var(--app-warning)]`,children:[n.size,` modified`]})]}),(0,N.jsxs)(`div`,{className:`mb-6`,children:[(0,N.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,N.jsx)(`h3`,{className:`text-xs font-medium text-[var(--app-text-muted)]`,children:`Denied Read Paths`}),!f&&(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[(0,N.jsx)(r,{size:A.xs}),` restart required`]})]}),(0,N.jsxs)(`p`,{className:`mb-2 text-xs text-[var(--app-text-subtle)]`,children:[`Paths blocked at both the SDK and OS layer for all roles. System defaults (locked) cannot be removed. Uses `,(0,N.jsx)(`code`,{className:`text-[var(--app-text-muted)]`,children:`*`}),` as wildcard.`]}),(0,N.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:m.map(e=>{let t=y(e);return(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-xs ${t?`border-[var(--app-border)] bg-[var(--app-panel-elevated)] text-[var(--app-text-subtle)]`:`border-[var(--app-danger-soft-border)] bg-[var(--app-danger-soft-bg)] text-[var(--app-danger-soft-text)]`}`,children:[t&&(0,N.jsx)(r,{size:A.xs}),e,!t&&f&&(0,N.jsx)(`button`,{type:`button`,className:`ml-0.5 text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,onClick:()=>S(e),children:(0,N.jsx)(a,{size:A.xs})})]},e)})}),f&&(0,N.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,N.jsx)(`input`,{className:`flex-1 rounded border border-[var(--app-border)] bg-[var(--app-panel)] px-2 py-1 text-xs text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`/absolute/path or ~/path`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x())}}),(0,N.jsx)(_,{variant:`ghost`,size:`sm`,className:`scale-75`,onClick:()=>x(),children:`Add`})]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,N.jsx)(`h3`,{className:`text-xs font-medium text-[var(--app-text-muted)]`,children:`Approval Required Patterns`}),!p&&(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[(0,N.jsx)(r,{size:A.xs}),` restart required`]})]}),(0,N.jsxs)(`p`,{className:`mb-2 text-xs text-[var(--app-text-subtle)]`,children:[`Operations matching these glob patterns require user approval before execution. Uses SDK Permission Rule glob syntax (`,(0,N.jsx)(`code`,{className:`text-[var(--app-text-muted)]`,children:`*`}),` = wildcard, e.g.,`,` `,(0,N.jsx)(`code`,{className:`text-[var(--app-text-muted)]`,children:`rm -rf *`}),`).`]}),(0,N.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:h.map(e=>{let t=b(e);return(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-xs ${t?`border-[var(--app-border)] bg-[var(--app-panel-elevated)] text-[var(--app-text-subtle)]`:`border-[var(--app-warning-soft-border)] bg-[var(--app-warning-soft-bg)] text-[var(--app-warning-soft-text)]`}`,children:[t&&(0,N.jsx)(r,{size:A.xs}),e,!t&&p&&(0,N.jsx)(`button`,{type:`button`,className:`ml-0.5 text-[var(--app-warning)] hover:text-[var(--app-warning-soft-text)]`,onClick:()=>w(e),children:(0,N.jsx)(a,{size:A.xs})})]},e)})}),p&&(0,N.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,N.jsx)(`input`,{className:`flex-1 rounded border border-[var(--app-border)] bg-[var(--app-panel)] px-2 py-1 text-xs text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`e.g. "curl * --request POST *"`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),C())}}),(0,N.jsx)(_,{variant:`ghost`,size:`sm`,className:`scale-75`,onClick:()=>C(),children:`Add`})]})]})]})}function H(){let e=v()??``,[t,n]=(0,M.useState)(!1),[r,i]=(0,M.useState)(!1),[s,c]=(0,M.useState)(!1),[C,w]=(0,M.useState)(null),[E,O]=(0,M.useState)(null),k=e.length>12?e.slice(0,4)+`****`+e.slice(-4):`(no key in localStorage)`;async function j(){i(!0),O(null);try{let e=await S();y(e),w(e),c(!1)}catch(e){O(e instanceof Error?e.message:String(e)),c(!1)}finally{i(!1)}}function P(){x(),b()}return(0,N.jsxs)(T,{children:[(0,N.jsx)(D,{title:`Adam API Key`,description:`Rotate or sign out`}),(0,N.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`code`,{className:`flex-1 rounded bg-[var(--app-bg)] px-3 py-2 font-mono text-sm`,children:t?e||`(no key)`:k}),(0,N.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>n(e=>!e),children:t?`Hide`:`Show`})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>c(!0),disabled:r,children:[(0,N.jsx)(o,{size:A.xs,className:`mr-1`}),`Rotate key`]}),(0,N.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:P,children:[(0,N.jsx)(a,{size:A.xs,className:`mr-1`}),`Log out`]})]}),E&&(0,N.jsx)(`div`,{className:`rounded border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-400`,children:E}),(0,N.jsxs)(`p`,{className:`text-xs text-[var(--app-muted)]`,children:[`Rotating generates a new key, writes it to `,(0,N.jsx)(`code`,{children:`~/.adam/adam.key`}),`, and invalidates the old key on every device that uses the Adam API (Web UI, TUI, other browsers). Channel adapters (WeChat, Telegram, Discord) keep their own credentials and are NOT affected. Only external callers of your `,(0,N.jsx)(`code`,{children:`/webhooks/:name`}),` endpoints need the new key.`]})]}),(0,N.jsx)(g,{open:s,children:(0,N.jsxs)(d,{children:[(0,N.jsxs)(h,{children:[(0,N.jsx)(u,{children:`Rotate API key?`}),(0,N.jsxs)(l,{children:[`The old key stops working immediately. Other browsers/TUI sessions and any external callers of `,(0,N.jsx)(`code`,{children:`/webhooks/:name`}),` will return 401 until updated. Channel adapters (WeChat, Telegram, Discord) use their own credentials and are not affected.`]})]}),(0,N.jsxs)(p,{children:[(0,N.jsx)(m,{onClick:()=>c(!1),children:`Cancel`}),(0,N.jsx)(f,{onClick:j,disabled:r,children:r?`Rotating...`:`Rotate`})]})]})}),(0,N.jsx)(g,{open:!!C,children:(0,N.jsxs)(d,{children:[(0,N.jsxs)(h,{children:[(0,N.jsx)(u,{children:`New API key`}),(0,N.jsx)(l,{children:`Save this somewhere safe. Other devices and channels need to be updated with this key.`})]}),(0,N.jsx)(`code`,{className:`mt-2 block break-all rounded bg-[var(--app-bg)] p-3 font-mono text-xs`,children:C}),(0,N.jsxs)(p,{children:[(0,N.jsx)(f,{onClick:()=>{C&&navigator.clipboard.writeText(C)},children:`Copy`}),(0,N.jsx)(f,{onClick:()=>w(null),children:`Done`})]})]})})]})}export{B as Settings};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{$ as t,E as n,N as r,S as i,T as a,V as o,ct as s,et as c,it as l,s as u,tt as d,y as f}from"./vendor-icons-Dk0hMuJz.js";import{r as p,t as m}from"./vendor-react-C6faO6LO.js";import{n as h}from"./dist-CgGno8kE.js";import{_ as g,a as _,b as v,c as y,d as b,g as ee,i as te,n as x,o as ne,p as S,r as re,s as ie,t as ae,u as oe,v as se,x as C}from"./AlertDialog-B1zj0Qs3.js";import{i as w,t as T}from"./Button-BehrGSvy.js";import{t as ce}from"./vendor-state-DahK0J-G.js";import{t as E}from"./api-Bux34u4-.js";import{i as D,n as O,r as k,t as A}from"./index-B3_4_qY6.js";import{t as j}from"./Card-B5E56u94.js";import{t as M}from"./PageHeader-B2CgcZ-t.js";import{t as le}from"./SectionHeader-CmXz6PM3.js";import{a as ue,o as de,t as fe}from"./format-BUYXZqDw.js";import{t as pe}from"./EmptyState-tTclFq_B.js";import{t as me}from"./ui-CerQw0jA.js";import{t as he}from"./useIsMobileLayout-dYzXP1EC.js";import{a as ge,i as N,n as _e,o as ve,r as P,t as ye}from"./Table-CXAcZ8Ru.js";import{t as be}from"./Switch-yrTepsdl.js";import{Goals as xe,t as Se}from"./Goals-DYrggK-M.js";var F=e(s(),1),I=m();function Ce(e){let t=e+`CollectionProvider`,[n,r]=v(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=F.useRef(null),a=F.useRef(new Map).current;return(0,I.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=se(s),l=F.forwardRef((e,t)=>{let{scope:n,children:r}=e;return(0,I.jsx)(c,{ref:w(t,a(s,n).collectionRef),children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=se(u),p=F.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=F.useRef(null),s=w(t,o),c=a(u,n);return F.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,I.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return F.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var L=F.createContext(void 0);function R(e){let t=F.useContext(L);return e||t||`ltr`}var z=`rovingFocusGroup.onEntryFocus`,we={bubbles:!1,cancelable:!0},B=`RovingFocusGroup`,[V,Te,H]=Ce(B),[Ee,De]=v(B,[H]),[U,Oe]=Ee(B),W=F.forwardRef((e,t)=>(0,I.jsx)(V.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(V.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,I.jsx)(ke,{...e,ref:t})})}));W.displayName=B;var ke=F.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=F.useRef(null),p=w(t,f),m=R(a),[h,_]=oe({prop:o,defaultProp:s??null,onChange:c,caller:B}),[v,y]=F.useState(!1),b=ee(l),te=Te(n),x=F.useRef(!1),[ne,S]=F.useState(0);return F.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(z,b),()=>e.removeEventListener(z,b)},[b]),(0,I.jsx)(U,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:F.useCallback(e=>_(e),[_]),onItemShiftTab:F.useCallback(()=>y(!0),[]),onFocusableItemAdd:F.useCallback(()=>S(e=>e+1),[]),onFocusableItemRemove:F.useCallback(()=>S(e=>e-1),[]),children:(0,I.jsx)(g.div,{tabIndex:v||ne===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:C(e.onMouseDown,()=>{x.current=!0}),onFocus:C(e.onFocus,e=>{let t=!x.current;if(e.target===e.currentTarget&&t&&!v){let t=new CustomEvent(z,we);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=te().filter(e=>e.focusable);Pe([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}x.current=!1}),onBlur:C(e.onBlur,()=>y(!1))})})}),G=`RovingFocusGroupItem`,Ae=F.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=S(),l=a||c,u=Oe(G,n),d=u.currentTabStopId===l,f=Te(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u;return F.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),(0,I.jsx)(V.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,I.jsx)(g.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:C(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:C(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:C(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Ne(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Fe(n,r+1):n.slice(r+1)}setTimeout(()=>Pe(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})});Ae.displayName=G;var je={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function Me(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function Ne(e,t,n){let r=Me(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return je[r]}function Pe(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function Fe(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Ie=W,Le=Ae,K=`Tabs`,[Re,ze]=v(K,[De]),Be=De(),[Ve,q]=Re(K),J=F.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=R(s),[d,f]=oe({prop:r,onChange:i,defaultProp:a??``,caller:K});return(0,I.jsx)(Ve,{scope:n,baseId:S(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,I.jsx)(g.div,{dir:u,"data-orientation":o,...l,ref:t})})});J.displayName=K;var He=`TabsList`,Ue=F.forwardRef((e,t)=>{let{__scopeTabs:n,loop:r=!0,...i}=e,a=q(He,n),o=Be(n);return(0,I.jsx)(Ie,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,I.jsx)(g.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})});Ue.displayName=He;var We=`TabsTrigger`,Ge=F.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=q(We,n),s=Be(n),c=X(o.baseId,r),l=qe(o.baseId,r),u=r===o.value;return(0,I.jsx)(Le,{asChild:!0,...s,focusable:!i,active:u,children:(0,I.jsx)(g.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:C(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:C(e.onKeyDown,e=>{[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:C(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})});Ge.displayName=We;var Y=`TabsContent`,Ke=F.forwardRef((e,t)=>{let{__scopeTabs:n,value:r,forceMount:i,children:a,...o}=e,s=q(Y,n),c=X(s.baseId,r),l=qe(s.baseId,r),u=r===s.value,d=F.useRef(u);return F.useEffect(()=>{let e=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(e)},[]),(0,I.jsx)(b,{present:i||u,children:({present:n})=>(0,I.jsx)(g.div,{"data-state":u?`active`:`inactive`,"data-orientation":s.orientation,role:`tabpanel`,"aria-labelledby":c,hidden:!n,id:l,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:d.current?`0s`:void 0},children:n&&a})})});Ke.displayName=Y;function X(e,t){return`${e}-trigger-${t}`}function qe(e,t){return`${e}-content-${t}`}var Je=J,Ye=Ue,Xe=Ge,Ze=Ke,Qe=Je,$e=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(Ye,{ref:n,className:h(`surface-panel-muted inline-flex min-h-11 items-center justify-center gap-1 rounded-full p-1 text-[var(--app-text-muted)]`,e),...t}));$e.displayName=Ye.displayName;var Z=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(Xe,{ref:n,className:h(`inline-flex items-center justify-center whitespace-nowrap rounded-full px-4 py-2 text-sm font-medium ring-offset-[var(--app-canvas)] transition-[background-color,color,box-shadow] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:surface-panel data-[state=active]:text-[var(--app-text)] data-[state=active]:shadow-[var(--app-shadow-sm)]`,e),...t}));Z.displayName=Xe.displayName;var Q=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(Ze,{ref:n,className:h(`mt-4 ring-offset-[var(--app-canvas)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2`,e),...t}));Q.displayName=Ze.displayName;var et=[{label:`All`,value:`all`},{label:`Running`,value:`running`},{label:`Pending`,value:`pending`},{label:`Completed`,value:`completed`},{label:`Failed`,value:`failed`},{label:`Cancelled`,value:`cancelled`},{label:`Blocked`,value:`blocked`}],$=new Set([`pending`,`queued`,`running`,`paused`]);function tt(){let e=k(e=>e.tasks),t=k(e=>e.fetchTasks),[n,a]=(0,F.useState)(`all`),[o,s]=(0,F.useState)(!1),[c,u]=(0,F.useState)(``),[m,h]=(0,F.useState)(!1),[g,_]=(0,F.useState)(new Set),[v,y]=(0,F.useState)(!1),b=he();(0,F.useEffect)(()=>{let e=n===`all`?void 0:n;t(e);let r=setInterval(()=>void t(e),5e3);return()=>clearInterval(r)},[t,n]),(0,F.useEffect)(()=>{_(new Set)},[n]);let ee=async()=>{if(c.trim()){h(!0);try{await E(`/tasks`,{method:`POST`,body:JSON.stringify({prompt:c.trim()})}),u(``),s(!1),t(n===`all`?void 0:n)}finally{h(!1)}}},te=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},x=()=>{let e=S.filter(e=>$.has(e.status)).map(e=>e.id);_(new Set(e))},ne=async()=>{if(g.size!==0){y(!0);try{await E(`/tasks/batch-cancel`,{method:`POST`,body:JSON.stringify({taskIds:Array.from(g)})}),_(new Set),t(n===`all`?void 0:n)}finally{y(!1)}}},S=[...e].sort((e,t)=>t.createdAt-e.createdAt),re=Array.from(g).filter(t=>{let n=e.find(e=>e.id===t);return n&&$.has(n.status)});return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(le,{title:`Tasks`,description:`Review active execution, cancel work, or create the next task.`,compact:!0,action:(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[g.size>0&&(0,I.jsxs)(T,{variant:`destructive`,size:`sm`,onClick:()=>void ne(),disabled:v||re.length===0,children:[(0,I.jsx)(l,{size:me.sm}),v?`Cancelling...`:`Cancel ${re.length} task${re.length===1?``:`s`}`]}),(0,I.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>void t(n===`all`?void 0:n),children:(0,I.jsx)(f,{size:me.sm})}),(0,I.jsxs)(T,{size:`sm`,onClick:()=>s(!o),children:[(0,I.jsx)(i,{size:me.sm}),`New Task`]})]})}),o&&(0,I.jsxs)(j,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Enter task prompt...`,value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ee()}}),(0,I.jsx)(T,{onClick:()=>void ee(),disabled:m||!c.trim(),children:m?`Creating...`:`Create`}),(0,I.jsx)(T,{variant:`ghost`,onClick:()=>s(!1),children:`Cancel`})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 md:flex-row md:items-center md:justify-between`,children:[(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:et.map(e=>(0,I.jsx)(`button`,{onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs font-medium transition-colors ${n===e.value?`bg-[var(--app-panel-elevated)] text-[var(--app-text)]`:`text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`}`,children:e.label},e.value))}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[S.some(e=>$.has(e.status))&&(0,I.jsx)(`button`,{onClick:x,className:`text-xs text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`,children:`Select all cancellable`}),g.size>0&&(0,I.jsxs)(`button`,{onClick:()=>_(new Set),className:`text-xs text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`,children:[`Clear selection (`,g.size,`)`]})]})]}),S.length===0?(0,I.jsx)(j,{padding:!1,children:(0,I.jsx)(pe,{icon:(0,I.jsx)(r,{size:32}),title:`No tasks found`,description:n===`all`?`Create a task to get started`:`No tasks with status "${n}"`})}):b?(0,I.jsx)(`div`,{className:`space-y-3`,children:S.map(e=>(0,I.jsx)(j,{className:g.has(e.id)?`border-[var(--app-accent)]/40 bg-[var(--app-accent)]/8`:``,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`pt-1`,children:$.has(e.status)?(0,I.jsx)(`button`,{onClick:()=>te(e.id),className:`flex h-4 w-4 items-center justify-center rounded border transition-colors ${g.has(e.id)?`border-[var(--app-accent-strong)] bg-[var(--app-accent)] text-white`:`border-[var(--app-border-strong)] bg-transparent hover:border-[var(--app-text-muted)]`}`,children:g.has(e.id)&&(0,I.jsx)(d,{size:12})}):(0,I.jsx)(`span`,{className:`inline-block h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,I.jsx)(p,{to:`/tasks/${e.id}`,className:`break-all font-mono text-xs text-[var(--app-accent)] hover:text-[var(--app-accent)]`,children:e.id.slice(0,8)}),(0,I.jsx)(`p`,{className:`break-words text-sm font-medium leading-6 text-[var(--app-text)]`,children:de(e.prompt,140)})]}),(0,I.jsx)(A,{variant:O(e.status),children:e.status})]}),(0,I.jsxs)(`div`,{className:`grid gap-2 text-xs text-[var(--app-text-subtle)] sm:grid-cols-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Role`}),(0,I.jsx)(`div`,{className:`mt-1 font-mono text-[var(--app-text)]`,children:e.roleId?e.roleId.slice(0,12):`—`})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Cost`}),(0,I.jsx)(`div`,{className:`mt-1 font-mono text-[var(--app-text)]`,children:e.costUsd==null?`—`:fe(e.costUsd)})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`span`,{className:`text-[10px] uppercase tracking-[0.14em] text-[var(--app-text-subtle)]`,children:`Created`}),(0,I.jsx)(`div`,{className:`mt-1 text-[var(--app-text)]`,children:ue(e.createdAt)})]})]})]})]})},e.id))}):(0,I.jsx)(j,{padding:!1,children:(0,I.jsxs)(ye,{children:[(0,I.jsx)(ge,{children:(0,I.jsxs)(ve,{children:[(0,I.jsx)(N,{className:`w-8`,children:(0,I.jsx)(`button`,{onClick:()=>{g.size>0&&g.size===S.filter(e=>$.has(e.status)).length?_(new Set):x()},className:`flex h-4 w-4 items-center justify-center rounded border transition-colors ${g.size>0&&g.size===S.filter(e=>$.has(e.status)).length?`border-[var(--app-accent-strong)] bg-[var(--app-accent)] text-white`:`border-[var(--app-border-strong)] bg-transparent hover:border-[var(--app-text-muted)]`}`,children:g.size>0&&g.size===S.filter(e=>$.has(e.status)).length&&(0,I.jsx)(d,{size:12})})}),(0,I.jsx)(N,{children:`ID`}),(0,I.jsx)(N,{children:`Prompt`}),(0,I.jsx)(N,{children:`Status`}),(0,I.jsx)(N,{children:`Role`}),(0,I.jsx)(N,{children:`Cost`}),(0,I.jsx)(N,{children:`Created`})]})}),(0,I.jsx)(_e,{children:S.map(e=>(0,I.jsxs)(ve,{className:g.has(e.id)?`bg-[var(--app-panel-elevated)]/50`:``,children:[(0,I.jsx)(P,{children:$.has(e.status)?(0,I.jsx)(`button`,{onClick:()=>te(e.id),className:`flex h-4 w-4 items-center justify-center rounded border transition-colors ${g.has(e.id)?`border-[var(--app-accent-strong)] bg-[var(--app-accent)] text-white`:`border-[var(--app-border-strong)] bg-transparent hover:border-[var(--app-text-muted)]`}`,children:g.has(e.id)&&(0,I.jsx)(d,{size:12})}):(0,I.jsx)(`span`,{className:`inline-block w-4`})}),(0,I.jsx)(P,{children:(0,I.jsx)(p,{to:`/tasks/${e.id}`,className:`font-mono text-xs text-[var(--app-accent)] hover:text-[var(--app-accent)]`,children:e.id.slice(0,8)})}),(0,I.jsx)(P,{children:(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`div`,{className:`break-words font-medium text-[var(--app-text)]`,children:de(e.prompt,120)}),(0,I.jsxs)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:[e.totalDurationMs?fe(e.costUsd??0):`Awaiting completion`,` · `,ue(e.createdAt)]})]})}),(0,I.jsx)(P,{children:(0,I.jsx)(A,{variant:O(e.status),children:e.status})}),(0,I.jsx)(P,{children:(0,I.jsx)(`span`,{className:`font-mono text-xs text-[var(--app-text-subtle)]`,children:e.roleId?e.roleId.slice(0,12):`—`})}),(0,I.jsx)(P,{className:`font-mono text-xs`,children:e.costUsd==null?`—`:fe(e.costUsd)}),(0,I.jsx)(P,{className:`text-xs text-[var(--app-text-subtle)]`,children:ue(e.createdAt)})]},e.id))})]})})]})}function nt(e){return`step-${e+1}`}function rt(){let e=k(e=>e.templates),r=k(e=>e.fetchTemplates),s=k(e=>e.goals),l=k(e=>e.fetchGoals),d=k(e=>e.roles),p=k(e=>e.fetchRoles),[m,h]=(0,F.useState)(!1),[g,v]=(0,F.useState)(``),[b,ee]=(0,F.useState)(`manual`),[S,oe]=(0,F.useState)(``),[se,C]=(0,F.useState)(``),[w,ce]=(0,F.useState)(``),[O,M]=(0,F.useState)([{id:`step-1`,prompt:``}]),[de,fe]=(0,F.useState)(!1),[me,he]=(0,F.useState)(!1),[xe,Ce]=(0,F.useState)(null),[L,R]=(0,F.useState)(null),[z,we]=(0,F.useState)(null),[B,V]=(0,F.useState)(null),[Te,H]=(0,F.useState)(`template_only`),[Ee,De]=(0,F.useState)(!1),[U,Oe]=(0,F.useState)(null),[W,ke]=(0,F.useState)(``),[G,Ae]=(0,F.useState)(`manual`),[je,Me]=(0,F.useState)(``),[Ne,Pe]=(0,F.useState)(``),[Fe,Ie]=(0,F.useState)(``),[Le,K]=(0,F.useState)(``),[Re,ze]=(0,F.useState)(``),[Be,Ve]=(0,F.useState)([]),[q,J]=(0,F.useState)([]),[He,Ue]=(0,F.useState)(!1),[We,Ge]=(0,F.useState)(!1),[Y,Ke]=(0,F.useState)(`prompt`),[X,qe]=(0,F.useState)([]),[Je,Ye]=(0,F.useState)([]),[Xe,Ze]=(0,F.useState)([]),[Qe,$e]=(0,F.useState)(null),[Z,Q]=(0,F.useState)([]),[et,$]=(0,F.useState)(!1),tt=(0,F.useCallback)(async e=>{$(!0);try{let t=await E(`/workflow-executions?templateId=${e}&limit=5`);Q(await Promise.all(t.executions.map(async e=>{try{let t=await E(`/workflow-executions/${e.id}`);return{...t.execution,stepTasks:t.stepTasks}}catch{return{...e,stepTasks:[]}}})))}catch{Q([])}finally{$(!1)}},[]),rt=(0,F.useCallback)(e=>{Qe===e?($e(null),Q([])):($e(e),tt(e))},[Qe,tt]),it=(0,F.useMemo)(()=>Object.fromEntries(e.map(e=>[e.id,e.name])),[e]),at=e=>e.type===`cron`?`Cron: ${e.cron??`—`}`:e.type===`once`?`Once at ${e.runAt?new Date(e.runAt).toLocaleString():`—`}`:e.type===`template_complete`?`When template '${it[e.event?.split(`:`)[1]??``]??`[deleted template]`}' completes`:e.type===`event`?`On event '${Be.find(t=>t.id===e.eventDefId)?.name??`[deleted event]`}'`:e.type;(0,F.useEffect)(()=>{r(),l(),p(),(async()=>{try{Ve(await E(`/event-defs`))}catch{}})()},[r,l,p]);let ot=async()=>{if(g.trim()&&!(Y===`prompt`&&O.every(e=>!e.prompt.trim()))&&!(Y===`goal`&&X.length===0)){he(!0);try{let e={name:g.trim(),trigger:{type:b,...b===`cron`&&se?{cron:se}:{},...b===`once`&&w?{runAt:new Date(w).toISOString()}:{},...b===`template_complete`&&S?{event:`template_complete:${S}`}:{},...b===`event`&&Le?{eventDefId:Le}:{}},enabled:!0,...Je.length>0?{deliverTo:Je}:{},...de?{config:{continueOnError:!0}}:{}};Y===`prompt`?e.steps=O.filter(e=>e.prompt.trim()).map((e,t)=>({id:e.id||nt(t),prompt:e.prompt.trim(),...e.roleId?{roleId:e.roleId}:{},...e.dependsOn&&e.dependsOn.length>0?{dependsOn:e.dependsOn}:{},...e.config&&(e.config.timeout!==void 0||e.config.maxTurns!==void 0)?{config:e.config}:{}})):(e.goalIds=X,e.steps=[]),await E(`/task-templates`,{method:`POST`,body:JSON.stringify(e)}),v(``),M([{id:`step-1`,prompt:``}]),C(``),ce(``),oe(``),K(``),qe([]),Ye([]),h(!1),r()}finally{he(!1)}}},st=async t=>{let n=e.find(e=>e.id===t);Ce(t);try{await E(`/task-templates/${t}/run`,{method:`POST`}),D.success(`Triggered: ${n?.name??t}`)}catch(e){let t=e instanceof Error?e.message:`Failed to trigger template`;D.error(`Trigger failed: ${t}`)}finally{Ce(null)}},ct=async e=>{we(e),H(`template_only`),V(null);try{V((await E(`/task-templates/${e}/dependents`)).dependents)}catch{V({executionCount:0,taskCount:0})}},lt=async(t,n)=>{let i=e.find(e=>e.id===t);De(!0);try{let e=await E(`/task-templates/${t}?mode=${n}`,{method:`DELETE`}),a=[];e.deletedCounts.workflowExecutions>0&&a.push(`${e.deletedCounts.workflowExecutions} execution${e.deletedCounts.workflowExecutions===1?``:`s`}`),e.deletedCounts.tasks>0&&a.push(`${e.deletedCounts.tasks} task${e.deletedCounts.tasks===1?``:`s`}`);let o=a.length?` (+ ${a.join(`, `)})`:``;D.success(`Deleted: ${i?.name??t}${o}`),r()}catch(e){let t=e instanceof Error?e.message:`Failed to delete template`;D.error(`Delete failed: ${t}`)}finally{De(!1)}},ut=async t=>{let n=e.find(e=>e.id===t);if(!n)return;if(![`cron`,`once`,`template_complete`].includes(n.trigger.type)){D.error(`Toggle not applicable for manual triggers`);return}let i=!n.enabled;try{await E(`/task-templates/${t}`,{method:`PATCH`,body:JSON.stringify({enabled:i})}),D.success(`${n.name} ${i?`enabled`:`disabled`}`),r()}catch(e){let t=e instanceof Error?e.message:`Failed to toggle template`;D.error(`Toggle failed: ${t}`)}},dt=e=>{Oe(e.id),ke(e.name),Ae(e.trigger.type===`workflow_complete`?`template_complete`:e.trigger.type),Me(e.trigger.cron??``),Pe(e.trigger.runAt?new Date(e.trigger.runAt).toISOString().slice(0,16):``),J(e.steps.map(e=>({id:e.id,prompt:e.prompt,roleId:e.roleId,dependsOn:e.dependsOn,config:e.config}))),Ue(e.config?.continueOnError??!1),Ze(e.deliverTo??[]),Ie(e.trigger.type===`template_complete`||e.trigger.type===`workflow_complete`?e.trigger.event?.split(`:`)[1]??``:``),ze(e.trigger.eventDefId??``)},ft=async()=>{if(!(!U||!W.trim()||q.every(e=>!e.prompt.trim()))){Ge(!0);try{await E(`/task-templates/${U}`,{method:`PATCH`,body:JSON.stringify({name:W.trim(),trigger:{type:G,...G===`cron`&&je?{cron:je}:{},...G===`once`&&Ne?{runAt:new Date(Ne).toISOString()}:{},...G===`template_complete`&&Fe?{event:`template_complete:${Fe}`}:{},...G===`event`&&Re?{eventDefId:Re}:{}},steps:q.filter(e=>e.prompt.trim()).map((e,t)=>({id:e.id||nt(t),prompt:e.prompt.trim(),...e.roleId?{roleId:e.roleId}:{},...e.dependsOn&&e.dependsOn.length>0?{dependsOn:e.dependsOn}:{},...e.config&&(e.config.timeout!==void 0||e.config.maxTurns!==void 0)?{config:e.config}:{}})),enabled:e.find(e=>e.id===U)?.enabled??!0,...He?{config:{continueOnError:!0}}:{config:{}},deliverTo:Xe.length>0?Xe:void 0})}),Oe(null),r(),D.success(`Template updated`)}catch(e){let t=e instanceof Error?e.message:`Failed to update template`;D.error(t)}finally{Ge(!1)}}},pt=e.find(e=>e.id===L),mt=e.find(e=>e.id===z);return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(le,{title:`Automations`,description:`Reusable workflows, manual triggers, and recent workflow runs.`,compact:!0,action:(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>void r(),children:(0,I.jsx)(f,{size:14})}),(0,I.jsxs)(T,{size:`sm`,onClick:()=>h(!m),children:[(0,I.jsx)(i,{size:14}),`New Automation`]})]})}),m&&(0,I.jsxs)(j,{className:`space-y-3`,children:[(0,I.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Template name`,value:g,onChange:e=>v(e.target.value)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Triggered by:`}),(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:b,onChange:e=>ee(e.target.value),children:[(0,I.jsx)(`option`,{value:`manual`,children:`Manual`}),(0,I.jsx)(`option`,{value:`cron`,children:`Schedule (Cron)`}),(0,I.jsx)(`option`,{value:`once`,children:`One-time`}),(0,I.jsx)(`option`,{value:`template_complete`,children:`Template completion`}),(0,I.jsx)(`option`,{value:`event`,children:`Event (definition)`})]}),b===`template_complete`&&(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:S,onChange:e=>oe(e.target.value),children:[(0,I.jsx)(`option`,{value:``,children:`-- Select target template --`}),e.filter(e=>e.id!==U).map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),b===`event`&&(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:Le,onChange:e=>K(e.target.value),children:[(0,I.jsx)(`option`,{value:``,children:`-- Select event --`}),Be.map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),b===`cron`&&(0,I.jsx)(`input`,{className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Cron expression (e.g. */5 * * * *)`,value:se,onChange:e=>C(e.target.value)}),b===`once`&&(0,I.jsx)(`input`,{type:`datetime-local`,className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:w,onChange:e=>ce(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Action type:`}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:()=>Ke(`prompt`),className:`rounded px-2 py-1 text-xs ${Y===`prompt`?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-muted)] hover:text-[var(--app-text)]`}`,children:`Custom Prompt`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>Ke(`goal`),className:`rounded px-2 py-1 text-xs ${Y===`goal`?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-muted)] hover:text-[var(--app-text)]`}`,children:`Goal Reference`})]})]}),Y===`prompt`?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Steps`}),(0,I.jsxs)(T,{variant:`ghost`,size:`sm`,onClick:()=>M([...O,{id:nt(O.length),prompt:``}]),children:[(0,I.jsx)(i,{size:12}),` Add Step`]})]}),O.map((e,t)=>(0,I.jsxs)(`div`,{className:`rounded-md border border-[var(--app-border)] p-2 space-y-1.5`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--app-text-subtle)]`,children:e.id}),(0,I.jsxs)(`select`,{className:`flex-1 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1 text-xs text-[var(--app-text)]`,value:e.roleId??``,onChange:n=>{let r=[...O];r[t]={...e,roleId:n.target.value||void 0},M(r)},children:[(0,I.jsx)(`option`,{value:``,children:`Role (template default)`}),d.filter(e=>e.source!==`system`).map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),O.length>1&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>M(O.filter((e,n)=>n!==t)),className:`text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,children:(0,I.jsx)(u,{size:12})})]}),(0,I.jsx)(`textarea`,{className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Step ${t+1} prompt${t>0?` (use {{`+O[t-1].id+`.result}} for prev output)`:``}`,rows:2,value:e.prompt,onChange:n=>{let r=[...O];r[t]={...e,prompt:n.target.value},M(r)}}),t>0&&(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(`span`,{className:`text-[10px] text-[var(--app-text-subtle)]`,children:`depends on:`}),O.slice(0,t).map(n=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>{let r=e.dependsOn??[],i=[...O];i[t]={...e,dependsOn:r.includes(n.id)?r.filter(e=>e!==n.id):[...r,n.id]},M(i)},className:`rounded px-1.5 py-0.5 text-[10px] ${(e.dependsOn??[]).includes(n.id)?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`}`,children:n.id},n.id))]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[`timeout(s):`,(0,I.jsx)(`input`,{type:`number`,min:0,placeholder:`default`,className:`w-20 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-1.5 py-0.5 text-xs text-[var(--app-text)]`,value:e.config?.timeout??``,onChange:n=>{let r=[...O],i=n.target.value===``?void 0:Number(n.target.value);r[t]={...e,config:{...e.config,timeout:i}},M(r)}})]}),(0,I.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[`max turns:`,(0,I.jsx)(`input`,{type:`number`,min:0,placeholder:`default`,className:`w-20 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-1.5 py-0.5 text-xs text-[var(--app-text)]`,value:e.config?.maxTurns??``,onChange:n=>{let r=[...O],i=n.target.value===``?void 0:Number(n.target.value);r[t]={...e,config:{...e.config,maxTurns:i}},M(r)}})]})]})]},e.id))]}):(0,I.jsx)(`div`,{className:`space-y-1`,children:s.length===0?(0,I.jsx)(`p`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`No goals available`}):s.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-[var(--app-text)] hover:text-[var(--app-text)] cursor-pointer`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:X.includes(e.id),onChange:t=>{t.target.checked?qe([...X,e.id]):qe(X.filter(t=>t!==e.id))},className:`rounded border-[var(--app-border-strong)] bg-[var(--app-panel-elevated)]`}),(0,I.jsx)(`span`,{className:`truncate`,children:e.name}),(0,I.jsx)(A,{variant:`muted`,className:`text-[10px]`,children:e.status})]},e.id))}),O.length>1&&(0,I.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-[var(--app-text)] cursor-pointer`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:de,onChange:e=>fe(e.target.checked),className:`rounded border-[var(--app-border-strong)] bg-[var(--app-panel-elevated)]`}),`Continue on error (skip failed step dependents, run independent steps)`]}),(0,I.jsx)(Se,{value:Je,onChange:Ye}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(T,{onClick:()=>void ot(),disabled:me||!g.trim()||Y===`prompt`&&O.every(e=>!e.prompt.trim())||Y===`goal`&&X.length===0||b===`template_complete`&&!S,children:me?`Creating...`:`Create`}),(0,I.jsx)(T,{variant:`ghost`,onClick:()=>h(!1),children:`Cancel`})]})]}),U!==null&&(0,I.jsxs)(j,{className:`space-y-3`,children:[(0,I.jsx)(`span`,{className:`text-sm font-medium text-[var(--app-text)]`,children:`Edit Automation`}),(0,I.jsx)(`input`,{className:`w-full rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Template name`,value:W,onChange:e=>ke(e.target.value)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Triggered by:`}),(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:G,onChange:e=>Ae(e.target.value),children:[(0,I.jsx)(`option`,{value:`manual`,children:`Manual`}),(0,I.jsx)(`option`,{value:`cron`,children:`Schedule (Cron)`}),(0,I.jsx)(`option`,{value:`once`,children:`One-time`}),(0,I.jsx)(`option`,{value:`template_complete`,children:`Template completion`}),(0,I.jsx)(`option`,{value:`event`,children:`Event (definition)`})]}),G===`template_complete`&&(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:Fe,onChange:e=>Ie(e.target.value),children:[(0,I.jsx)(`option`,{value:``,children:`-- Select target template --`}),e.filter(e=>e.id!==U).map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),G===`event`&&(0,I.jsxs)(`select`,{className:`rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:Re,onChange:e=>ze(e.target.value),children:[(0,I.jsx)(`option`,{value:``,children:`-- Select event --`}),Be.map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),G===`cron`&&(0,I.jsx)(`input`,{className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Cron expression`,value:je,onChange:e=>Me(e.target.value)}),G===`once`&&(0,I.jsx)(`input`,{type:`datetime-local`,className:`flex-1 rounded-md border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-3 py-1.5 text-sm text-[var(--app-text)] focus:border-[var(--app-accent)] focus:outline-none`,value:Ne,onChange:e=>Pe(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-muted)]`,children:`Steps`}),(0,I.jsxs)(T,{variant:`ghost`,size:`sm`,onClick:()=>J([...q,{id:nt(q.length),prompt:``}]),children:[(0,I.jsx)(i,{size:12}),` Add Step`]})]}),q.map((e,t)=>(0,I.jsxs)(`div`,{className:`rounded-md border border-[var(--app-border)] p-2 space-y-1.5`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--app-text-subtle)]`,children:e.id}),(0,I.jsxs)(`select`,{className:`flex-1 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1 text-xs text-[var(--app-text)]`,value:e.roleId??``,onChange:n=>{let r=[...q];r[t]={...e,roleId:n.target.value||void 0},J(r)},children:[(0,I.jsx)(`option`,{value:``,children:`Role (template default)`}),d.filter(e=>e.source!==`system`).map(e=>(0,I.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),q.length>1&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>J(q.filter((e,n)=>n!==t)),className:`text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,children:(0,I.jsx)(u,{size:12})})]}),(0,I.jsx)(`textarea`,{className:`w-full rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-2 py-1.5 text-sm text-[var(--app-text)] placeholder:text-[var(--app-text-subtle)] focus:border-[var(--app-accent)] focus:outline-none`,placeholder:`Step ${t+1} prompt`,rows:2,value:e.prompt,onChange:n=>{let r=[...q];r[t]={...e,prompt:n.target.value},J(r)}}),t>0&&(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(`span`,{className:`text-[10px] text-[var(--app-text-subtle)]`,children:`depends on:`}),q.slice(0,t).map(n=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>{let r=e.dependsOn??[],i=[...q];i[t]={...e,dependsOn:r.includes(n.id)?r.filter(e=>e!==n.id):[...r,n.id]},J(i)},className:`rounded px-1.5 py-0.5 text-[10px] ${(e.dependsOn??[]).includes(n.id)?`bg-[var(--app-accent)] text-white`:`bg-[var(--app-panel-elevated)] text-[var(--app-text-subtle)] hover:text-[var(--app-text)]`}`,children:n.id},n.id))]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[`timeout(s):`,(0,I.jsx)(`input`,{type:`number`,min:0,placeholder:`default`,className:`w-20 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-1.5 py-0.5 text-xs text-[var(--app-text)]`,value:e.config?.timeout??``,onChange:n=>{let r=[...q],i=n.target.value===``?void 0:Number(n.target.value);r[t]={...e,config:{...e.config,timeout:i}},J(r)}})]}),(0,I.jsxs)(`label`,{className:`flex items-center gap-1 text-[10px] text-[var(--app-text-subtle)]`,children:[`max turns:`,(0,I.jsx)(`input`,{type:`number`,min:0,placeholder:`default`,className:`w-20 rounded border border-[var(--app-border)] bg-[var(--app-panel-elevated)] px-1.5 py-0.5 text-xs text-[var(--app-text)]`,value:e.config?.maxTurns??``,onChange:n=>{let r=[...q],i=n.target.value===``?void 0:Number(n.target.value);r[t]={...e,config:{...e.config,maxTurns:i}},J(r)}})]})]})]},e.id))]}),q.length>1&&(0,I.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-[var(--app-text)] cursor-pointer`,children:[(0,I.jsx)(`input`,{type:`checkbox`,checked:He,onChange:e=>Ue(e.target.checked),className:`rounded border-[var(--app-border-strong)] bg-[var(--app-panel-elevated)]`}),`Continue on error`]}),(0,I.jsx)(Se,{value:Xe,onChange:Ze}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(T,{onClick:()=>void ft(),disabled:We||!W.trim()||q.every(e=>!e.prompt.trim()),children:We?`Saving...`:`Save`}),(0,I.jsx)(T,{variant:`ghost`,onClick:()=>Oe(null),children:`Cancel`})]})]}),(0,I.jsx)(j,{padding:!1,children:e.length===0?(0,I.jsx)(pe,{icon:(0,I.jsx)(o,{size:32}),title:`No automations`,description:`Create an automation to run recurring tasks`}):(0,I.jsxs)(ye,{children:[(0,I.jsx)(ge,{children:(0,I.jsxs)(ve,{children:[(0,I.jsx)(N,{children:`Name`}),(0,I.jsx)(N,{children:`Trigger`}),(0,I.jsx)(N,{children:`Schedule`}),(0,I.jsx)(N,{children:`Steps`}),(0,I.jsx)(N,{children:`Enabled`}),(0,I.jsx)(N,{children:`Created`}),(0,I.jsx)(N,{children:`Webhook URL`}),(0,I.jsx)(N,{children:`Actions`})]})}),(0,I.jsx)(_e,{children:e.map(e=>(0,I.jsxs)(F.Fragment,{children:[(0,I.jsxs)(ve,{children:[(0,I.jsx)(P,{className:`font-medium text-[var(--app-text)]`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>rt(e.id),className:`flex items-center gap-1 hover:text-[var(--app-accent)] transition-colors`,children:[Qe===e.id?(0,I.jsx)(c,{size:12}):(0,I.jsx)(t,{size:12}),e.name]})}),(0,I.jsx)(P,{children:(0,I.jsx)(A,{variant:e.trigger.type===`cron`?`info`:(e.trigger.type,`muted`),children:at(e.trigger)})}),(0,I.jsx)(P,{className:`font-mono text-xs`,children:e.trigger.type===`once`&&e.trigger.runAt?new Date(e.trigger.runAt).toLocaleString():e.trigger.cron??`—`}),(0,I.jsx)(P,{className:`font-mono text-xs`,children:e.goalIds&&e.goalIds.length>0?`Goals: ${e.goalIds.length}`:(()=>{let t=new Set(e.steps.filter(e=>e.roleId).map(e=>e.roleId));return t.size>0?`${e.steps.length} steps / ${t.size} roles`:String(e.steps.length)})()}),(0,I.jsx)(P,{children:[`cron`,`once`,`template_complete`].every(t=>e.trigger.type!==t)?(0,I.jsx)(`span`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`—`}):(0,I.jsx)(be,{checked:e.enabled,onCheckedChange:()=>void ut(e.id),"aria-label":`Toggle ${e.name}`})}),(0,I.jsx)(P,{className:`text-xs text-[var(--app-text-subtle)]`,children:e.createdAt?ue(e.createdAt):`—`}),(0,I.jsx)(P,{className:`font-mono text-xs text-[var(--app-text-muted)]`,children:e.enabled?`POST /webhooks/${e.id}`:`—`}),(0,I.jsx)(P,{children:(0,I.jsxs)(`div`,{className:`flex gap-1`,children:[(0,I.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>dt(e),title:`Edit`,children:(0,I.jsx)(n,{size:12})}),(0,I.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>R(e.id),disabled:xe===e.id,title:`Run now`,children:(0,I.jsx)(a,{size:12})}),(0,I.jsx)(T,{variant:`ghost`,size:`sm`,className:`text-[var(--app-danger)] hover:text-[var(--app-danger-soft-text)]`,onClick:()=>{ct(e.id)},title:`Delete`,children:(0,I.jsx)(u,{size:12})})]})})]}),Qe===e.id&&(0,I.jsx)(ve,{children:(0,I.jsxs)(P,{colSpan:8,className:`bg-[var(--app-panel)]/50 p-3`,children:[(0,I.jsx)(`div`,{className:`text-xs text-[var(--app-text-muted)] mb-2 font-medium`,children:`Recent Executions`}),et?(0,I.jsx)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`Loading...`}):Z.length===0?(0,I.jsx)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`No executions yet`}):(0,I.jsx)(`div`,{className:`space-y-1.5`,children:Z.map(t=>{let n=Object.entries(t.stepStatuses),r=n.filter(([,e])=>e.status===`completed`).length,i=n.filter(([,e])=>e.status===`failed`).length,a=n.filter(([,e])=>e.status===`skipped`).length,o=n.filter(([,e])=>e.status===`cancelled`).length,s=n.length,c=new Map(t.stepTasks.filter(e=>e.stepId).map(e=>[e.stepId,e])),l=[...e.steps.map(e=>e.id),...Object.keys(t.stepStatuses).filter(t=>!e.steps.some(e=>e.id===t))];return(0,I.jsxs)(`div`,{className:`rounded border border-[var(--app-border)] bg-[var(--app-canvas)]/50 p-2.5 space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,I.jsx)(A,{variant:t.status===`completed`?`success`:t.status===`failed`?`destructive`:t.status===`partial`?`warning`:t.status===`cancelled`?`secondary`:`muted`,children:t.status}),(0,I.jsx)(`span`,{className:`text-[var(--app-text-subtle)]`,children:new Date(t.startedAt).toLocaleString()}),s>0&&(0,I.jsxs)(`span`,{className:`text-[var(--app-text-muted)]`,children:[r,`/`,s,` steps`,(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[i>0&&(0,I.jsxs)(`span`,{className:`text-[var(--app-danger)]`,children:[i,` failed`]}),a>0&&(0,I.jsxs)(`span`,{className:`text-[var(--app-warning)]`,children:[a,` skipped`]}),o>0&&(0,I.jsxs)(`span`,{className:`text-[var(--app-text)]`,children:[o,` cancelled`]})]})]}),t.completedAt&&(0,I.jsxs)(`span`,{className:`text-[var(--app-text-subtle)]`,children:[Math.round((t.completedAt-t.startedAt)/1e3),`s`]}),(0,I.jsx)(`span`,{className:`font-mono text-[var(--app-text-subtle)] truncate max-w-[120px]`,children:t.id.slice(0,8)})]}),(0,I.jsx)(`div`,{className:`space-y-1.5`,children:l.map(n=>{let r=t.stepStatuses[n];if(!r)return null;let i=e.steps.find(e=>e.id===n),a=c.get(n),o=a?.roleId??r.roleId??i?.roleId,s=d.find(e=>e.id===o)?.name??o,l=a?.error??r.error??a?.result??r.result;return(0,I.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] gap-2 rounded bg-[var(--app-panel)]/60 px-2 py-1.5 text-xs`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`font-mono text-[var(--app-text)]`,children:n}),s&&(0,I.jsxs)(`span`,{className:`text-[var(--app-warning-soft-text)]`,children:[`@`,s]}),i?.dependsOn&&i.dependsOn.length>0&&(0,I.jsxs)(`span`,{className:`text-[var(--app-text-subtle)]`,children:[`after `,i.dependsOn.join(`, `)]})]}),l&&(0,I.jsx)(`div`,{className:`mt-1 truncate ${r.status===`failed`?`text-[var(--app-danger-soft-text)]`:r.status===`skipped`?`text-[var(--app-warning-soft-text)]`:r.status===`cancelled`?`text-[var(--app-text)]`:`text-[var(--app-text-muted)]`}`,children:l})]}),(0,I.jsx)(A,{variant:r.status===`completed`?`success`:r.status===`failed`?`destructive`:r.status===`skipped`?`warning`:r.status===`cancelled`?`secondary`:`muted`,children:r.status}),(0,I.jsxs)(`div`,{className:`text-right text-[var(--app-text-subtle)]`,children:[a?.completedAt&&(0,I.jsxs)(`div`,{children:[Math.max(0,Math.round((a.completedAt-a.createdAt)/1e3)),`s`]}),a?.id&&(0,I.jsx)(`div`,{className:`font-mono`,children:a.id.slice(0,8)})]})]},`${t.id}-${n}`)})})]},t.id)})})]})})]},e.id))})]})}),(0,I.jsx)(ae,{open:L!==null,onOpenChange:e=>{e||R(null)},children:(0,I.jsxs)(te,{children:[(0,I.jsxs)(ie,{children:[(0,I.jsx)(y,{children:`Run Template`}),(0,I.jsxs)(_,{children:[`Run “`,pt?.name,`” now? This will execute the template immediately.`]})]}),(0,I.jsxs)(ne,{children:[(0,I.jsx)(re,{children:`Cancel`}),(0,I.jsx)(x,{onClick:()=>{L&&st(L),R(null)},children:`Run Now`})]})]})}),(0,I.jsx)(ae,{open:z!==null,onOpenChange:e=>{e||(we(null),V(null),H(`template_only`))},children:(0,I.jsxs)(te,{children:[(0,I.jsxs)(ie,{children:[(0,I.jsx)(y,{children:`Delete Template`}),(0,I.jsx)(_,{children:B===null?(0,I.jsx)(I.Fragment,{children:`Loading…`}):B.taskCount===0&&B.executionCount===0?(0,I.jsxs)(I.Fragment,{children:[`Delete “`,mt?.name,`”? This action cannot be undone.`]}):B.taskCount===0?(0,I.jsxs)(I.Fragment,{children:[`“`,mt?.name,`” has `,B.executionCount,` execution`,B.executionCount===1?``:`s`,` which will be removed. Delete?`]}):(0,I.jsxs)(I.Fragment,{children:[`“`,mt?.name,`” has`,` `,B.executionCount>0&&(0,I.jsxs)(I.Fragment,{children:[B.executionCount,` execution`,B.executionCount===1?``:`s`]}),B.executionCount>0&&B.taskCount>0&&` and `,B.taskCount,` task`,B.taskCount===1?``:`s`,`. Choose what to delete:`]})})]}),B!==null&&B.taskCount>0&&(0,I.jsxs)(`div`,{className:`space-y-2 px-1`,children:[(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2`,children:[(0,I.jsx)(`input`,{type:`radio`,name:`deleteMode`,value:`template_only`,checked:Te===`template_only`,onChange:()=>H(`template_only`),className:`mt-1`}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`text-sm font-medium`,children:`Template only`}),(0,I.jsx)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:`Removes the automation. Tasks remain under the Tasks tab as history.`})]})]}),(0,I.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2`,children:[(0,I.jsx)(`input`,{type:`radio`,name:`deleteMode`,value:`with_tasks`,checked:Te===`with_tasks`,onChange:()=>H(`with_tasks`),className:`mt-1`}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`text-sm font-medium`,children:`Template and its tasks`}),(0,I.jsxs)(`div`,{className:`text-xs text-[var(--app-text-subtle)]`,children:[`Also deletes `,B.taskCount,` task`,B.taskCount===1?``:`s`,` and their score history. Cannot be undone.`]})]})]})]}),(0,I.jsxs)(ne,{children:[(0,I.jsx)(re,{disabled:Ee,children:`Cancel`}),(0,I.jsx)(x,{className:`bg-[var(--app-danger)] hover:bg-[var(--app-danger)]`,disabled:Ee||B===null,onClick:()=>{z&&lt(z,B&&B.taskCount>0?Te:`template_only`),we(null),V(null),H(`template_only`)},children:`Delete`})]})]})})]})}function it(){let{tasks:e,templates:t,goals:n}=k(ce(e=>({tasks:e.tasks,templates:e.templates,goals:e.goals}))),r=k(e=>e.fetchTasks),i=k(e=>e.fetchTemplates),a=k(e=>e.fetchGoals);return(0,F.useEffect)(()=>{r(),i(),a()},[r,i,a]),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(M,{eyebrow:`Operations`,title:`Work`,description:`Tasks, automations, and goals in one place.`,metrics:[{label:`Running`,value:e.filter(e=>e.status===`running`).length},{label:`Automations`,value:t.length},{label:`Goals`,value:n.length}],compact:!0}),(0,I.jsxs)(Qe,{defaultValue:`tasks`,children:[(0,I.jsxs)($e,{children:[(0,I.jsx)(Z,{value:`tasks`,children:`Tasks`}),(0,I.jsx)(Z,{value:`automations`,children:`Automations`}),(0,I.jsx)(Z,{value:`goals`,children:`Goals`})]}),(0,I.jsx)(Q,{value:`tasks`,children:(0,I.jsx)(tt,{})}),(0,I.jsx)(Q,{value:`automations`,children:(0,I.jsx)(rt,{})}),(0,I.jsx)(Q,{value:`goals`,children:(0,I.jsx)(xe,{})})]})]})}export{it as Work};
@@ -1 +0,0 @@
1
- import{n as e}from"./rolldown-runtime-Dw2cE7zH.js";var t=e({AUTH_STORAGE_KEY:()=>r,ApiError:()=>n,api:()=>c,clearStoredApiKey:()=>o,fetchDeliveryLog:()=>l,getStoredApiKey:()=>i,redirectToLogin:()=>s,rotateApiKey:()=>d,setStoredApiKey:()=>a,verifyApiKey:()=>u}),n=class extends Error{status;code;constructor(e,t,n){super(n),this.name=`ApiError`,this.status=e,this.code=t}},r=`adam_api_key`;function i(){return typeof localStorage<`u`?localStorage.getItem(r):null}function a(e){localStorage.setItem(r,e)}function o(){localStorage.removeItem(r)}function s(){if(typeof window>`u`||window.location.pathname===`/ui/login`)return;let e=encodeURIComponent(window.location.pathname+window.location.search);window.location.href=`/ui/login?returnTo=${e}`}async function c(e,t){let r=i(),a={...t?.headers,...r?{"x-api-key":r}:{}};t?.body&&(a[`Content-Type`]??=`application/json`);let c=await fetch(e,{...t,headers:a});if(!c.ok){let e=`UNKNOWN_ERROR`,t=c.statusText;try{let n=await c.json();e=n.code??e,t=n.message??t}catch{}throw c.status===401&&(o(),s()),new n(c.status,e,t)}if(c.status!==204)return c.json()}async function l(e,t=50){return(await c(`/tasks/${e}/delivery-log?limit=${t}`)).logs}async function u(e){return(await fetch(`/auth/verify`,{headers:{"x-api-key":e}})).ok}async function d(){return(await c(`/auth/rotate`,{method:`POST`})).apiKey}export{i as a,a as c,l as i,u as l,t as n,s as o,o as r,d as s,c as t};