agent-relay 2.0.23 → 2.0.24

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 (168) hide show
  1. package/dist/src/cli/index.js +66 -13
  2. package/package.json +18 -52
  3. package/packages/api-types/package.json +1 -1
  4. package/packages/bridge/package.json +8 -8
  5. package/packages/cli-tester/package.json +1 -1
  6. package/packages/config/package.json +2 -2
  7. package/packages/continuity/package.json +1 -1
  8. package/packages/daemon/package.json +12 -12
  9. package/packages/hooks/package.json +4 -4
  10. package/packages/mcp/package.json +2 -2
  11. package/packages/memory/package.json +2 -2
  12. package/packages/policy/package.json +2 -2
  13. package/packages/protocol/package.json +1 -1
  14. package/packages/resiliency/package.json +1 -1
  15. package/packages/sdk/package.json +2 -2
  16. package/packages/spawner/package.json +1 -1
  17. package/packages/state/package.json +1 -1
  18. package/packages/storage/package.json +2 -2
  19. package/packages/telemetry/package.json +1 -1
  20. package/packages/trajectory/package.json +2 -2
  21. package/packages/user-directory/package.json +2 -2
  22. package/packages/utils/package.json +1 -1
  23. package/packages/wrapper/package.json +6 -6
  24. package/deploy/init-db.sql +0 -5
  25. package/deploy/scripts/setup-fly-workspaces.sh +0 -69
  26. package/deploy/scripts/setup-railway.sh +0 -75
  27. package/dist/src/cloud/index.d.ts +0 -8
  28. package/dist/src/cloud/index.js +0 -8
  29. package/packages/cloud/dist/api/admin.d.ts +0 -8
  30. package/packages/cloud/dist/api/admin.js +0 -225
  31. package/packages/cloud/dist/api/auth.d.ts +0 -20
  32. package/packages/cloud/dist/api/auth.js +0 -138
  33. package/packages/cloud/dist/api/billing.d.ts +0 -7
  34. package/packages/cloud/dist/api/billing.js +0 -564
  35. package/packages/cloud/dist/api/cli-pty-runner.d.ts +0 -53
  36. package/packages/cloud/dist/api/cli-pty-runner.js +0 -175
  37. package/packages/cloud/dist/api/codex-auth-helper.d.ts +0 -21
  38. package/packages/cloud/dist/api/codex-auth-helper.js +0 -327
  39. package/packages/cloud/dist/api/consensus.d.ts +0 -13
  40. package/packages/cloud/dist/api/consensus.js +0 -261
  41. package/packages/cloud/dist/api/coordinators.d.ts +0 -8
  42. package/packages/cloud/dist/api/coordinators.js +0 -750
  43. package/packages/cloud/dist/api/daemons.d.ts +0 -12
  44. package/packages/cloud/dist/api/daemons.js +0 -535
  45. package/packages/cloud/dist/api/email-auth.d.ts +0 -11
  46. package/packages/cloud/dist/api/email-auth.js +0 -347
  47. package/packages/cloud/dist/api/generic-webhooks.d.ts +0 -8
  48. package/packages/cloud/dist/api/generic-webhooks.js +0 -129
  49. package/packages/cloud/dist/api/git.d.ts +0 -8
  50. package/packages/cloud/dist/api/git.js +0 -269
  51. package/packages/cloud/dist/api/github-app.d.ts +0 -11
  52. package/packages/cloud/dist/api/github-app.js +0 -223
  53. package/packages/cloud/dist/api/middleware/planLimits.d.ts +0 -43
  54. package/packages/cloud/dist/api/middleware/planLimits.js +0 -202
  55. package/packages/cloud/dist/api/monitoring.d.ts +0 -11
  56. package/packages/cloud/dist/api/monitoring.js +0 -578
  57. package/packages/cloud/dist/api/nango-auth.d.ts +0 -9
  58. package/packages/cloud/dist/api/nango-auth.js +0 -741
  59. package/packages/cloud/dist/api/onboarding.d.ts +0 -15
  60. package/packages/cloud/dist/api/onboarding.js +0 -679
  61. package/packages/cloud/dist/api/policy.d.ts +0 -8
  62. package/packages/cloud/dist/api/policy.js +0 -229
  63. package/packages/cloud/dist/api/provider-env.d.ts +0 -26
  64. package/packages/cloud/dist/api/provider-env.js +0 -141
  65. package/packages/cloud/dist/api/providers.d.ts +0 -7
  66. package/packages/cloud/dist/api/providers.js +0 -574
  67. package/packages/cloud/dist/api/repos.d.ts +0 -8
  68. package/packages/cloud/dist/api/repos.js +0 -577
  69. package/packages/cloud/dist/api/sessions.d.ts +0 -11
  70. package/packages/cloud/dist/api/sessions.js +0 -302
  71. package/packages/cloud/dist/api/teams.d.ts +0 -7
  72. package/packages/cloud/dist/api/teams.js +0 -281
  73. package/packages/cloud/dist/api/test-helpers.d.ts +0 -10
  74. package/packages/cloud/dist/api/test-helpers.js +0 -745
  75. package/packages/cloud/dist/api/usage.d.ts +0 -7
  76. package/packages/cloud/dist/api/usage.js +0 -111
  77. package/packages/cloud/dist/api/webhooks.d.ts +0 -8
  78. package/packages/cloud/dist/api/webhooks.js +0 -645
  79. package/packages/cloud/dist/api/workspaces.d.ts +0 -25
  80. package/packages/cloud/dist/api/workspaces.js +0 -1799
  81. package/packages/cloud/dist/billing/index.d.ts +0 -9
  82. package/packages/cloud/dist/billing/index.js +0 -9
  83. package/packages/cloud/dist/billing/plans.d.ts +0 -39
  84. package/packages/cloud/dist/billing/plans.js +0 -245
  85. package/packages/cloud/dist/billing/service.d.ts +0 -80
  86. package/packages/cloud/dist/billing/service.js +0 -388
  87. package/packages/cloud/dist/billing/types.d.ts +0 -141
  88. package/packages/cloud/dist/billing/types.js +0 -7
  89. package/packages/cloud/dist/config.d.ts +0 -5
  90. package/packages/cloud/dist/config.js +0 -5
  91. package/packages/cloud/dist/db/bulk-ingest.d.ts +0 -89
  92. package/packages/cloud/dist/db/bulk-ingest.js +0 -268
  93. package/packages/cloud/dist/db/drizzle.d.ts +0 -290
  94. package/packages/cloud/dist/db/drizzle.js +0 -1422
  95. package/packages/cloud/dist/db/index.d.ts +0 -56
  96. package/packages/cloud/dist/db/index.js +0 -70
  97. package/packages/cloud/dist/db/schema.d.ts +0 -5117
  98. package/packages/cloud/dist/db/schema.js +0 -656
  99. package/packages/cloud/dist/index.d.ts +0 -11
  100. package/packages/cloud/dist/index.js +0 -38
  101. package/packages/cloud/dist/provisioner/index.d.ts +0 -207
  102. package/packages/cloud/dist/provisioner/index.js +0 -2118
  103. package/packages/cloud/dist/server.d.ts +0 -17
  104. package/packages/cloud/dist/server.js +0 -2055
  105. package/packages/cloud/dist/services/auto-scaler.d.ts +0 -152
  106. package/packages/cloud/dist/services/auto-scaler.js +0 -439
  107. package/packages/cloud/dist/services/capacity-manager.d.ts +0 -148
  108. package/packages/cloud/dist/services/capacity-manager.js +0 -449
  109. package/packages/cloud/dist/services/ci-agent-spawner.d.ts +0 -49
  110. package/packages/cloud/dist/services/ci-agent-spawner.js +0 -373
  111. package/packages/cloud/dist/services/cloud-message-bus.d.ts +0 -28
  112. package/packages/cloud/dist/services/cloud-message-bus.js +0 -19
  113. package/packages/cloud/dist/services/compute-enforcement.d.ts +0 -57
  114. package/packages/cloud/dist/services/compute-enforcement.js +0 -175
  115. package/packages/cloud/dist/services/coordinator.d.ts +0 -62
  116. package/packages/cloud/dist/services/coordinator.js +0 -389
  117. package/packages/cloud/dist/services/index.d.ts +0 -17
  118. package/packages/cloud/dist/services/index.js +0 -25
  119. package/packages/cloud/dist/services/intro-expiration.d.ts +0 -60
  120. package/packages/cloud/dist/services/intro-expiration.js +0 -252
  121. package/packages/cloud/dist/services/mention-handler.d.ts +0 -65
  122. package/packages/cloud/dist/services/mention-handler.js +0 -405
  123. package/packages/cloud/dist/services/nango.d.ts +0 -219
  124. package/packages/cloud/dist/services/nango.js +0 -424
  125. package/packages/cloud/dist/services/persistence.d.ts +0 -131
  126. package/packages/cloud/dist/services/persistence.js +0 -200
  127. package/packages/cloud/dist/services/planLimits.d.ts +0 -147
  128. package/packages/cloud/dist/services/planLimits.js +0 -335
  129. package/packages/cloud/dist/services/presence-registry.d.ts +0 -56
  130. package/packages/cloud/dist/services/presence-registry.js +0 -91
  131. package/packages/cloud/dist/services/scaling-orchestrator.d.ts +0 -159
  132. package/packages/cloud/dist/services/scaling-orchestrator.js +0 -502
  133. package/packages/cloud/dist/services/scaling-policy.d.ts +0 -121
  134. package/packages/cloud/dist/services/scaling-policy.js +0 -415
  135. package/packages/cloud/dist/services/ssh-security.d.ts +0 -31
  136. package/packages/cloud/dist/services/ssh-security.js +0 -63
  137. package/packages/cloud/dist/services/workspace-keepalive.d.ts +0 -76
  138. package/packages/cloud/dist/services/workspace-keepalive.js +0 -234
  139. package/packages/cloud/dist/shims/consensus.d.ts +0 -23
  140. package/packages/cloud/dist/shims/consensus.js +0 -5
  141. package/packages/cloud/dist/webhooks/index.d.ts +0 -24
  142. package/packages/cloud/dist/webhooks/index.js +0 -29
  143. package/packages/cloud/dist/webhooks/parsers/github.d.ts +0 -8
  144. package/packages/cloud/dist/webhooks/parsers/github.js +0 -234
  145. package/packages/cloud/dist/webhooks/parsers/index.d.ts +0 -23
  146. package/packages/cloud/dist/webhooks/parsers/index.js +0 -30
  147. package/packages/cloud/dist/webhooks/parsers/linear.d.ts +0 -9
  148. package/packages/cloud/dist/webhooks/parsers/linear.js +0 -258
  149. package/packages/cloud/dist/webhooks/parsers/slack.d.ts +0 -9
  150. package/packages/cloud/dist/webhooks/parsers/slack.js +0 -214
  151. package/packages/cloud/dist/webhooks/responders/github.d.ts +0 -8
  152. package/packages/cloud/dist/webhooks/responders/github.js +0 -73
  153. package/packages/cloud/dist/webhooks/responders/index.d.ts +0 -23
  154. package/packages/cloud/dist/webhooks/responders/index.js +0 -30
  155. package/packages/cloud/dist/webhooks/responders/linear.d.ts +0 -9
  156. package/packages/cloud/dist/webhooks/responders/linear.js +0 -149
  157. package/packages/cloud/dist/webhooks/responders/slack.d.ts +0 -20
  158. package/packages/cloud/dist/webhooks/responders/slack.js +0 -178
  159. package/packages/cloud/dist/webhooks/router.d.ts +0 -25
  160. package/packages/cloud/dist/webhooks/router.js +0 -504
  161. package/packages/cloud/dist/webhooks/rules-engine.d.ts +0 -24
  162. package/packages/cloud/dist/webhooks/rules-engine.js +0 -287
  163. package/packages/cloud/dist/webhooks/types.d.ts +0 -186
  164. package/packages/cloud/dist/webhooks/types.js +0 -8
  165. package/packages/cloud/package.json +0 -60
  166. package/scripts/run-migrations.js +0 -43
  167. package/scripts/setup-stripe-products.ts +0 -312
  168. package/scripts/verify-schema.js +0 -134
@@ -1,750 +0,0 @@
1
- /**
2
- * Coordinator Agent API Routes
3
- *
4
- * Manage coordinator agents for project groups.
5
- * Coordinators oversee and orchestrate work across repositories in a group.
6
- */
7
- import { Router } from 'express';
8
- import { requireAuth } from './auth.js';
9
- import { checkCoordinatorAccess } from './middleware/planLimits.js';
10
- import { db } from '../db/index.js';
11
- import { getCoordinatorService, sendToWorkspace, broadcastToGroup, routeToCoordinator, getActiveCoordinators, } from '../services/coordinator.js';
12
- export const coordinatorsRouter = Router();
13
- // All routes require authentication
14
- coordinatorsRouter.use(requireAuth);
15
- // Coordinator modification routes require Pro plan or higher
16
- const coordinatorWriteRoutes = [
17
- '/:groupId/coordinator/enable',
18
- '/:groupId/coordinator/disable',
19
- ];
20
- coordinatorWriteRoutes.forEach(route => {
21
- coordinatorsRouter.use(route, checkCoordinatorAccess);
22
- });
23
- // ============================================================================
24
- // Project Group CRUD Routes
25
- // These must come BEFORE the /:groupId/coordinator routes
26
- // ============================================================================
27
- /**
28
- * GET /api/project-groups
29
- * List all project groups for the authenticated user
30
- */
31
- coordinatorsRouter.get('/', async (req, res) => {
32
- const userId = req.session.userId;
33
- try {
34
- const result = await db.projectGroups.findAllWithRepositories(userId);
35
- res.json({
36
- groups: result.groups.map(group => ({
37
- id: group.id,
38
- name: group.name,
39
- description: group.description,
40
- color: group.color,
41
- icon: group.icon,
42
- coordinatorAgent: group.coordinatorAgent,
43
- sortOrder: group.sortOrder,
44
- repositoryCount: group.repositories.length,
45
- repositories: group.repositories.map(repo => ({
46
- id: repo.id,
47
- githubFullName: repo.githubFullName,
48
- defaultBranch: repo.defaultBranch,
49
- isPrivate: repo.isPrivate,
50
- })),
51
- createdAt: group.createdAt,
52
- updatedAt: group.updatedAt,
53
- })),
54
- ungroupedRepositories: result.ungroupedRepositories.map(repo => ({
55
- id: repo.id,
56
- githubFullName: repo.githubFullName,
57
- defaultBranch: repo.defaultBranch,
58
- isPrivate: repo.isPrivate,
59
- workspaceId: repo.workspaceId,
60
- })),
61
- });
62
- }
63
- catch (error) {
64
- console.error('Error listing project groups:', error);
65
- res.status(500).json({ error: 'Failed to list project groups' });
66
- }
67
- });
68
- /**
69
- * POST /api/project-groups
70
- * Create a new project group
71
- */
72
- coordinatorsRouter.post('/', async (req, res) => {
73
- const userId = req.session.userId;
74
- const { name, description, color, icon, repositoryIds } = req.body;
75
- if (!name || typeof name !== 'string' || name.trim().length === 0) {
76
- return res.status(400).json({ error: 'Name is required' });
77
- }
78
- if (name.length > 255) {
79
- return res.status(400).json({ error: 'Name must be 255 characters or less' });
80
- }
81
- try {
82
- // Check for duplicate name
83
- const existing = await db.projectGroups.findByName(userId, name.trim());
84
- if (existing) {
85
- return res.status(409).json({ error: 'A project group with this name already exists' });
86
- }
87
- // Create the group
88
- const group = await db.projectGroups.create({
89
- userId,
90
- name: name.trim(),
91
- description: description?.trim() || null,
92
- color: color || null,
93
- icon: icon || null,
94
- coordinatorAgent: { enabled: false },
95
- sortOrder: 0,
96
- });
97
- // Assign repositories to the group if provided
98
- if (repositoryIds && Array.isArray(repositoryIds) && repositoryIds.length > 0) {
99
- // Verify all repositories belong to the user
100
- const userRepos = await db.repositories.findByUserId(userId);
101
- const userRepoIds = new Set(userRepos.map(r => r.id));
102
- for (const repoId of repositoryIds) {
103
- if (!userRepoIds.has(repoId)) {
104
- return res.status(400).json({
105
- error: `Repository ${repoId} not found or not owned by user`,
106
- });
107
- }
108
- }
109
- // Assign repositories to the group
110
- for (const repoId of repositoryIds) {
111
- await db.repositories.assignToGroup(repoId, group.id);
112
- }
113
- }
114
- // Fetch the group with repositories for response
115
- const groupWithRepos = await db.projectGroups.findWithRepositories(group.id);
116
- res.status(201).json({
117
- success: true,
118
- group: {
119
- id: groupWithRepos.id,
120
- name: groupWithRepos.name,
121
- description: groupWithRepos.description,
122
- color: groupWithRepos.color,
123
- icon: groupWithRepos.icon,
124
- coordinatorAgent: groupWithRepos.coordinatorAgent,
125
- repositories: groupWithRepos.repositories.map(repo => ({
126
- id: repo.id,
127
- githubFullName: repo.githubFullName,
128
- defaultBranch: repo.defaultBranch,
129
- isPrivate: repo.isPrivate,
130
- })),
131
- createdAt: groupWithRepos.createdAt,
132
- updatedAt: groupWithRepos.updatedAt,
133
- },
134
- });
135
- }
136
- catch (error) {
137
- console.error('Error creating project group:', error);
138
- res.status(500).json({ error: 'Failed to create project group' });
139
- }
140
- });
141
- /**
142
- * GET /api/project-groups/:id
143
- * Get a specific project group with its repositories
144
- */
145
- coordinatorsRouter.get('/:id', async (req, res) => {
146
- const userId = req.session.userId;
147
- const id = req.params.id;
148
- // Skip if this looks like a coordinator route
149
- if (id === 'coordinators') {
150
- return res.status(404).json({ error: 'Not found' });
151
- }
152
- try {
153
- const group = await db.projectGroups.findWithRepositories(id);
154
- if (!group) {
155
- return res.status(404).json({ error: 'Project group not found' });
156
- }
157
- if (group.userId !== userId) {
158
- return res.status(403).json({ error: 'Unauthorized' });
159
- }
160
- res.json({
161
- id: group.id,
162
- name: group.name,
163
- description: group.description,
164
- color: group.color,
165
- icon: group.icon,
166
- coordinatorAgent: group.coordinatorAgent,
167
- sortOrder: group.sortOrder,
168
- repositories: group.repositories.map(repo => ({
169
- id: repo.id,
170
- githubFullName: repo.githubFullName,
171
- defaultBranch: repo.defaultBranch,
172
- isPrivate: repo.isPrivate,
173
- syncStatus: repo.syncStatus,
174
- lastSyncedAt: repo.lastSyncedAt,
175
- workspaceId: repo.workspaceId,
176
- })),
177
- createdAt: group.createdAt,
178
- updatedAt: group.updatedAt,
179
- });
180
- }
181
- catch (error) {
182
- console.error('Error getting project group:', error);
183
- res.status(500).json({ error: 'Failed to get project group' });
184
- }
185
- });
186
- /**
187
- * PATCH /api/project-groups/:id
188
- * Update a project group's metadata
189
- */
190
- coordinatorsRouter.patch('/:id', async (req, res) => {
191
- const userId = req.session.userId;
192
- const id = req.params.id;
193
- const { name, description, color, icon } = req.body;
194
- try {
195
- const group = await db.projectGroups.findById(id);
196
- if (!group) {
197
- return res.status(404).json({ error: 'Project group not found' });
198
- }
199
- if (group.userId !== userId) {
200
- return res.status(403).json({ error: 'Unauthorized' });
201
- }
202
- // Build update object with only provided fields
203
- const updates = {};
204
- if (name !== undefined) {
205
- if (typeof name !== 'string' || name.trim().length === 0) {
206
- return res.status(400).json({ error: 'Name cannot be empty' });
207
- }
208
- if (name.length > 255) {
209
- return res.status(400).json({ error: 'Name must be 255 characters or less' });
210
- }
211
- // Check for duplicate name (excluding current group)
212
- const existing = await db.projectGroups.findByName(userId, name.trim());
213
- if (existing && existing.id !== id) {
214
- return res.status(409).json({ error: 'A project group with this name already exists' });
215
- }
216
- updates.name = name.trim();
217
- }
218
- if (description !== undefined) {
219
- updates.description = description?.trim() || null;
220
- }
221
- if (color !== undefined) {
222
- // Validate hex color format if provided
223
- if (color && !/^#[0-9A-Fa-f]{6}$/.test(color)) {
224
- return res.status(400).json({ error: 'Color must be a valid hex color (e.g., #3B82F6)' });
225
- }
226
- updates.color = color || null;
227
- }
228
- if (icon !== undefined) {
229
- updates.icon = icon || null;
230
- }
231
- if (Object.keys(updates).length === 0) {
232
- return res.status(400).json({ error: 'No valid fields to update' });
233
- }
234
- await db.projectGroups.update(id, updates);
235
- // Fetch updated group
236
- const updatedGroup = await db.projectGroups.findWithRepositories(id);
237
- res.json({
238
- success: true,
239
- group: {
240
- id: updatedGroup.id,
241
- name: updatedGroup.name,
242
- description: updatedGroup.description,
243
- color: updatedGroup.color,
244
- icon: updatedGroup.icon,
245
- coordinatorAgent: updatedGroup.coordinatorAgent,
246
- repositories: updatedGroup.repositories.map(repo => ({
247
- id: repo.id,
248
- githubFullName: repo.githubFullName,
249
- defaultBranch: repo.defaultBranch,
250
- isPrivate: repo.isPrivate,
251
- })),
252
- updatedAt: updatedGroup.updatedAt,
253
- },
254
- });
255
- }
256
- catch (error) {
257
- console.error('Error updating project group:', error);
258
- res.status(500).json({ error: 'Failed to update project group' });
259
- }
260
- });
261
- /**
262
- * DELETE /api/project-groups/:id
263
- * Delete a project group (repositories are unassigned, not deleted)
264
- */
265
- coordinatorsRouter.delete('/:id', async (req, res) => {
266
- const userId = req.session.userId;
267
- const id = req.params.id;
268
- try {
269
- const group = await db.projectGroups.findById(id);
270
- if (!group) {
271
- return res.status(404).json({ error: 'Project group not found' });
272
- }
273
- if (group.userId !== userId) {
274
- return res.status(403).json({ error: 'Unauthorized' });
275
- }
276
- // Stop coordinator if running
277
- if (group.coordinatorAgent?.enabled) {
278
- try {
279
- const coordinatorService = getCoordinatorService();
280
- await coordinatorService.stop(id);
281
- }
282
- catch (err) {
283
- console.warn('Error stopping coordinator during group deletion:', err);
284
- }
285
- }
286
- // Delete the group (repositories will have projectGroupId set to null due to ON DELETE SET NULL)
287
- await db.projectGroups.delete(id);
288
- res.json({
289
- success: true,
290
- message: 'Project group deleted',
291
- });
292
- }
293
- catch (error) {
294
- console.error('Error deleting project group:', error);
295
- res.status(500).json({ error: 'Failed to delete project group' });
296
- }
297
- });
298
- /**
299
- * POST /api/project-groups/:id/repositories
300
- * Add repositories to a project group
301
- */
302
- coordinatorsRouter.post('/:id/repositories', async (req, res) => {
303
- const userId = req.session.userId;
304
- const id = req.params.id;
305
- const { repositoryIds } = req.body;
306
- if (!repositoryIds || !Array.isArray(repositoryIds) || repositoryIds.length === 0) {
307
- return res.status(400).json({ error: 'repositoryIds array is required' });
308
- }
309
- try {
310
- const group = await db.projectGroups.findById(id);
311
- if (!group) {
312
- return res.status(404).json({ error: 'Project group not found' });
313
- }
314
- if (group.userId !== userId) {
315
- return res.status(403).json({ error: 'Unauthorized' });
316
- }
317
- // Verify all repositories belong to the user
318
- const userRepos = await db.repositories.findByUserId(userId);
319
- const userRepoIds = new Set(userRepos.map(r => r.id));
320
- for (const repoId of repositoryIds) {
321
- if (!userRepoIds.has(repoId)) {
322
- return res.status(400).json({
323
- error: `Repository ${repoId} not found or not owned by user`,
324
- });
325
- }
326
- }
327
- // Assign repositories to the group
328
- for (const repoId of repositoryIds) {
329
- await db.repositories.assignToGroup(repoId, id);
330
- }
331
- // Fetch updated group
332
- const updatedGroup = await db.projectGroups.findWithRepositories(id);
333
- res.json({
334
- success: true,
335
- group: {
336
- id: updatedGroup.id,
337
- name: updatedGroup.name,
338
- repositories: updatedGroup.repositories.map(repo => ({
339
- id: repo.id,
340
- githubFullName: repo.githubFullName,
341
- defaultBranch: repo.defaultBranch,
342
- isPrivate: repo.isPrivate,
343
- })),
344
- },
345
- });
346
- }
347
- catch (error) {
348
- console.error('Error adding repositories to group:', error);
349
- res.status(500).json({ error: 'Failed to add repositories to group' });
350
- }
351
- });
352
- /**
353
- * DELETE /api/project-groups/:id/repositories/:repoId
354
- * Remove a repository from a project group
355
- */
356
- coordinatorsRouter.delete('/:id/repositories/:repoId', async (req, res) => {
357
- const userId = req.session.userId;
358
- const id = req.params.id;
359
- const repoId = req.params.repoId;
360
- try {
361
- const group = await db.projectGroups.findById(id);
362
- if (!group) {
363
- return res.status(404).json({ error: 'Project group not found' });
364
- }
365
- if (group.userId !== userId) {
366
- return res.status(403).json({ error: 'Unauthorized' });
367
- }
368
- // Verify repository exists and belongs to this group
369
- const repo = await db.repositories.findById(repoId);
370
- if (!repo) {
371
- return res.status(404).json({ error: 'Repository not found' });
372
- }
373
- if (repo.userId !== userId) {
374
- return res.status(403).json({ error: 'Unauthorized' });
375
- }
376
- if (repo.projectGroupId !== id) {
377
- return res.status(400).json({ error: 'Repository is not in this group' });
378
- }
379
- // Remove repository from group (set projectGroupId to null)
380
- await db.repositories.assignToGroup(repoId, null);
381
- res.json({
382
- success: true,
383
- message: 'Repository removed from group',
384
- });
385
- }
386
- catch (error) {
387
- console.error('Error removing repository from group:', error);
388
- res.status(500).json({ error: 'Failed to remove repository from group' });
389
- }
390
- });
391
- /**
392
- * PUT /api/project-groups/reorder
393
- * Reorder project groups
394
- */
395
- coordinatorsRouter.put('/reorder', async (req, res) => {
396
- const userId = req.session.userId;
397
- const { orderedIds } = req.body;
398
- if (!orderedIds || !Array.isArray(orderedIds)) {
399
- return res.status(400).json({ error: 'orderedIds array is required' });
400
- }
401
- try {
402
- // Verify all groups belong to user
403
- const userGroups = await db.projectGroups.findByUserId(userId);
404
- const userGroupIds = new Set(userGroups.map(g => g.id));
405
- for (const groupId of orderedIds) {
406
- if (!userGroupIds.has(groupId)) {
407
- return res.status(400).json({
408
- error: `Group ${groupId} not found or not owned by user`,
409
- });
410
- }
411
- }
412
- await db.projectGroups.reorder(userId, orderedIds);
413
- res.json({
414
- success: true,
415
- message: 'Groups reordered',
416
- });
417
- }
418
- catch (error) {
419
- console.error('Error reordering project groups:', error);
420
- res.status(500).json({ error: 'Failed to reorder project groups' });
421
- }
422
- });
423
- // ============================================================================
424
- // Coordinator Agent Routes
425
- // ============================================================================
426
- /**
427
- * GET /api/project-groups/:groupId/coordinator
428
- * Get coordinator agent configuration
429
- */
430
- coordinatorsRouter.get('/:groupId/coordinator', async (req, res) => {
431
- const userId = req.session.userId;
432
- const groupId = req.params.groupId;
433
- try {
434
- const group = await db.projectGroups.findById(groupId);
435
- if (!group) {
436
- return res.status(404).json({ error: 'Project group not found' });
437
- }
438
- if (group.userId !== userId) {
439
- return res.status(403).json({ error: 'Unauthorized' });
440
- }
441
- res.json({
442
- groupId: group.id,
443
- groupName: group.name,
444
- coordinator: group.coordinatorAgent || { enabled: false },
445
- });
446
- }
447
- catch (error) {
448
- console.error('Error getting coordinator config:', error);
449
- res.status(500).json({ error: 'Failed to get coordinator configuration' });
450
- }
451
- });
452
- /**
453
- * PUT /api/project-groups/:groupId/coordinator
454
- * Update coordinator agent configuration
455
- */
456
- coordinatorsRouter.put('/:groupId/coordinator', async (req, res) => {
457
- const userId = req.session.userId;
458
- const groupId = req.params.groupId;
459
- const { name, model, systemPrompt, capabilities } = req.body;
460
- try {
461
- const group = await db.projectGroups.findById(groupId);
462
- if (!group) {
463
- return res.status(404).json({ error: 'Project group not found' });
464
- }
465
- if (group.userId !== userId) {
466
- return res.status(403).json({ error: 'Unauthorized' });
467
- }
468
- // Build updated config, preserving enabled state
469
- const currentConfig = group.coordinatorAgent || { enabled: false };
470
- const updatedConfig = {
471
- enabled: currentConfig.enabled,
472
- name: name !== undefined ? name : currentConfig.name,
473
- model: model !== undefined ? model : currentConfig.model,
474
- systemPrompt: systemPrompt !== undefined ? systemPrompt : currentConfig.systemPrompt,
475
- capabilities: capabilities !== undefined ? capabilities : currentConfig.capabilities,
476
- };
477
- await db.projectGroups.updateCoordinatorAgent(groupId, updatedConfig);
478
- // If coordinator is currently enabled, restart it with new config
479
- if (updatedConfig.enabled) {
480
- const coordinatorService = getCoordinatorService();
481
- await coordinatorService.restart(groupId);
482
- }
483
- res.json({
484
- success: true,
485
- coordinator: updatedConfig,
486
- });
487
- }
488
- catch (error) {
489
- console.error('Error updating coordinator config:', error);
490
- res.status(500).json({ error: 'Failed to update coordinator configuration' });
491
- }
492
- });
493
- /**
494
- * POST /api/project-groups/:groupId/coordinator/enable
495
- * Enable coordinator agent for a project group
496
- */
497
- coordinatorsRouter.post('/:groupId/coordinator/enable', async (req, res) => {
498
- const userId = req.session.userId;
499
- const groupId = req.params.groupId;
500
- try {
501
- const group = await db.projectGroups.findById(groupId);
502
- if (!group) {
503
- return res.status(404).json({ error: 'Project group not found' });
504
- }
505
- if (group.userId !== userId) {
506
- return res.status(403).json({ error: 'Unauthorized' });
507
- }
508
- // Plan check is handled by checkCoordinatorAccess middleware
509
- // Get repositories in the group
510
- const repositories = await db.repositories.findByProjectGroupId(groupId);
511
- if (repositories.length === 0) {
512
- return res.status(400).json({
513
- error: 'Cannot enable coordinator for empty group',
514
- message: 'Add at least one repository to this group first',
515
- });
516
- }
517
- // Enable coordinator
518
- const currentConfig = group.coordinatorAgent || { enabled: false };
519
- const updatedConfig = {
520
- ...currentConfig,
521
- enabled: true,
522
- name: currentConfig.name || `${group.name} Coordinator`,
523
- };
524
- await db.projectGroups.updateCoordinatorAgent(groupId, updatedConfig);
525
- // Start the coordinator agent
526
- const coordinatorService = getCoordinatorService();
527
- await coordinatorService.start(groupId);
528
- res.json({
529
- success: true,
530
- message: 'Coordinator agent enabled',
531
- coordinator: updatedConfig,
532
- });
533
- }
534
- catch (error) {
535
- console.error('Error enabling coordinator:', error);
536
- res.status(500).json({ error: 'Failed to enable coordinator agent' });
537
- }
538
- });
539
- /**
540
- * POST /api/project-groups/:groupId/coordinator/disable
541
- * Disable coordinator agent for a project group
542
- */
543
- coordinatorsRouter.post('/:groupId/coordinator/disable', async (req, res) => {
544
- const userId = req.session.userId;
545
- const groupId = req.params.groupId;
546
- try {
547
- const group = await db.projectGroups.findById(groupId);
548
- if (!group) {
549
- return res.status(404).json({ error: 'Project group not found' });
550
- }
551
- if (group.userId !== userId) {
552
- return res.status(403).json({ error: 'Unauthorized' });
553
- }
554
- // Disable coordinator
555
- const currentConfig = group.coordinatorAgent || { enabled: false };
556
- const updatedConfig = {
557
- ...currentConfig,
558
- enabled: false,
559
- };
560
- await db.projectGroups.updateCoordinatorAgent(groupId, updatedConfig);
561
- // Stop the coordinator agent
562
- const coordinatorService = getCoordinatorService();
563
- await coordinatorService.stop(groupId);
564
- res.json({
565
- success: true,
566
- message: 'Coordinator agent disabled',
567
- coordinator: updatedConfig,
568
- });
569
- }
570
- catch (error) {
571
- console.error('Error disabling coordinator:', error);
572
- res.status(500).json({ error: 'Failed to disable coordinator agent' });
573
- }
574
- });
575
- /**
576
- * GET /api/project-groups/coordinators/active
577
- * List all active coordinators for the user
578
- */
579
- coordinatorsRouter.get('/coordinators/active', async (req, res) => {
580
- const userId = req.session.userId;
581
- try {
582
- // Get all coordinators
583
- const activeCoordinators = await getActiveCoordinators();
584
- // Filter to only user's project groups
585
- const userGroups = await db.projectGroups.findByUserId(userId);
586
- const userGroupIds = new Set(userGroups.map((g) => g.id));
587
- const userCoordinators = activeCoordinators.filter((c) => userGroupIds.has(c.groupId));
588
- res.json({
589
- coordinators: userCoordinators,
590
- });
591
- }
592
- catch (error) {
593
- console.error('Error listing active coordinators:', error);
594
- res.status(500).json({ error: 'Failed to list coordinators' });
595
- }
596
- });
597
- /**
598
- * POST /api/project-groups/:groupId/coordinator/message
599
- * Send a message from coordinator to a specific workspace/agent
600
- */
601
- coordinatorsRouter.post('/:groupId/coordinator/message', async (req, res) => {
602
- const userId = req.session.userId;
603
- const groupId = req.params.groupId;
604
- const { workspaceId, agentName, message, thread } = req.body;
605
- if (!workspaceId || !agentName || !message) {
606
- return res.status(400).json({
607
- error: 'workspaceId, agentName, and message are required',
608
- });
609
- }
610
- try {
611
- const group = await db.projectGroups.findById(groupId);
612
- if (!group) {
613
- return res.status(404).json({ error: 'Project group not found' });
614
- }
615
- if (group.userId !== userId) {
616
- return res.status(403).json({ error: 'Unauthorized' });
617
- }
618
- if (!group.coordinatorAgent?.enabled) {
619
- return res.status(400).json({ error: 'Coordinator is not enabled' });
620
- }
621
- await sendToWorkspace(groupId, workspaceId, agentName, message, thread);
622
- res.json({
623
- success: true,
624
- message: 'Message sent',
625
- });
626
- }
627
- catch (error) {
628
- console.error('Error sending coordinator message:', error);
629
- res.status(500).json({ error: 'Failed to send message' });
630
- }
631
- });
632
- /**
633
- * POST /api/project-groups/:groupId/coordinator/broadcast
634
- * Broadcast a message from coordinator to all workspaces in the group
635
- */
636
- coordinatorsRouter.post('/:groupId/coordinator/broadcast', async (req, res) => {
637
- const userId = req.session.userId;
638
- const groupId = req.params.groupId;
639
- const { message, thread } = req.body;
640
- if (!message) {
641
- return res.status(400).json({ error: 'message is required' });
642
- }
643
- try {
644
- const group = await db.projectGroups.findById(groupId);
645
- if (!group) {
646
- return res.status(404).json({ error: 'Project group not found' });
647
- }
648
- if (group.userId !== userId) {
649
- return res.status(403).json({ error: 'Unauthorized' });
650
- }
651
- if (!group.coordinatorAgent?.enabled) {
652
- return res.status(400).json({ error: 'Coordinator is not enabled' });
653
- }
654
- await broadcastToGroup(groupId, message, thread);
655
- res.json({
656
- success: true,
657
- message: 'Broadcast sent',
658
- });
659
- }
660
- catch (error) {
661
- console.error('Error broadcasting coordinator message:', error);
662
- res.status(500).json({ error: 'Failed to broadcast message' });
663
- }
664
- });
665
- /**
666
- * POST /api/project-groups/coordinator/route
667
- * Route a message from a workspace to its coordinator
668
- * (Called by workspace daemons)
669
- */
670
- coordinatorsRouter.post('/coordinator/route', async (req, res) => {
671
- const { workspaceId, agentName, message, thread } = req.body;
672
- if (!workspaceId || !agentName || !message) {
673
- return res.status(400).json({
674
- error: 'workspaceId, agentName, and message are required',
675
- });
676
- }
677
- try {
678
- // Verify workspace exists and get its owner
679
- const workspace = await db.workspaces.findById(workspaceId);
680
- if (!workspace) {
681
- return res.status(404).json({ error: 'Workspace not found' });
682
- }
683
- await routeToCoordinator(workspaceId, agentName, message, thread);
684
- res.json({
685
- success: true,
686
- message: 'Message routed to coordinator',
687
- });
688
- }
689
- catch (error) {
690
- console.error('Error routing to coordinator:', error);
691
- res.status(500).json({ error: 'Failed to route message' });
692
- }
693
- });
694
- /**
695
- * GET /api/project-groups/:groupId/coordinator/status
696
- * Get detailed coordinator status including connected workspaces
697
- */
698
- coordinatorsRouter.get('/:groupId/coordinator/status', async (req, res) => {
699
- const userId = req.session.userId;
700
- const groupId = req.params.groupId;
701
- try {
702
- const group = await db.projectGroups.findById(groupId);
703
- if (!group) {
704
- return res.status(404).json({ error: 'Project group not found' });
705
- }
706
- if (group.userId !== userId) {
707
- return res.status(403).json({ error: 'Unauthorized' });
708
- }
709
- const coordinatorService = getCoordinatorService();
710
- const status = await coordinatorService.getStatus(groupId);
711
- // Get connected workspaces info
712
- const repositories = await db.repositories.findByProjectGroupId(groupId);
713
- const workspaceIds = new Set();
714
- for (const repo of repositories) {
715
- if (repo.workspaceId) {
716
- workspaceIds.add(repo.workspaceId);
717
- }
718
- }
719
- const workspaces = await Promise.all(Array.from(workspaceIds).map(async (id) => {
720
- const ws = await db.workspaces.findById(id);
721
- return ws
722
- ? {
723
- id: ws.id,
724
- name: ws.name,
725
- status: ws.status,
726
- publicUrl: ws.publicUrl,
727
- }
728
- : null;
729
- }));
730
- res.json({
731
- groupId,
732
- groupName: group.name,
733
- coordinator: {
734
- enabled: group.coordinatorAgent?.enabled || false,
735
- name: group.coordinatorAgent?.name,
736
- model: group.coordinatorAgent?.model,
737
- status: status?.status || 'stopped',
738
- startedAt: status?.startedAt,
739
- error: status?.error,
740
- },
741
- workspaces: workspaces.filter(Boolean),
742
- repositoryCount: repositories.length,
743
- });
744
- }
745
- catch (error) {
746
- console.error('Error getting coordinator status:', error);
747
- res.status(500).json({ error: 'Failed to get coordinator status' });
748
- }
749
- });
750
- //# sourceMappingURL=coordinators.js.map