thepopebot 1.1.2 → 1.2.3

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 (143) hide show
  1. package/README.md +1 -1
  2. package/api/index.js +72 -165
  3. package/bin/cli.js +36 -6
  4. package/bin/local.sh +31 -0
  5. package/bin/postinstall.js +6 -2
  6. package/config/index.js +2 -11
  7. package/config/instrumentation.js +17 -5
  8. package/lib/actions.js +7 -6
  9. package/lib/ai/agent.js +36 -0
  10. package/lib/ai/index.js +274 -0
  11. package/lib/ai/model.js +67 -0
  12. package/lib/ai/tools.js +49 -0
  13. package/lib/auth/actions.js +28 -0
  14. package/lib/auth/config.js +45 -0
  15. package/lib/auth/index.js +27 -0
  16. package/lib/auth/middleware.js +30 -0
  17. package/lib/channels/base.js +56 -0
  18. package/lib/channels/index.js +15 -0
  19. package/lib/channels/telegram.js +146 -0
  20. package/lib/chat/actions.js +239 -0
  21. package/lib/chat/api.js +103 -0
  22. package/lib/chat/components/app-sidebar.js +161 -0
  23. package/lib/chat/components/app-sidebar.jsx +214 -0
  24. package/lib/chat/components/chat-header.js +9 -0
  25. package/lib/chat/components/chat-header.jsx +14 -0
  26. package/lib/chat/components/chat-input.js +230 -0
  27. package/lib/chat/components/chat-input.jsx +232 -0
  28. package/lib/chat/components/chat-nav-context.js +11 -0
  29. package/lib/chat/components/chat-nav-context.jsx +11 -0
  30. package/lib/chat/components/chat-page.js +70 -0
  31. package/lib/chat/components/chat-page.jsx +89 -0
  32. package/lib/chat/components/chat.js +78 -0
  33. package/lib/chat/components/chat.jsx +91 -0
  34. package/lib/chat/components/chats-page.js +170 -0
  35. package/lib/chat/components/chats-page.jsx +203 -0
  36. package/lib/chat/components/crons-page.js +144 -0
  37. package/lib/chat/components/crons-page.jsx +204 -0
  38. package/lib/chat/components/greeting.js +11 -0
  39. package/lib/chat/components/greeting.jsx +14 -0
  40. package/lib/chat/components/icons.js +518 -0
  41. package/lib/chat/components/icons.jsx +482 -0
  42. package/lib/chat/components/index.js +19 -0
  43. package/lib/chat/components/message.js +66 -0
  44. package/lib/chat/components/message.jsx +92 -0
  45. package/lib/chat/components/messages.js +63 -0
  46. package/lib/chat/components/messages.jsx +72 -0
  47. package/lib/chat/components/notifications-page.js +54 -0
  48. package/lib/chat/components/notifications-page.jsx +83 -0
  49. package/lib/chat/components/page-layout.js +21 -0
  50. package/lib/chat/components/page-layout.jsx +28 -0
  51. package/lib/chat/components/settings-layout.js +37 -0
  52. package/lib/chat/components/settings-layout.jsx +51 -0
  53. package/lib/chat/components/settings-secrets-page.js +216 -0
  54. package/lib/chat/components/settings-secrets-page.jsx +264 -0
  55. package/lib/chat/components/sidebar-history-item.js +54 -0
  56. package/lib/chat/components/sidebar-history-item.jsx +50 -0
  57. package/lib/chat/components/sidebar-history.js +92 -0
  58. package/lib/chat/components/sidebar-history.jsx +132 -0
  59. package/lib/chat/components/sidebar-user-nav.js +59 -0
  60. package/lib/chat/components/sidebar-user-nav.jsx +69 -0
  61. package/lib/chat/components/swarm-page.js +250 -0
  62. package/lib/chat/components/swarm-page.jsx +356 -0
  63. package/lib/chat/components/triggers-page.js +121 -0
  64. package/lib/chat/components/triggers-page.jsx +177 -0
  65. package/lib/chat/components/ui/dropdown-menu.js +98 -0
  66. package/lib/chat/components/ui/dropdown-menu.jsx +116 -0
  67. package/lib/chat/components/ui/scroll-area.js +13 -0
  68. package/lib/chat/components/ui/scroll-area.jsx +17 -0
  69. package/lib/chat/components/ui/separator.js +21 -0
  70. package/lib/chat/components/ui/separator.jsx +18 -0
  71. package/lib/chat/components/ui/sheet.js +75 -0
  72. package/lib/chat/components/ui/sheet.jsx +95 -0
  73. package/lib/chat/components/ui/sidebar.js +227 -0
  74. package/lib/chat/components/ui/sidebar.jsx +245 -0
  75. package/lib/chat/components/ui/tooltip.js +56 -0
  76. package/lib/chat/components/ui/tooltip.jsx +66 -0
  77. package/lib/chat/utils.js +11 -0
  78. package/lib/cron.js +7 -8
  79. package/lib/db/api-keys.js +160 -0
  80. package/lib/db/chats.js +129 -0
  81. package/lib/db/index.js +106 -0
  82. package/lib/db/notifications.js +99 -0
  83. package/lib/db/schema.js +51 -0
  84. package/lib/db/users.js +89 -0
  85. package/lib/paths.js +23 -17
  86. package/lib/tools/create-job.js +3 -3
  87. package/lib/tools/github.js +145 -1
  88. package/lib/tools/openai.js +1 -1
  89. package/lib/tools/telegram.js +4 -3
  90. package/lib/triggers.js +6 -7
  91. package/lib/utils/render-md.js +6 -6
  92. package/package.json +43 -6
  93. package/setup/lib/auth.mjs +22 -9
  94. package/setup/lib/prerequisites.mjs +10 -3
  95. package/setup/lib/telegram-verify.mjs +3 -16
  96. package/setup/setup-telegram.mjs +31 -62
  97. package/setup/setup.mjs +58 -98
  98. package/templates/.dockerignore +5 -0
  99. package/templates/.env.example +18 -2
  100. package/templates/.github/workflows/auto-merge.yml +1 -1
  101. package/templates/.github/workflows/build-image.yml +6 -4
  102. package/templates/.github/workflows/notify-job-failed.yml +2 -2
  103. package/templates/.github/workflows/notify-pr-complete.yml +2 -2
  104. package/templates/.github/workflows/run-job.yml +24 -10
  105. package/templates/CLAUDE.md +5 -3
  106. package/templates/app/api/auth/[...nextauth]/route.js +1 -0
  107. package/templates/app/api/chat/route.js +1 -0
  108. package/templates/app/chat/[chatId]/page.js +8 -0
  109. package/templates/app/chats/page.js +7 -0
  110. package/templates/app/components/ascii-logo.jsx +10 -0
  111. package/templates/app/components/login-form.jsx +81 -0
  112. package/templates/app/components/setup-form.jsx +82 -0
  113. package/templates/app/components/theme-provider.jsx +11 -0
  114. package/templates/app/components/theme-toggle.jsx +38 -0
  115. package/templates/app/components/ui/button.jsx +21 -0
  116. package/templates/app/components/ui/card.jsx +23 -0
  117. package/templates/app/components/ui/input.jsx +10 -0
  118. package/templates/app/components/ui/label.jsx +10 -0
  119. package/templates/app/crons/page.js +7 -0
  120. package/templates/app/globals.css +66 -0
  121. package/templates/app/layout.js +9 -2
  122. package/templates/app/login/page.js +15 -0
  123. package/templates/app/notifications/page.js +7 -0
  124. package/templates/app/page.js +6 -30
  125. package/templates/app/settings/layout.js +7 -0
  126. package/templates/app/settings/page.js +5 -0
  127. package/templates/app/settings/secrets/page.js +5 -0
  128. package/templates/app/swarm/page.js +7 -0
  129. package/templates/app/triggers/page.js +7 -0
  130. package/templates/config/CRONS.json +2 -2
  131. package/templates/config/TRIGGERS.json +2 -2
  132. package/templates/docker/event_handler/Dockerfile +19 -0
  133. package/templates/docker/{entrypoint.sh → job/entrypoint.sh} +4 -4
  134. package/templates/docker/runner/Dockerfile +38 -0
  135. package/templates/docker/runner/entrypoint.sh +41 -0
  136. package/templates/docker-compose.yml +52 -0
  137. package/templates/instrumentation.js +6 -1
  138. package/templates/middleware.js +1 -0
  139. package/templates/postcss.config.mjs +5 -0
  140. package/lib/claude/conversation.js +0 -76
  141. package/lib/claude/index.js +0 -142
  142. package/lib/claude/tools.js +0 -54
  143. /package/templates/docker/{Dockerfile → job/Dockerfile} +0 -0
@@ -0,0 +1,204 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import { PageLayout } from './page-layout.js';
5
+ import { ClockIcon, SpinnerIcon, ChevronDownIcon } from './icons.js';
6
+ import { getSwarmConfig } from '../actions.js';
7
+
8
+ // ─────────────────────────────────────────────────────────────────────────────
9
+ // Utilities
10
+ // ─────────────────────────────────────────────────────────────────────────────
11
+
12
+ function describeCron(schedule) {
13
+ const parts = schedule.trim().split(/\s+/);
14
+ if (parts.length !== 5) return schedule;
15
+
16
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
17
+
18
+ // Every N minutes
19
+ if (minute.startsWith('*/') && hour === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
20
+ const n = parseInt(minute.slice(2), 10);
21
+ if (n === 1) return 'Every minute';
22
+ return `Every ${n} minutes`;
23
+ }
24
+
25
+ // Every N hours
26
+ if (hour.startsWith('*/') && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
27
+ const n = parseInt(hour.slice(2), 10);
28
+ if (n === 1) return 'Every hour';
29
+ return `Every ${n} hours`;
30
+ }
31
+
32
+ // Specific time daily
33
+ if (minute !== '*' && hour !== '*' && !hour.includes('/') && !minute.includes('/') && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
34
+ const h = parseInt(hour, 10);
35
+ const m = parseInt(minute, 10);
36
+ const period = h >= 12 ? 'PM' : 'AM';
37
+ const displayH = h === 0 ? 12 : h > 12 ? h - 12 : h;
38
+ return `Daily at ${displayH}:${String(m).padStart(2, '0')} ${period}`;
39
+ }
40
+
41
+ // Specific time on specific weekdays
42
+ if (minute !== '*' && hour !== '*' && dayOfMonth === '*' && month === '*' && dayOfWeek !== '*') {
43
+ const dayNames = { '0': 'Sun', '1': 'Mon', '2': 'Tue', '3': 'Wed', '4': 'Thu', '5': 'Fri', '6': 'Sat' };
44
+ const days = dayOfWeek.split(',').map(d => dayNames[d] || d).join(', ');
45
+ const h = parseInt(hour, 10);
46
+ const m = parseInt(minute, 10);
47
+ const period = h >= 12 ? 'PM' : 'AM';
48
+ const displayH = h === 0 ? 12 : h > 12 ? h - 12 : h;
49
+ return `${days} at ${displayH}:${String(m).padStart(2, '0')} ${period}`;
50
+ }
51
+
52
+ return schedule;
53
+ }
54
+
55
+ const typeBadgeStyles = {
56
+ agent: 'bg-purple-500/10 text-purple-500',
57
+ command: 'bg-blue-500/10 text-blue-500',
58
+ webhook: 'bg-orange-500/10 text-orange-500',
59
+ };
60
+
61
+ // ─────────────────────────────────────────────────────────────────────────────
62
+ // Cron Card
63
+ // ─────────────────────────────────────────────────────────────────────────────
64
+
65
+ function CronCard({ cron }) {
66
+ const [expanded, setExpanded] = useState(false);
67
+ const type = cron.type || 'agent';
68
+ const disabled = cron.enabled === false;
69
+
70
+ return (
71
+ <div
72
+ className={`rounded-lg border bg-card transition-opacity ${disabled ? 'opacity-60' : ''}`}
73
+ >
74
+ <button
75
+ onClick={() => setExpanded(!expanded)}
76
+ className="flex items-center gap-3 w-full text-left p-4 hover:bg-accent/50 rounded-lg"
77
+ >
78
+ <div className="shrink-0 rounded-md bg-muted p-2">
79
+ <ClockIcon size={16} />
80
+ </div>
81
+ <div className="flex-1 min-w-0">
82
+ <p className="text-sm font-medium truncate">{cron.name}</p>
83
+ <p className="text-xs text-muted-foreground mt-0.5">
84
+ <span className="font-mono">{cron.schedule}</span>
85
+ <span className="mx-1.5 text-border">|</span>
86
+ {describeCron(cron.schedule)}
87
+ </p>
88
+ </div>
89
+ <div className="flex items-center gap-2 shrink-0">
90
+ <span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${typeBadgeStyles[type] || typeBadgeStyles.agent}`}>
91
+ {type}
92
+ </span>
93
+ <span
94
+ className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${
95
+ disabled ? 'bg-muted text-muted-foreground' : 'bg-green-500/10 text-green-500'
96
+ }`}
97
+ >
98
+ {disabled ? 'disabled' : 'enabled'}
99
+ </span>
100
+ <span className={`transition-transform ${expanded ? 'rotate-180' : ''}`}>
101
+ <ChevronDownIcon size={14} />
102
+ </span>
103
+ </div>
104
+ </button>
105
+
106
+ {expanded && (
107
+ <div className="border-t px-4 py-3">
108
+ {type === 'agent' && cron.job && (
109
+ <div>
110
+ <p className="text-xs font-medium text-muted-foreground mb-1.5">Job prompt</p>
111
+ <pre className="text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48">
112
+ {cron.job}
113
+ </pre>
114
+ </div>
115
+ )}
116
+ {type === 'command' && cron.command && (
117
+ <div>
118
+ <p className="text-xs font-medium text-muted-foreground mb-1.5">Command</p>
119
+ <pre className="text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48">
120
+ {cron.command}
121
+ </pre>
122
+ </div>
123
+ )}
124
+ {type === 'webhook' && (
125
+ <div className="flex flex-col gap-2">
126
+ <div>
127
+ <p className="text-xs font-medium text-muted-foreground mb-1.5">URL</p>
128
+ <pre className="text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto">
129
+ {cron.method && cron.method !== 'POST' ? `${cron.method} ` : ''}{cron.url}
130
+ </pre>
131
+ </div>
132
+ {cron.vars && Object.keys(cron.vars).length > 0 && (
133
+ <div>
134
+ <p className="text-xs font-medium text-muted-foreground mb-1.5">Variables</p>
135
+ <pre className="text-xs bg-muted rounded-md p-3 whitespace-pre-wrap break-words font-mono overflow-auto max-h-48">
136
+ {JSON.stringify(cron.vars, null, 2)}
137
+ </pre>
138
+ </div>
139
+ )}
140
+ </div>
141
+ )}
142
+ </div>
143
+ )}
144
+ </div>
145
+ );
146
+ }
147
+
148
+ // ─────────────────────────────────────────────────────────────────────────────
149
+ // Main Page
150
+ // ─────────────────────────────────────────────────────────────────────────────
151
+
152
+ export function CronsPage({ session }) {
153
+ const [crons, setCrons] = useState([]);
154
+ const [loading, setLoading] = useState(true);
155
+
156
+ useEffect(() => {
157
+ getSwarmConfig()
158
+ .then((data) => {
159
+ if (data?.crons) setCrons(data.crons);
160
+ })
161
+ .catch(() => {})
162
+ .finally(() => setLoading(false));
163
+ }, []);
164
+
165
+ const enabledCount = crons.filter((c) => c.enabled !== false).length;
166
+
167
+ return (
168
+ <PageLayout session={session}>
169
+ {/* Header */}
170
+ <div className="mb-6">
171
+ <h1 className="text-2xl font-semibold">Cron Jobs</h1>
172
+ {!loading && (
173
+ <p className="text-sm text-muted-foreground mt-1">
174
+ {crons.length} job{crons.length !== 1 ? 's' : ''} configured, {enabledCount} enabled
175
+ </p>
176
+ )}
177
+ </div>
178
+
179
+ {loading ? (
180
+ <div className="flex flex-col gap-3">
181
+ {[...Array(3)].map((_, i) => (
182
+ <div key={i} className="h-20 animate-pulse rounded-lg bg-border/50" />
183
+ ))}
184
+ </div>
185
+ ) : crons.length === 0 ? (
186
+ <div className="flex flex-col items-center justify-center py-16 text-center">
187
+ <div className="rounded-full bg-muted p-4 mb-4">
188
+ <ClockIcon size={24} />
189
+ </div>
190
+ <p className="text-sm font-medium mb-1">No cron jobs configured</p>
191
+ <p className="text-xs text-muted-foreground max-w-sm">
192
+ Add scheduled jobs by editing <span className="font-mono">config/CRONS.json</span> in your project.
193
+ </p>
194
+ </div>
195
+ ) : (
196
+ <div className="flex flex-col gap-3">
197
+ {crons.map((cron, i) => (
198
+ <CronCard key={i} cron={cron} />
199
+ ))}
200
+ </div>
201
+ )}
202
+ </PageLayout>
203
+ );
204
+ }
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ function Greeting() {
4
+ return /* @__PURE__ */ jsxs("div", { className: "mx-auto mt-8 flex size-full max-w-3xl flex-col justify-center px-4 md:mt-16 md:px-8", children: [
5
+ /* @__PURE__ */ jsx("div", { className: "font-semibold text-xl md:text-2xl text-foreground", children: "Hello there!" }),
6
+ /* @__PURE__ */ jsx("div", { className: "text-xl text-muted-foreground md:text-2xl", children: "How can I help you today?" })
7
+ ] });
8
+ }
9
+ export {
10
+ Greeting
11
+ };
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+
3
+ export function Greeting() {
4
+ return (
5
+ <div className="mx-auto mt-8 flex size-full max-w-3xl flex-col justify-center px-4 md:mt-16 md:px-8">
6
+ <div className="font-semibold text-xl md:text-2xl text-foreground">
7
+ Hello there!
8
+ </div>
9
+ <div className="text-xl text-muted-foreground md:text-2xl">
10
+ How can I help you today?
11
+ </div>
12
+ </div>
13
+ );
14
+ }