@harbinger-ai/harbinger 0.1.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 (317) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +406 -0
  3. package/agents/README.md +76 -0
  4. package/agents/_template/CONFIG.yaml +7 -0
  5. package/agents/_template/HEARTBEAT.md +59 -0
  6. package/agents/_template/IDENTITY.md +4 -0
  7. package/agents/_template/SKILLS.md +1 -0
  8. package/agents/_template/SOUL.md +25 -0
  9. package/agents/_template/TOOLS.md +3 -0
  10. package/agents/binary-reverser/CONFIG.yaml +21 -0
  11. package/agents/binary-reverser/HEARTBEAT.md +65 -0
  12. package/agents/binary-reverser/IDENTITY.md +1 -0
  13. package/agents/binary-reverser/SKILLS.md +1 -0
  14. package/agents/binary-reverser/SOUL.md +23 -0
  15. package/agents/binary-reverser/TOOLS.md +99 -0
  16. package/agents/browser-agent/CONFIG.yaml +20 -0
  17. package/agents/browser-agent/HEARTBEAT.md +79 -0
  18. package/agents/browser-agent/IDENTITY.md +5 -0
  19. package/agents/browser-agent/SKILLS.md +86 -0
  20. package/agents/browser-agent/SOUL.md +23 -0
  21. package/agents/browser-agent/TOOLS.md +186 -0
  22. package/agents/cloud-infiltrator/CONFIG.yaml +22 -0
  23. package/agents/cloud-infiltrator/HEARTBEAT.md +78 -0
  24. package/agents/cloud-infiltrator/IDENTITY.md +1 -0
  25. package/agents/cloud-infiltrator/SKILLS.md +1 -0
  26. package/agents/cloud-infiltrator/SOUL.md +23 -0
  27. package/agents/cloud-infiltrator/TOOLS.md +68 -0
  28. package/agents/coding-assistant/CONFIG.yaml +22 -0
  29. package/agents/coding-assistant/HEARTBEAT.md +57 -0
  30. package/agents/coding-assistant/IDENTITY.md +5 -0
  31. package/agents/coding-assistant/SKILLS.md +69 -0
  32. package/agents/coding-assistant/SOUL.md +60 -0
  33. package/agents/coding-assistant/TOOLS.md +168 -0
  34. package/agents/learning-agent/CONFIG.yaml +21 -0
  35. package/agents/learning-agent/HEARTBEAT.md +63 -0
  36. package/agents/learning-agent/IDENTITY.md +5 -0
  37. package/agents/learning-agent/SKILLS.md +86 -0
  38. package/agents/learning-agent/SOUL.md +77 -0
  39. package/agents/learning-agent/TOOLS.md +145 -0
  40. package/agents/maintainer/CONFIG.yaml +31 -0
  41. package/agents/maintainer/HEARTBEAT.md +28 -0
  42. package/agents/maintainer/IDENTITY.md +33 -0
  43. package/agents/maintainer/SKILLS.md +24 -0
  44. package/agents/maintainer/SOUL.md +61 -0
  45. package/agents/maintainer/TOOLS.md +29 -0
  46. package/agents/maintainer/lib/engine.js +279 -0
  47. package/agents/maintainer/lib/safe-fixer.js +183 -0
  48. package/agents/morning-brief/CONFIG.yaml +22 -0
  49. package/agents/morning-brief/HEARTBEAT.md +60 -0
  50. package/agents/morning-brief/IDENTITY.md +5 -0
  51. package/agents/morning-brief/SKILLS.md +56 -0
  52. package/agents/morning-brief/SOUL.md +64 -0
  53. package/agents/morning-brief/TOOLS.md +112 -0
  54. package/agents/osint-detective/CONFIG.yaml +24 -0
  55. package/agents/osint-detective/HEARTBEAT.md +66 -0
  56. package/agents/osint-detective/IDENTITY.md +1 -0
  57. package/agents/osint-detective/SKILLS.md +1 -0
  58. package/agents/osint-detective/SOUL.md +23 -0
  59. package/agents/osint-detective/TOOLS.md +81 -0
  60. package/agents/recon-scout/CONFIG.yaml +22 -0
  61. package/agents/recon-scout/HEARTBEAT.md +79 -0
  62. package/agents/recon-scout/IDENTITY.md +1 -0
  63. package/agents/recon-scout/SKILLS.md +1 -0
  64. package/agents/recon-scout/SOUL.md +23 -0
  65. package/agents/recon-scout/TOOLS.md +93 -0
  66. package/agents/report-writer/CONFIG.yaml +21 -0
  67. package/agents/report-writer/HEARTBEAT.md +63 -0
  68. package/agents/report-writer/IDENTITY.md +1 -0
  69. package/agents/report-writer/SKILLS.md +1 -0
  70. package/agents/report-writer/SOUL.md +23 -0
  71. package/agents/report-writer/TOOLS.md +69 -0
  72. package/agents/shared/README.md +13 -0
  73. package/agents/web-hacker/CONFIG.yaml +24 -0
  74. package/agents/web-hacker/HEARTBEAT.md +78 -0
  75. package/agents/web-hacker/IDENTITY.md +1 -0
  76. package/agents/web-hacker/SKILLS.md +1 -0
  77. package/agents/web-hacker/SOUL.md +23 -0
  78. package/agents/web-hacker/TOOLS.md +86 -0
  79. package/api/CLAUDE.md +19 -0
  80. package/api/index.js +274 -0
  81. package/bin/cli.js +620 -0
  82. package/bin/local.sh +31 -0
  83. package/bin/postinstall.js +63 -0
  84. package/config/index.js +24 -0
  85. package/config/instrumentation.js +93 -0
  86. package/drizzle/0000_initial.sql +52 -0
  87. package/drizzle/0001_bounty_and_registry.sql +82 -0
  88. package/drizzle/0002_sync_columns.sql +7 -0
  89. package/drizzle/0003_graceful_bloodscream.sql +86 -0
  90. package/drizzle/meta/0000_snapshot.json +321 -0
  91. package/drizzle/meta/0003_snapshot.json +878 -0
  92. package/drizzle/meta/_journal.json +34 -0
  93. package/drizzle/relations.ts +3 -0
  94. package/drizzle/schema.ts +145 -0
  95. package/lib/actions.js +47 -0
  96. package/lib/agents.js +166 -0
  97. package/lib/ai/agent.js +96 -0
  98. package/lib/ai/autonomous-engine.js +261 -0
  99. package/lib/ai/index.js +359 -0
  100. package/lib/ai/model-router.js +254 -0
  101. package/lib/ai/model.js +73 -0
  102. package/lib/ai/tools.js +84 -0
  103. package/lib/auth/actions.js +28 -0
  104. package/lib/auth/config.js +27 -0
  105. package/lib/auth/edge-config.js +27 -0
  106. package/lib/auth/index.js +27 -0
  107. package/lib/auth/middleware.js +53 -0
  108. package/lib/bounty/actions.js +119 -0
  109. package/lib/bounty/findings.js +64 -0
  110. package/lib/bounty/programs.js +34 -0
  111. package/lib/bounty/sync-targets.js +267 -0
  112. package/lib/bounty/targets.js +33 -0
  113. package/lib/channels/base.js +56 -0
  114. package/lib/channels/index.js +15 -0
  115. package/lib/channels/telegram.js +148 -0
  116. package/lib/chat/actions.js +288 -0
  117. package/lib/chat/api.js +135 -0
  118. package/lib/chat/components/app-sidebar.js +237 -0
  119. package/lib/chat/components/app-sidebar.jsx +289 -0
  120. package/lib/chat/components/chat-header.js +27 -0
  121. package/lib/chat/components/chat-header.jsx +37 -0
  122. package/lib/chat/components/chat-input.js +230 -0
  123. package/lib/chat/components/chat-input.jsx +228 -0
  124. package/lib/chat/components/chat-nav-context.js +11 -0
  125. package/lib/chat/components/chat-nav-context.jsx +11 -0
  126. package/lib/chat/components/chat-page.js +81 -0
  127. package/lib/chat/components/chat-page.jsx +100 -0
  128. package/lib/chat/components/chat.js +150 -0
  129. package/lib/chat/components/chat.jsx +182 -0
  130. package/lib/chat/components/chats-page.js +302 -0
  131. package/lib/chat/components/chats-page.jsx +330 -0
  132. package/lib/chat/components/crons-page.js +172 -0
  133. package/lib/chat/components/crons-page.jsx +244 -0
  134. package/lib/chat/components/enhanced-tool-call.js +103 -0
  135. package/lib/chat/components/enhanced-tool-call.jsx +139 -0
  136. package/lib/chat/components/findings-page.js +175 -0
  137. package/lib/chat/components/findings-page.jsx +214 -0
  138. package/lib/chat/components/greeting.js +22 -0
  139. package/lib/chat/components/greeting.jsx +26 -0
  140. package/lib/chat/components/icons.js +777 -0
  141. package/lib/chat/components/icons.jsx +741 -0
  142. package/lib/chat/components/index.js +26 -0
  143. package/lib/chat/components/mcp-page.js +260 -0
  144. package/lib/chat/components/mcp-page.jsx +355 -0
  145. package/lib/chat/components/message.js +289 -0
  146. package/lib/chat/components/message.jsx +315 -0
  147. package/lib/chat/components/messages.js +66 -0
  148. package/lib/chat/components/messages.jsx +77 -0
  149. package/lib/chat/components/notifications-page.js +56 -0
  150. package/lib/chat/components/notifications-page.jsx +87 -0
  151. package/lib/chat/components/page-layout.js +21 -0
  152. package/lib/chat/components/page-layout.jsx +28 -0
  153. package/lib/chat/components/registry-page.js +222 -0
  154. package/lib/chat/components/registry-page.jsx +255 -0
  155. package/lib/chat/components/settings-layout.js +40 -0
  156. package/lib/chat/components/settings-layout.jsx +54 -0
  157. package/lib/chat/components/settings-secrets-page.js +216 -0
  158. package/lib/chat/components/settings-secrets-page.jsx +264 -0
  159. package/lib/chat/components/sidebar-history-item.js +132 -0
  160. package/lib/chat/components/sidebar-history-item.jsx +113 -0
  161. package/lib/chat/components/sidebar-history.js +115 -0
  162. package/lib/chat/components/sidebar-history.jsx +157 -0
  163. package/lib/chat/components/sidebar-user-nav.js +63 -0
  164. package/lib/chat/components/sidebar-user-nav.jsx +73 -0
  165. package/lib/chat/components/status-bar.js +39 -0
  166. package/lib/chat/components/status-bar.jsx +51 -0
  167. package/lib/chat/components/swarm-page.js +157 -0
  168. package/lib/chat/components/swarm-page.jsx +210 -0
  169. package/lib/chat/components/targets-page.js +376 -0
  170. package/lib/chat/components/targets-page.jsx +389 -0
  171. package/lib/chat/components/tool-call.js +86 -0
  172. package/lib/chat/components/tool-call.jsx +104 -0
  173. package/lib/chat/components/tool-panel.js +107 -0
  174. package/lib/chat/components/tool-panel.jsx +145 -0
  175. package/lib/chat/components/triggers-page.js +153 -0
  176. package/lib/chat/components/triggers-page.jsx +221 -0
  177. package/lib/chat/components/ui/confirm-dialog.js +53 -0
  178. package/lib/chat/components/ui/confirm-dialog.jsx +57 -0
  179. package/lib/chat/components/ui/dropdown-menu.js +98 -0
  180. package/lib/chat/components/ui/dropdown-menu.jsx +116 -0
  181. package/lib/chat/components/ui/rename-dialog.js +74 -0
  182. package/lib/chat/components/ui/rename-dialog.jsx +72 -0
  183. package/lib/chat/components/ui/scroll-area.js +13 -0
  184. package/lib/chat/components/ui/scroll-area.jsx +17 -0
  185. package/lib/chat/components/ui/separator.js +21 -0
  186. package/lib/chat/components/ui/separator.jsx +18 -0
  187. package/lib/chat/components/ui/sheet.js +75 -0
  188. package/lib/chat/components/ui/sheet.jsx +95 -0
  189. package/lib/chat/components/ui/sidebar.js +227 -0
  190. package/lib/chat/components/ui/sidebar.jsx +245 -0
  191. package/lib/chat/components/ui/tooltip.js +56 -0
  192. package/lib/chat/components/ui/tooltip.jsx +66 -0
  193. package/lib/chat/components/upgrade-dialog.js +151 -0
  194. package/lib/chat/components/upgrade-dialog.jsx +170 -0
  195. package/lib/chat/utils.js +11 -0
  196. package/lib/cron.js +246 -0
  197. package/lib/db/api-keys.js +163 -0
  198. package/lib/db/chats.js +145 -0
  199. package/lib/db/index.js +52 -0
  200. package/lib/db/notifications.js +99 -0
  201. package/lib/db/schema.js +145 -0
  202. package/lib/db/update-check.js +96 -0
  203. package/lib/db/users.js +89 -0
  204. package/lib/mcp/actions.js +104 -0
  205. package/lib/mcp/client.js +79 -0
  206. package/lib/mcp/handler.js +57 -0
  207. package/lib/mcp/server.js +165 -0
  208. package/lib/paths.js +46 -0
  209. package/lib/registry/actions.js +164 -0
  210. package/lib/registry/catalog.js +137 -0
  211. package/lib/registry/tools.js +71 -0
  212. package/lib/tools/create-job.js +99 -0
  213. package/lib/tools/github.js +217 -0
  214. package/lib/tools/openai.js +35 -0
  215. package/lib/tools/telegram.js +292 -0
  216. package/lib/triggers.js +118 -0
  217. package/lib/utils/render-md.js +102 -0
  218. package/package.json +103 -0
  219. package/setup/lib/auth.mjs +81 -0
  220. package/setup/lib/env.mjs +21 -0
  221. package/setup/lib/fs-utils.mjs +20 -0
  222. package/setup/lib/github.mjs +149 -0
  223. package/setup/lib/prerequisites.mjs +155 -0
  224. package/setup/lib/prompts.mjs +267 -0
  225. package/setup/lib/providers.mjs +48 -0
  226. package/setup/lib/sync.mjs +125 -0
  227. package/setup/lib/targets.mjs +45 -0
  228. package/setup/lib/telegram-verify.mjs +63 -0
  229. package/setup/lib/telegram.mjs +76 -0
  230. package/setup/setup-telegram.mjs +264 -0
  231. package/setup/setup.mjs +842 -0
  232. package/templates/.dockerignore +5 -0
  233. package/templates/.env.example +63 -0
  234. package/templates/.github/workflows/auto-merge.yml +117 -0
  235. package/templates/.github/workflows/build-image.yml +36 -0
  236. package/templates/.github/workflows/notify-job-failed.yml +64 -0
  237. package/templates/.github/workflows/notify-pr-complete.yml +119 -0
  238. package/templates/.github/workflows/rebuild-event-handler.yml +121 -0
  239. package/templates/.github/workflows/run-job.yml +89 -0
  240. package/templates/.github/workflows/upgrade-event-handler.yml +62 -0
  241. package/templates/.gitignore.template +45 -0
  242. package/templates/.pi/extensions/env-sanitizer/index.ts +48 -0
  243. package/templates/.pi/extensions/env-sanitizer/package.json +5 -0
  244. package/templates/CLAUDE.md +29 -0
  245. package/templates/CLAUDE.md.template +307 -0
  246. package/templates/app/api/[...thepopebot]/route.js +1 -0
  247. package/templates/app/api/auth/[...nextauth]/route.js +1 -0
  248. package/templates/app/chat/[chatId]/page.js +8 -0
  249. package/templates/app/chats/page.js +7 -0
  250. package/templates/app/components/ascii-logo.jsx +10 -0
  251. package/templates/app/components/login-form.jsx +92 -0
  252. package/templates/app/components/setup-form.jsx +82 -0
  253. package/templates/app/components/theme-provider.jsx +11 -0
  254. package/templates/app/components/theme-toggle.jsx +38 -0
  255. package/templates/app/components/ui/button.jsx +21 -0
  256. package/templates/app/components/ui/card.jsx +23 -0
  257. package/templates/app/components/ui/input.jsx +10 -0
  258. package/templates/app/components/ui/label.jsx +10 -0
  259. package/templates/app/crons/page.js +5 -0
  260. package/templates/app/findings/page.js +7 -0
  261. package/templates/app/globals.css +90 -0
  262. package/templates/app/layout.js +19 -0
  263. package/templates/app/login/page.js +15 -0
  264. package/templates/app/notifications/page.js +7 -0
  265. package/templates/app/page.js +7 -0
  266. package/templates/app/settings/crons/page.js +5 -0
  267. package/templates/app/settings/layout.js +7 -0
  268. package/templates/app/settings/mcp/page.js +5 -0
  269. package/templates/app/settings/page.js +5 -0
  270. package/templates/app/settings/secrets/page.js +5 -0
  271. package/templates/app/settings/triggers/page.js +5 -0
  272. package/templates/app/stream/chat/route.js +1 -0
  273. package/templates/app/swarm/page.js +7 -0
  274. package/templates/app/targets/page.js +7 -0
  275. package/templates/app/toolbox/page.js +7 -0
  276. package/templates/app/triggers/page.js +5 -0
  277. package/templates/config/AGENT.md +34 -0
  278. package/templates/config/CRONS.json +56 -0
  279. package/templates/config/EVENT_HANDLER.md +224 -0
  280. package/templates/config/HEARTBEAT.md +3 -0
  281. package/templates/config/JOB_SUMMARY.md +130 -0
  282. package/templates/config/MCP_SERVERS.json +1 -0
  283. package/templates/config/SKILL_BUILDING_GUIDE.md +90 -0
  284. package/templates/config/SOUL.md +17 -0
  285. package/templates/config/TRIGGERS.json +58 -0
  286. package/templates/docker/event-handler/Dockerfile +20 -0
  287. package/templates/docker/event-handler/ecosystem.config.cjs +8 -0
  288. package/templates/docker/job-claude-code/Dockerfile +34 -0
  289. package/templates/docker/job-claude-code/entrypoint.sh +139 -0
  290. package/templates/docker/job-pi-coding-agent/Dockerfile +44 -0
  291. package/templates/docker/job-pi-coding-agent/entrypoint.sh +163 -0
  292. package/templates/docker-compose.yml +63 -0
  293. package/templates/instrumentation.js +6 -0
  294. package/templates/middleware.js +1 -0
  295. package/templates/next.config.mjs +3 -0
  296. package/templates/postcss.config.mjs +5 -0
  297. package/templates/skills/LICENSE +21 -0
  298. package/templates/skills/README.md +119 -0
  299. package/templates/skills/brave-search/SKILL.md +79 -0
  300. package/templates/skills/brave-search/content.js +86 -0
  301. package/templates/skills/brave-search/package-lock.json +621 -0
  302. package/templates/skills/brave-search/package.json +14 -0
  303. package/templates/skills/brave-search/search.js +199 -0
  304. package/templates/skills/browser-tools/SKILL.md +196 -0
  305. package/templates/skills/browser-tools/browser-content.js +103 -0
  306. package/templates/skills/browser-tools/browser-cookies.js +35 -0
  307. package/templates/skills/browser-tools/browser-eval.js +53 -0
  308. package/templates/skills/browser-tools/browser-hn-scraper.js +108 -0
  309. package/templates/skills/browser-tools/browser-nav.js +44 -0
  310. package/templates/skills/browser-tools/browser-pick.js +162 -0
  311. package/templates/skills/browser-tools/browser-screenshot.js +34 -0
  312. package/templates/skills/browser-tools/browser-start.js +87 -0
  313. package/templates/skills/browser-tools/package-lock.json +2556 -0
  314. package/templates/skills/browser-tools/package.json +19 -0
  315. package/templates/skills/llm-secrets/SKILL.md +34 -0
  316. package/templates/skills/llm-secrets/llm-secrets.js +33 -0
  317. package/templates/skills/modify-self/SKILL.md +12 -0
@@ -0,0 +1,330 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useRef } from 'react';
4
+ import { PageLayout } from './page-layout.js';
5
+ import { MessageIcon, TrashIcon, SearchIcon, PlusIcon, MoreHorizontalIcon, StarIcon, StarFilledIcon, PencilIcon } from './icons.js';
6
+ import { getChats, deleteChat, renameChat, starChat } from '../actions.js';
7
+ import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from './ui/dropdown-menu.js';
8
+ import { ConfirmDialog } from './ui/confirm-dialog.js';
9
+ import { cn } from '../utils.js';
10
+
11
+ function groupChatsByDate(chats) {
12
+ const now = new Date();
13
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
14
+ const yesterday = new Date(today.getTime() - 86400000);
15
+ const last7Days = new Date(today.getTime() - 7 * 86400000);
16
+ const last30Days = new Date(today.getTime() - 30 * 86400000);
17
+
18
+ const groups = {
19
+ Starred: [],
20
+ Today: [],
21
+ Yesterday: [],
22
+ 'Last 7 Days': [],
23
+ 'Last 30 Days': [],
24
+ Older: [],
25
+ };
26
+
27
+ for (const chat of chats) {
28
+ if (chat.starred) {
29
+ groups.Starred.push(chat);
30
+ continue;
31
+ }
32
+ const date = new Date(chat.updatedAt);
33
+ if (date >= today) {
34
+ groups.Today.push(chat);
35
+ } else if (date >= yesterday) {
36
+ groups.Yesterday.push(chat);
37
+ } else if (date >= last7Days) {
38
+ groups['Last 7 Days'].push(chat);
39
+ } else if (date >= last30Days) {
40
+ groups['Last 30 Days'].push(chat);
41
+ } else {
42
+ groups.Older.push(chat);
43
+ }
44
+ }
45
+
46
+ return groups;
47
+ }
48
+
49
+ function timeAgo(date) {
50
+ const seconds = Math.floor((Date.now() - new Date(date).getTime()) / 1000);
51
+ if (seconds < 60) return 'just now';
52
+ const minutes = Math.floor(seconds / 60);
53
+ if (minutes < 60) return `${minutes}m ago`;
54
+ const hours = Math.floor(minutes / 60);
55
+ if (hours < 24) return `${hours}h ago`;
56
+ const days = Math.floor(hours / 24);
57
+ if (days < 30) return `${days}d ago`;
58
+ const months = Math.floor(days / 30);
59
+ return `${months}mo ago`;
60
+ }
61
+
62
+ export function ChatsPage({ session }) {
63
+ const [chats, setChats] = useState([]);
64
+ const [loading, setLoading] = useState(true);
65
+ const [query, setQuery] = useState('');
66
+
67
+ const navigateToChat = (id) => {
68
+ window.location.href = id ? `/chat/${id}` : '/';
69
+ };
70
+
71
+ const loadChats = async () => {
72
+ try {
73
+ const result = await getChats();
74
+ setChats(result);
75
+ } catch (err) {
76
+ console.error('Failed to load chats:', err);
77
+ } finally {
78
+ setLoading(false);
79
+ }
80
+ };
81
+
82
+ useEffect(() => {
83
+ loadChats();
84
+ }, []);
85
+
86
+ useEffect(() => {
87
+ const handler = () => loadChats();
88
+ window.addEventListener('chatsupdated', handler);
89
+ return () => window.removeEventListener('chatsupdated', handler);
90
+ }, []);
91
+
92
+ const handleDelete = async (chatId) => {
93
+ setChats((prev) => prev.filter((c) => c.id !== chatId));
94
+ const { success } = await deleteChat(chatId);
95
+ if (!success) loadChats();
96
+ };
97
+
98
+ const handleStar = async (chatId) => {
99
+ setChats((prev) =>
100
+ prev.map((c) => (c.id === chatId ? { ...c, starred: c.starred ? 0 : 1 } : c))
101
+ );
102
+ const { success } = await starChat(chatId);
103
+ if (!success) loadChats();
104
+ };
105
+
106
+ const handleRename = async (chatId, title) => {
107
+ setChats((prev) =>
108
+ prev.map((c) => (c.id === chatId ? { ...c, title } : c))
109
+ );
110
+ const { success } = await renameChat(chatId, title);
111
+ if (!success) loadChats();
112
+ };
113
+
114
+ const filtered = query
115
+ ? chats.filter((c) => c.title?.toLowerCase().includes(query.toLowerCase()))
116
+ : chats;
117
+
118
+ const grouped = groupChatsByDate(filtered);
119
+
120
+ return (
121
+ <PageLayout session={session}>
122
+ {/* Header */}
123
+ <div className="flex items-center justify-between mb-6">
124
+ <h1 className="text-2xl font-semibold">Chats</h1>
125
+ <button
126
+ onClick={() => navigateToChat(null)}
127
+ className="inline-flex items-center gap-2 rounded-md px-3 py-2 text-sm font-medium bg-foreground text-background hover:bg-foreground/90"
128
+ >
129
+ <PlusIcon size={14} />
130
+ New chat
131
+ </button>
132
+ </div>
133
+
134
+ {/* Search */}
135
+ <div className="relative mb-4">
136
+ <input
137
+ type="text"
138
+ placeholder="Search your chats..."
139
+ value={query}
140
+ onChange={(e) => setQuery(e.target.value)}
141
+ className="w-full rounded-md border border-input bg-background px-9 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
142
+ />
143
+ <div className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none">
144
+ <SearchIcon size={16} />
145
+ </div>
146
+ </div>
147
+
148
+ {/* Count */}
149
+ <p className="text-sm text-muted-foreground mb-4">
150
+ {filtered.length} {filtered.length === 1 ? 'chat' : 'chats'}
151
+ </p>
152
+
153
+ {/* Chat list */}
154
+ {loading ? (
155
+ <div className="flex flex-col gap-3">
156
+ {[...Array(5)].map((_, i) => (
157
+ <div key={i} className="h-14 animate-pulse rounded-md bg-border/50" />
158
+ ))}
159
+ </div>
160
+ ) : filtered.length === 0 ? (
161
+ <p className="text-sm text-muted-foreground py-8 text-center">
162
+ {query ? 'No chats match your search.' : 'No chats yet. Start a conversation!'}
163
+ </p>
164
+ ) : (
165
+ <div className="flex flex-col">
166
+ {Object.entries(grouped).map(([label, groupChats]) =>
167
+ groupChats.length > 0 ? (
168
+ <div key={label} className="mb-4">
169
+ <h2 className="text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2">
170
+ {label}
171
+ </h2>
172
+ <div className="flex flex-col divide-y divide-border">
173
+ {groupChats.map((chat) => (
174
+ <ChatRow
175
+ key={chat.id}
176
+ chat={chat}
177
+ onNavigate={navigateToChat}
178
+ onDelete={handleDelete}
179
+ onStar={handleStar}
180
+ onRename={handleRename}
181
+ />
182
+ ))}
183
+ </div>
184
+ </div>
185
+ ) : null
186
+ )}
187
+ </div>
188
+ )}
189
+ </PageLayout>
190
+ );
191
+ }
192
+
193
+ function ChatRow({ chat, onNavigate, onDelete, onStar, onRename }) {
194
+ const [hovered, setHovered] = useState(false);
195
+ const [dropdownOpen, setDropdownOpen] = useState(false);
196
+ const [confirmDelete, setConfirmDelete] = useState(false);
197
+ const [editing, setEditing] = useState(false);
198
+ const [editTitle, setEditTitle] = useState(chat.title || '');
199
+ const inputRef = useRef(null);
200
+
201
+ const showMenu = hovered || dropdownOpen;
202
+
203
+ useEffect(() => {
204
+ if (editing && inputRef.current) {
205
+ inputRef.current.focus();
206
+ inputRef.current.select();
207
+ }
208
+ }, [editing]);
209
+
210
+ const startRename = () => {
211
+ setEditTitle(chat.title || '');
212
+ setEditing(true);
213
+ };
214
+
215
+ const saveRename = () => {
216
+ const trimmed = editTitle.trim();
217
+ if (trimmed && trimmed !== chat.title) {
218
+ onRename(chat.id, trimmed);
219
+ }
220
+ setEditing(false);
221
+ };
222
+
223
+ const cancelRename = () => {
224
+ setEditing(false);
225
+ setEditTitle(chat.title || '');
226
+ };
227
+
228
+ return (
229
+ <div
230
+ className="relative group flex items-center gap-3 px-3 py-3 cursor-pointer hover:bg-muted/50 rounded-md"
231
+ onMouseEnter={() => setHovered(true)}
232
+ onMouseLeave={() => setHovered(false)}
233
+ onClick={() => !editing && onNavigate(chat.id)}
234
+ >
235
+ <MessageIcon size={16} />
236
+ <div className="flex-1 min-w-0">
237
+ {editing ? (
238
+ <input
239
+ ref={inputRef}
240
+ type="text"
241
+ value={editTitle}
242
+ onChange={(e) => setEditTitle(e.target.value)}
243
+ onKeyDown={(e) => {
244
+ if (e.key === 'Enter') saveRename();
245
+ if (e.key === 'Escape') cancelRename();
246
+ }}
247
+ onBlur={saveRename}
248
+ onClick={(e) => e.stopPropagation()}
249
+ className="w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-2 focus:ring-ring"
250
+ />
251
+ ) : (
252
+ <span
253
+ className="text-sm truncate block"
254
+ onDoubleClick={(e) => {
255
+ e.stopPropagation();
256
+ startRename();
257
+ }}
258
+ >
259
+ {chat.title || 'New Chat'}
260
+ </span>
261
+ )}
262
+ <span className="text-xs text-muted-foreground">
263
+ Last message {timeAgo(chat.updatedAt)}
264
+ </span>
265
+ </div>
266
+ {!editing && (
267
+ <div className={cn(
268
+ 'shrink-0',
269
+ showMenu ? 'opacity-100' : 'opacity-0 pointer-events-none'
270
+ )}>
271
+ <DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
272
+ <DropdownMenuTrigger asChild>
273
+ <button
274
+ className={cn(
275
+ 'rounded-md p-1.5',
276
+ 'text-muted-foreground hover:text-foreground hover:bg-muted'
277
+ )}
278
+ aria-label="Chat options"
279
+ >
280
+ <MoreHorizontalIcon size={14} />
281
+ </button>
282
+ </DropdownMenuTrigger>
283
+ <DropdownMenuContent align="end" side="bottom">
284
+ <DropdownMenuItem
285
+ onClick={(e) => {
286
+ e.stopPropagation();
287
+ onStar(chat.id);
288
+ }}
289
+ >
290
+ {chat.starred ? <StarFilledIcon size={14} /> : <StarIcon size={14} />}
291
+ {chat.starred ? 'Unstar' : 'Star'}
292
+ </DropdownMenuItem>
293
+ <DropdownMenuItem
294
+ onClick={(e) => {
295
+ e.stopPropagation();
296
+ startRename();
297
+ }}
298
+ >
299
+ <PencilIcon size={14} />
300
+ Rename
301
+ </DropdownMenuItem>
302
+ <DropdownMenuSeparator />
303
+ <DropdownMenuItem
304
+ className="text-destructive hover:text-destructive"
305
+ onClick={(e) => {
306
+ e.stopPropagation();
307
+ setConfirmDelete(true);
308
+ }}
309
+ >
310
+ <TrashIcon size={14} />
311
+ Delete
312
+ </DropdownMenuItem>
313
+ </DropdownMenuContent>
314
+ </DropdownMenu>
315
+ </div>
316
+ )}
317
+ <ConfirmDialog
318
+ open={confirmDelete}
319
+ title="Delete chat?"
320
+ description="This will permanently delete this chat and all its messages."
321
+ confirmLabel="Delete"
322
+ onConfirm={() => {
323
+ setConfirmDelete(false);
324
+ onDelete(chat.id);
325
+ }}
326
+ onCancel={() => setConfirmDelete(false)}
327
+ />
328
+ </div>
329
+ );
330
+ }
@@ -0,0 +1,172 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useState, useEffect } from "react";
4
+ import { ClockIcon, SpinnerIcon, ChevronDownIcon } from "./icons.js";
5
+ import { getSwarmConfig } from "../actions.js";
6
+ function describeCron(schedule) {
7
+ const parts = schedule.trim().split(/\s+/);
8
+ if (parts.length !== 5) return schedule;
9
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
10
+ if (minute.startsWith("*/") && hour === "*" && dayOfMonth === "*" && month === "*" && dayOfWeek === "*") {
11
+ const n = parseInt(minute.slice(2), 10);
12
+ if (n === 1) return "Every minute";
13
+ return `Every ${n} minutes`;
14
+ }
15
+ if (hour.startsWith("*/") && dayOfMonth === "*" && month === "*" && dayOfWeek === "*") {
16
+ const n = parseInt(hour.slice(2), 10);
17
+ if (n === 1) return "Every hour";
18
+ return `Every ${n} hours`;
19
+ }
20
+ if (minute !== "*" && hour !== "*" && !hour.includes("/") && !minute.includes("/") && dayOfMonth === "*" && month === "*" && dayOfWeek === "*") {
21
+ const h = parseInt(hour, 10);
22
+ const m = parseInt(minute, 10);
23
+ const period = h >= 12 ? "PM" : "AM";
24
+ const displayH = h === 0 ? 12 : h > 12 ? h - 12 : h;
25
+ return `Daily at ${displayH}:${String(m).padStart(2, "0")} ${period}`;
26
+ }
27
+ if (minute !== "*" && hour !== "*" && dayOfMonth === "*" && month === "*" && dayOfWeek !== "*") {
28
+ const dayNames = { "0": "Sun", "1": "Mon", "2": "Tue", "3": "Wed", "4": "Thu", "5": "Fri", "6": "Sat" };
29
+ const days = dayOfWeek.split(",").map((d) => dayNames[d] || d).join(", ");
30
+ const h = parseInt(hour, 10);
31
+ const m = parseInt(minute, 10);
32
+ const period = h >= 12 ? "PM" : "AM";
33
+ const displayH = h === 0 ? 12 : h > 12 ? h - 12 : h;
34
+ return `${days} at ${displayH}:${String(m).padStart(2, "0")} ${period}`;
35
+ }
36
+ return schedule;
37
+ }
38
+ const typeBadgeStyles = {
39
+ agent: "bg-purple-500/10 text-purple-500",
40
+ command: "bg-blue-500/10 text-blue-500",
41
+ webhook: "bg-orange-500/10 text-orange-500"
42
+ };
43
+ const typeOrder = { agent: 0, command: 1, webhook: 2 };
44
+ function sortByType(items) {
45
+ return [...items].sort((a, b) => {
46
+ const ta = typeOrder[a.type || "agent"] ?? 99;
47
+ const tb = typeOrder[b.type || "agent"] ?? 99;
48
+ return ta - tb;
49
+ });
50
+ }
51
+ function GroupHeader({ label, count }) {
52
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 pt-2 pb-1", children: [
53
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wide", children: label }),
54
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
55
+ "(",
56
+ count,
57
+ ")"
58
+ ] })
59
+ ] });
60
+ }
61
+ function CronCard({ cron }) {
62
+ const [expanded, setExpanded] = useState(false);
63
+ const type = cron.type || "agent";
64
+ const disabled = cron.enabled === false;
65
+ return /* @__PURE__ */ jsxs(
66
+ "div",
67
+ {
68
+ className: `rounded-lg border bg-card transition-opacity ${disabled ? "opacity-60" : ""}`,
69
+ children: [
70
+ /* @__PURE__ */ jsxs(
71
+ "button",
72
+ {
73
+ onClick: () => setExpanded(!expanded),
74
+ className: "flex items-center gap-3 w-full text-left p-4 hover:bg-accent/50 rounded-lg",
75
+ children: [
76
+ /* @__PURE__ */ jsx("div", { className: "shrink-0 rounded-md bg-muted p-2", children: /* @__PURE__ */ jsx(ClockIcon, { size: 16 }) }),
77
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
78
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium truncate", children: cron.name }),
79
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground mt-0.5", children: [
80
+ /* @__PURE__ */ jsx("span", { className: "font-mono", children: cron.schedule }),
81
+ /* @__PURE__ */ jsx("span", { className: "mx-1.5 text-border", children: "|" }),
82
+ describeCron(cron.schedule)
83
+ ] })
84
+ ] }),
85
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 shrink-0", children: [
86
+ /* @__PURE__ */ jsx("span", { className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${typeBadgeStyles[type] || typeBadgeStyles.agent}`, children: type }),
87
+ /* @__PURE__ */ jsx(
88
+ "span",
89
+ {
90
+ className: `inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${disabled ? "bg-muted text-muted-foreground" : "bg-green-500/10 text-green-500"}`,
91
+ children: disabled ? "disabled" : "enabled"
92
+ }
93
+ ),
94
+ /* @__PURE__ */ jsx("span", { className: `transition-transform ${expanded ? "rotate-180" : ""}`, children: /* @__PURE__ */ jsx(ChevronDownIcon, { size: 14 }) })
95
+ ] })
96
+ ]
97
+ }
98
+ ),
99
+ expanded && /* @__PURE__ */ jsxs("div", { className: "border-t px-4 py-3", children: [
100
+ type === "agent" && cron.job && /* @__PURE__ */ jsxs("div", { children: [
101
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground mb-1.5", children: "Job prompt" }),
102
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48", children: cron.job }),
103
+ (cron.llm_provider || cron.llm_model) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mt-2", children: [
104
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "LLM:" }),
105
+ /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-full bg-purple-500/10 text-purple-500 px-2 py-0.5 text-[10px] font-medium", children: [cron.llm_provider, cron.llm_model].filter(Boolean).join(" / ") })
106
+ ] })
107
+ ] }),
108
+ type === "command" && cron.command && /* @__PURE__ */ jsxs("div", { children: [
109
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground mb-1.5", children: "Command" }),
110
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48", children: cron.command })
111
+ ] }),
112
+ type === "webhook" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
113
+ /* @__PURE__ */ jsxs("div", { children: [
114
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground mb-1.5", children: "URL" }),
115
+ /* @__PURE__ */ jsxs("pre", { className: "text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto", children: [
116
+ cron.method && cron.method !== "POST" ? `${cron.method} ` : "",
117
+ cron.url
118
+ ] })
119
+ ] }),
120
+ cron.vars && Object.keys(cron.vars).length > 0 && /* @__PURE__ */ jsxs("div", { children: [
121
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground mb-1.5", children: "Variables" }),
122
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48", children: JSON.stringify(cron.vars, null, 2) })
123
+ ] })
124
+ ] })
125
+ ] })
126
+ ]
127
+ }
128
+ );
129
+ }
130
+ function CronsPage() {
131
+ const [crons, setCrons] = useState([]);
132
+ const [loading, setLoading] = useState(true);
133
+ useEffect(() => {
134
+ getSwarmConfig().then((data) => {
135
+ if (data?.crons) setCrons(data.crons);
136
+ }).catch(() => {
137
+ }).finally(() => setLoading(false));
138
+ }, []);
139
+ const enabled = sortByType(crons.filter((c) => c.enabled !== false));
140
+ const disabled = sortByType(crons.filter((c) => c.enabled === false));
141
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
142
+ !loading && /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground mb-4", children: [
143
+ crons.length,
144
+ " job",
145
+ crons.length !== 1 ? "s" : "",
146
+ " configured, ",
147
+ enabled.length,
148
+ " enabled"
149
+ ] }),
150
+ loading ? /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: [...Array(3)].map((_, i) => /* @__PURE__ */ jsx("div", { className: "h-20 animate-pulse rounded-lg bg-border/50" }, i)) }) : crons.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-16 text-center", children: [
151
+ /* @__PURE__ */ jsx("div", { className: "rounded-full bg-muted p-4 mb-4", children: /* @__PURE__ */ jsx(ClockIcon, { size: 24 }) }),
152
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium mb-1", children: "No cron jobs configured" }),
153
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground max-w-sm", children: [
154
+ "Add scheduled jobs by editing ",
155
+ /* @__PURE__ */ jsx("span", { className: "font-mono", children: "config/CRONS.json" }),
156
+ " in your project."
157
+ ] })
158
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
159
+ enabled.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
160
+ /* @__PURE__ */ jsx(GroupHeader, { label: "Enabled", count: enabled.length }),
161
+ enabled.map((cron, i) => /* @__PURE__ */ jsx(CronCard, { cron }, `enabled-${i}`))
162
+ ] }),
163
+ disabled.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
164
+ /* @__PURE__ */ jsx(GroupHeader, { label: "Disabled", count: disabled.length }),
165
+ disabled.map((cron, i) => /* @__PURE__ */ jsx(CronCard, { cron }, `disabled-${i}`))
166
+ ] })
167
+ ] })
168
+ ] });
169
+ }
170
+ export {
171
+ CronsPage
172
+ };