@generacy-ai/generacy 0.0.0-preview-20260304013206

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 (244) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +207 -0
  3. package/bin/generacy.js +11 -0
  4. package/dist/agency/index.d.ts +68 -0
  5. package/dist/agency/index.d.ts.map +1 -0
  6. package/dist/agency/index.js +28 -0
  7. package/dist/agency/index.js.map +1 -0
  8. package/dist/agency/network.d.ts +41 -0
  9. package/dist/agency/network.d.ts.map +1 -0
  10. package/dist/agency/network.js +133 -0
  11. package/dist/agency/network.js.map +1 -0
  12. package/dist/agency/subprocess.d.ts +58 -0
  13. package/dist/agency/subprocess.d.ts.map +1 -0
  14. package/dist/agency/subprocess.js +216 -0
  15. package/dist/agency/subprocess.js.map +1 -0
  16. package/dist/cli/commands/agent.d.ts +10 -0
  17. package/dist/cli/commands/agent.d.ts.map +1 -0
  18. package/dist/cli/commands/agent.js +216 -0
  19. package/dist/cli/commands/agent.js.map +1 -0
  20. package/dist/cli/commands/doctor/checks/agency-mcp.d.ts +3 -0
  21. package/dist/cli/commands/doctor/checks/agency-mcp.d.ts.map +1 -0
  22. package/dist/cli/commands/doctor/checks/agency-mcp.js +51 -0
  23. package/dist/cli/commands/doctor/checks/agency-mcp.js.map +1 -0
  24. package/dist/cli/commands/doctor/checks/anthropic-key.d.ts +3 -0
  25. package/dist/cli/commands/doctor/checks/anthropic-key.d.ts.map +1 -0
  26. package/dist/cli/commands/doctor/checks/anthropic-key.js +68 -0
  27. package/dist/cli/commands/doctor/checks/anthropic-key.js.map +1 -0
  28. package/dist/cli/commands/doctor/checks/config.d.ts +3 -0
  29. package/dist/cli/commands/doctor/checks/config.d.ts.map +1 -0
  30. package/dist/cli/commands/doctor/checks/config.js +81 -0
  31. package/dist/cli/commands/doctor/checks/config.js.map +1 -0
  32. package/dist/cli/commands/doctor/checks/devcontainer.d.ts +3 -0
  33. package/dist/cli/commands/doctor/checks/devcontainer.d.ts.map +1 -0
  34. package/dist/cli/commands/doctor/checks/devcontainer.js +58 -0
  35. package/dist/cli/commands/doctor/checks/devcontainer.js.map +1 -0
  36. package/dist/cli/commands/doctor/checks/docker.d.ts +3 -0
  37. package/dist/cli/commands/doctor/checks/docker.d.ts.map +1 -0
  38. package/dist/cli/commands/doctor/checks/docker.js +71 -0
  39. package/dist/cli/commands/doctor/checks/docker.js.map +1 -0
  40. package/dist/cli/commands/doctor/checks/env-file.d.ts +3 -0
  41. package/dist/cli/commands/doctor/checks/env-file.d.ts.map +1 -0
  42. package/dist/cli/commands/doctor/checks/env-file.js +56 -0
  43. package/dist/cli/commands/doctor/checks/env-file.js.map +1 -0
  44. package/dist/cli/commands/doctor/checks/github-token.d.ts +3 -0
  45. package/dist/cli/commands/doctor/checks/github-token.d.ts.map +1 -0
  46. package/dist/cli/commands/doctor/checks/github-token.js +99 -0
  47. package/dist/cli/commands/doctor/checks/github-token.js.map +1 -0
  48. package/dist/cli/commands/doctor/checks/npm-packages.d.ts +3 -0
  49. package/dist/cli/commands/doctor/checks/npm-packages.d.ts.map +1 -0
  50. package/dist/cli/commands/doctor/checks/npm-packages.js +117 -0
  51. package/dist/cli/commands/doctor/checks/npm-packages.js.map +1 -0
  52. package/dist/cli/commands/doctor/formatter.d.ts +27 -0
  53. package/dist/cli/commands/doctor/formatter.d.ts.map +1 -0
  54. package/dist/cli/commands/doctor/formatter.js +162 -0
  55. package/dist/cli/commands/doctor/formatter.js.map +1 -0
  56. package/dist/cli/commands/doctor/index.d.ts +5 -0
  57. package/dist/cli/commands/doctor/index.d.ts.map +1 -0
  58. package/dist/cli/commands/doctor/index.js +8 -0
  59. package/dist/cli/commands/doctor/index.js.map +1 -0
  60. package/dist/cli/commands/doctor/registry.d.ts +48 -0
  61. package/dist/cli/commands/doctor/registry.d.ts.map +1 -0
  62. package/dist/cli/commands/doctor/registry.js +166 -0
  63. package/dist/cli/commands/doctor/registry.js.map +1 -0
  64. package/dist/cli/commands/doctor/runner.d.ts +14 -0
  65. package/dist/cli/commands/doctor/runner.d.ts.map +1 -0
  66. package/dist/cli/commands/doctor/runner.js +257 -0
  67. package/dist/cli/commands/doctor/runner.js.map +1 -0
  68. package/dist/cli/commands/doctor/types.d.ts +87 -0
  69. package/dist/cli/commands/doctor/types.d.ts.map +1 -0
  70. package/dist/cli/commands/doctor/types.js +2 -0
  71. package/dist/cli/commands/doctor/types.js.map +1 -0
  72. package/dist/cli/commands/doctor.d.ts +12 -0
  73. package/dist/cli/commands/doctor.d.ts.map +1 -0
  74. package/dist/cli/commands/doctor.js +97 -0
  75. package/dist/cli/commands/doctor.js.map +1 -0
  76. package/dist/cli/commands/init/conflicts.d.ts +36 -0
  77. package/dist/cli/commands/init/conflicts.d.ts.map +1 -0
  78. package/dist/cli/commands/init/conflicts.js +165 -0
  79. package/dist/cli/commands/init/conflicts.js.map +1 -0
  80. package/dist/cli/commands/init/github.d.ts +32 -0
  81. package/dist/cli/commands/init/github.d.ts.map +1 -0
  82. package/dist/cli/commands/init/github.js +161 -0
  83. package/dist/cli/commands/init/github.js.map +1 -0
  84. package/dist/cli/commands/init/index.d.ts +21 -0
  85. package/dist/cli/commands/init/index.d.ts.map +1 -0
  86. package/dist/cli/commands/init/index.js +175 -0
  87. package/dist/cli/commands/init/index.js.map +1 -0
  88. package/dist/cli/commands/init/prompts.d.ts +15 -0
  89. package/dist/cli/commands/init/prompts.d.ts.map +1 -0
  90. package/dist/cli/commands/init/prompts.js +281 -0
  91. package/dist/cli/commands/init/prompts.js.map +1 -0
  92. package/dist/cli/commands/init/repo-utils.d.ts +32 -0
  93. package/dist/cli/commands/init/repo-utils.d.ts.map +1 -0
  94. package/dist/cli/commands/init/repo-utils.js +112 -0
  95. package/dist/cli/commands/init/repo-utils.js.map +1 -0
  96. package/dist/cli/commands/init/resolver.d.ts +20 -0
  97. package/dist/cli/commands/init/resolver.d.ts.map +1 -0
  98. package/dist/cli/commands/init/resolver.js +273 -0
  99. package/dist/cli/commands/init/resolver.js.map +1 -0
  100. package/dist/cli/commands/init/summary.d.ts +21 -0
  101. package/dist/cli/commands/init/summary.d.ts.map +1 -0
  102. package/dist/cli/commands/init/summary.js +100 -0
  103. package/dist/cli/commands/init/summary.js.map +1 -0
  104. package/dist/cli/commands/init/types.d.ts +53 -0
  105. package/dist/cli/commands/init/types.d.ts.map +1 -0
  106. package/dist/cli/commands/init/types.js +2 -0
  107. package/dist/cli/commands/init/types.js.map +1 -0
  108. package/dist/cli/commands/init/writer.d.ts +22 -0
  109. package/dist/cli/commands/init/writer.d.ts.map +1 -0
  110. package/dist/cli/commands/init/writer.js +96 -0
  111. package/dist/cli/commands/init/writer.js.map +1 -0
  112. package/dist/cli/commands/orchestrator.d.ts +11 -0
  113. package/dist/cli/commands/orchestrator.d.ts.map +1 -0
  114. package/dist/cli/commands/orchestrator.js +291 -0
  115. package/dist/cli/commands/orchestrator.js.map +1 -0
  116. package/dist/cli/commands/run.d.ts +10 -0
  117. package/dist/cli/commands/run.d.ts.map +1 -0
  118. package/dist/cli/commands/run.js +167 -0
  119. package/dist/cli/commands/run.js.map +1 -0
  120. package/dist/cli/commands/setup/auth.d.ts +11 -0
  121. package/dist/cli/commands/setup/auth.d.ts.map +1 -0
  122. package/dist/cli/commands/setup/auth.js +108 -0
  123. package/dist/cli/commands/setup/auth.js.map +1 -0
  124. package/dist/cli/commands/setup/build.d.ts +11 -0
  125. package/dist/cli/commands/setup/build.d.ts.map +1 -0
  126. package/dist/cli/commands/setup/build.js +212 -0
  127. package/dist/cli/commands/setup/build.js.map +1 -0
  128. package/dist/cli/commands/setup/services.d.ts +11 -0
  129. package/dist/cli/commands/setup/services.d.ts.map +1 -0
  130. package/dist/cli/commands/setup/services.js +294 -0
  131. package/dist/cli/commands/setup/services.js.map +1 -0
  132. package/dist/cli/commands/setup/workspace.d.ts +11 -0
  133. package/dist/cli/commands/setup/workspace.d.ts.map +1 -0
  134. package/dist/cli/commands/setup/workspace.js +215 -0
  135. package/dist/cli/commands/setup/workspace.js.map +1 -0
  136. package/dist/cli/commands/setup.d.ts +7 -0
  137. package/dist/cli/commands/setup.d.ts.map +1 -0
  138. package/dist/cli/commands/setup.js +19 -0
  139. package/dist/cli/commands/setup.js.map +1 -0
  140. package/dist/cli/commands/validate.d.ts +10 -0
  141. package/dist/cli/commands/validate.d.ts.map +1 -0
  142. package/dist/cli/commands/validate.js +164 -0
  143. package/dist/cli/commands/validate.js.map +1 -0
  144. package/dist/cli/commands/worker.d.ts +10 -0
  145. package/dist/cli/commands/worker.d.ts.map +1 -0
  146. package/dist/cli/commands/worker.js +224 -0
  147. package/dist/cli/commands/worker.js.map +1 -0
  148. package/dist/cli/index.d.ts +14 -0
  149. package/dist/cli/index.d.ts.map +1 -0
  150. package/dist/cli/index.js +68 -0
  151. package/dist/cli/index.js.map +1 -0
  152. package/dist/cli/utils/config.d.ts +49 -0
  153. package/dist/cli/utils/config.d.ts.map +1 -0
  154. package/dist/cli/utils/config.js +110 -0
  155. package/dist/cli/utils/config.js.map +1 -0
  156. package/dist/cli/utils/exec.d.ts +39 -0
  157. package/dist/cli/utils/exec.d.ts.map +1 -0
  158. package/dist/cli/utils/exec.js +68 -0
  159. package/dist/cli/utils/exec.js.map +1 -0
  160. package/dist/cli/utils/logger.d.ts +47 -0
  161. package/dist/cli/utils/logger.d.ts.map +1 -0
  162. package/dist/cli/utils/logger.js +97 -0
  163. package/dist/cli/utils/logger.js.map +1 -0
  164. package/dist/config/index.d.ts +10 -0
  165. package/dist/config/index.d.ts.map +1 -0
  166. package/dist/config/index.js +13 -0
  167. package/dist/config/index.js.map +1 -0
  168. package/dist/config/loader.d.ts +104 -0
  169. package/dist/config/loader.d.ts.map +1 -0
  170. package/dist/config/loader.js +266 -0
  171. package/dist/config/loader.js.map +1 -0
  172. package/dist/config/schema.d.ts +304 -0
  173. package/dist/config/schema.d.ts.map +1 -0
  174. package/dist/config/schema.js +160 -0
  175. package/dist/config/schema.js.map +1 -0
  176. package/dist/config/validator.d.ts +60 -0
  177. package/dist/config/validator.d.ts.map +1 -0
  178. package/dist/config/validator.js +112 -0
  179. package/dist/config/validator.js.map +1 -0
  180. package/dist/health/server.d.ts +47 -0
  181. package/dist/health/server.d.ts.map +1 -0
  182. package/dist/health/server.js +92 -0
  183. package/dist/health/server.js.map +1 -0
  184. package/dist/index.d.ts +21 -0
  185. package/dist/index.d.ts.map +1 -0
  186. package/dist/index.js +22 -0
  187. package/dist/index.js.map +1 -0
  188. package/dist/orchestrator/async-event-queue.d.ts +28 -0
  189. package/dist/orchestrator/async-event-queue.d.ts.map +1 -0
  190. package/dist/orchestrator/async-event-queue.js +57 -0
  191. package/dist/orchestrator/async-event-queue.js.map +1 -0
  192. package/dist/orchestrator/client.d.ts +110 -0
  193. package/dist/orchestrator/client.d.ts.map +1 -0
  194. package/dist/orchestrator/client.js +288 -0
  195. package/dist/orchestrator/client.js.map +1 -0
  196. package/dist/orchestrator/event-bus.d.ts +195 -0
  197. package/dist/orchestrator/event-bus.d.ts.map +1 -0
  198. package/dist/orchestrator/event-bus.js +557 -0
  199. package/dist/orchestrator/event-bus.js.map +1 -0
  200. package/dist/orchestrator/heartbeat.d.ts +71 -0
  201. package/dist/orchestrator/heartbeat.d.ts.map +1 -0
  202. package/dist/orchestrator/heartbeat.js +116 -0
  203. package/dist/orchestrator/heartbeat.js.map +1 -0
  204. package/dist/orchestrator/index.d.ts +25 -0
  205. package/dist/orchestrator/index.d.ts.map +1 -0
  206. package/dist/orchestrator/index.js +15 -0
  207. package/dist/orchestrator/index.js.map +1 -0
  208. package/dist/orchestrator/job-handler.d.ts +109 -0
  209. package/dist/orchestrator/job-handler.d.ts.map +1 -0
  210. package/dist/orchestrator/job-handler.js +612 -0
  211. package/dist/orchestrator/job-handler.js.map +1 -0
  212. package/dist/orchestrator/job-queue.d.ts +81 -0
  213. package/dist/orchestrator/job-queue.d.ts.map +1 -0
  214. package/dist/orchestrator/job-queue.js +206 -0
  215. package/dist/orchestrator/job-queue.js.map +1 -0
  216. package/dist/orchestrator/label-monitor-bridge.d.ts +25 -0
  217. package/dist/orchestrator/label-monitor-bridge.d.ts.map +1 -0
  218. package/dist/orchestrator/label-monitor-bridge.js +57 -0
  219. package/dist/orchestrator/label-monitor-bridge.js.map +1 -0
  220. package/dist/orchestrator/log-buffer.d.ts +74 -0
  221. package/dist/orchestrator/log-buffer.d.ts.map +1 -0
  222. package/dist/orchestrator/log-buffer.js +104 -0
  223. package/dist/orchestrator/log-buffer.js.map +1 -0
  224. package/dist/orchestrator/redis-job-queue.d.ts +44 -0
  225. package/dist/orchestrator/redis-job-queue.d.ts.map +1 -0
  226. package/dist/orchestrator/redis-job-queue.js +300 -0
  227. package/dist/orchestrator/redis-job-queue.js.map +1 -0
  228. package/dist/orchestrator/router.d.ts +125 -0
  229. package/dist/orchestrator/router.d.ts.map +1 -0
  230. package/dist/orchestrator/router.js +143 -0
  231. package/dist/orchestrator/router.js.map +1 -0
  232. package/dist/orchestrator/server.d.ts +62 -0
  233. package/dist/orchestrator/server.d.ts.map +1 -0
  234. package/dist/orchestrator/server.js +711 -0
  235. package/dist/orchestrator/server.js.map +1 -0
  236. package/dist/orchestrator/types.d.ts +184 -0
  237. package/dist/orchestrator/types.d.ts.map +1 -0
  238. package/dist/orchestrator/types.js +6 -0
  239. package/dist/orchestrator/types.js.map +1 -0
  240. package/dist/orchestrator/worker-registry.d.ts +110 -0
  241. package/dist/orchestrator/worker-registry.d.ts.map +1 -0
  242. package/dist/orchestrator/worker-registry.js +191 -0
  243. package/dist/orchestrator/worker-registry.js.map +1 -0
  244. package/package.json +80 -0
@@ -0,0 +1,288 @@
1
+ /**
2
+ * REST client for orchestrator communication
3
+ */
4
+ export class OrchestratorClient {
5
+ baseUrl;
6
+ timeout;
7
+ authToken;
8
+ customHeaders;
9
+ constructor(options) {
10
+ this.baseUrl = options.baseUrl.replace(/\/$/, ''); // Remove trailing slash
11
+ this.timeout = options.timeout ?? 30000;
12
+ this.authToken = options.authToken ?? process.env['ORCHESTRATOR_TOKEN'];
13
+ this.customHeaders = options.headers ?? {};
14
+ }
15
+ /**
16
+ * Make an HTTP request to the orchestrator
17
+ */
18
+ async request(method, path, body) {
19
+ const url = `${this.baseUrl}${path}`;
20
+ const controller = new AbortController();
21
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
22
+ try {
23
+ const headers = {
24
+ 'Content-Type': 'application/json',
25
+ ...this.customHeaders,
26
+ };
27
+ if (this.authToken) {
28
+ headers['Authorization'] = `Bearer ${this.authToken}`;
29
+ }
30
+ const response = await fetch(url, {
31
+ method,
32
+ headers,
33
+ body: body ? JSON.stringify(body) : undefined,
34
+ signal: controller.signal,
35
+ });
36
+ if (!response.ok) {
37
+ let errorData;
38
+ try {
39
+ const body = await response.json();
40
+ // Server wraps errors as { error: { code, message } }
41
+ const inner = (body['error'] ?? body);
42
+ errorData = {
43
+ code: inner.code ?? 'UNKNOWN_ERROR',
44
+ message: inner.message ?? response.statusText,
45
+ details: inner.details,
46
+ };
47
+ }
48
+ catch {
49
+ errorData = {
50
+ code: 'UNKNOWN_ERROR',
51
+ message: response.statusText,
52
+ };
53
+ }
54
+ throw new OrchestratorClientError(errorData.message, errorData.code, response.status, errorData.details);
55
+ }
56
+ // Handle empty responses
57
+ const text = await response.text();
58
+ if (!text) {
59
+ return {};
60
+ }
61
+ return JSON.parse(text);
62
+ }
63
+ finally {
64
+ clearTimeout(timeoutId);
65
+ }
66
+ }
67
+ /**
68
+ * Register worker with orchestrator
69
+ */
70
+ async register(registration) {
71
+ return this.request('POST', '/api/workers/register', registration);
72
+ }
73
+ /**
74
+ * Unregister worker from orchestrator
75
+ */
76
+ async unregister(workerId) {
77
+ await this.request('DELETE', `/api/workers/${workerId}`);
78
+ }
79
+ /**
80
+ * Send heartbeat to orchestrator
81
+ */
82
+ async heartbeat(data) {
83
+ return this.request('POST', `/api/workers/${data.workerId}/heartbeat`, data);
84
+ }
85
+ /**
86
+ * Poll for available jobs
87
+ */
88
+ async pollForJob(workerId, capabilities) {
89
+ const params = new URLSearchParams();
90
+ params.set('workerId', workerId);
91
+ if (capabilities && capabilities.length > 0) {
92
+ params.set('capabilities', capabilities.join(','));
93
+ }
94
+ return this.request('GET', `/api/jobs/poll?${params.toString()}`);
95
+ }
96
+ /**
97
+ * Update job status
98
+ */
99
+ async updateJobStatus(jobId, status, metadata) {
100
+ await this.request('PUT', `/api/jobs/${jobId}/status`, { status, ...metadata });
101
+ }
102
+ /**
103
+ * Report job result
104
+ */
105
+ async reportJobResult(result) {
106
+ await this.request('POST', `/api/jobs/${result.jobId}/result`, result);
107
+ }
108
+ /**
109
+ * Get job details
110
+ */
111
+ async getJob(jobId) {
112
+ return this.request('GET', `/api/jobs/${jobId}`);
113
+ }
114
+ /**
115
+ * Cancel a job
116
+ */
117
+ async cancelJob(jobId, reason) {
118
+ await this.request('POST', `/api/jobs/${jobId}/cancel`, { reason });
119
+ }
120
+ /**
121
+ * Publish an event for a job
122
+ */
123
+ async publishEvent(jobId, event) {
124
+ return this.request('POST', `/api/jobs/${jobId}/events`, event);
125
+ }
126
+ /**
127
+ * Subscribe to SSE events for a specific job.
128
+ * Returns an AsyncIterable that yields parsed JobEvent objects.
129
+ * The stream can be cancelled via AbortSignal or by breaking out of the for-await loop.
130
+ */
131
+ async *subscribeEvents(jobId, options) {
132
+ const url = `${this.baseUrl}/api/jobs/${jobId}/events`;
133
+ const headers = {
134
+ ...this.customHeaders,
135
+ };
136
+ if (this.authToken) {
137
+ headers['Authorization'] = `Bearer ${this.authToken}`;
138
+ }
139
+ if (options?.lastEventId) {
140
+ headers['Last-Event-ID'] = options.lastEventId;
141
+ }
142
+ const response = await fetch(url, {
143
+ headers,
144
+ signal: options?.signal,
145
+ });
146
+ if (!response.ok) {
147
+ let errorData;
148
+ try {
149
+ errorData = await response.json();
150
+ }
151
+ catch {
152
+ errorData = {
153
+ code: 'UNKNOWN_ERROR',
154
+ message: response.statusText,
155
+ };
156
+ }
157
+ throw new OrchestratorClientError(errorData.message, errorData.code, response.status, errorData.details);
158
+ }
159
+ yield* this.parseSSEStream(response, options?.signal);
160
+ }
161
+ /**
162
+ * Subscribe to SSE events for all jobs, optionally filtered.
163
+ * Returns an AsyncIterable that yields parsed JobEvent objects.
164
+ * The stream can be cancelled via AbortSignal or by breaking out of the for-await loop.
165
+ */
166
+ async *subscribeAllEvents(options) {
167
+ // Build query string from filters
168
+ const params = new URLSearchParams();
169
+ if (options?.filters?.tags && options.filters.tags.length > 0) {
170
+ params.set('tags', options.filters.tags.join(','));
171
+ }
172
+ if (options?.filters?.workflow) {
173
+ params.set('workflow', options.filters.workflow);
174
+ }
175
+ if (options?.filters?.status && options.filters.status.length > 0) {
176
+ params.set('status', options.filters.status.join(','));
177
+ }
178
+ const queryString = params.toString();
179
+ const url = `${this.baseUrl}/api/events${queryString ? `?${queryString}` : ''}`;
180
+ const headers = {
181
+ ...this.customHeaders,
182
+ };
183
+ if (this.authToken) {
184
+ headers['Authorization'] = `Bearer ${this.authToken}`;
185
+ }
186
+ if (options?.lastEventId) {
187
+ headers['Last-Event-ID'] = options.lastEventId;
188
+ }
189
+ const response = await fetch(url, {
190
+ headers,
191
+ signal: options?.signal,
192
+ });
193
+ if (!response.ok) {
194
+ let errorData;
195
+ try {
196
+ errorData = await response.json();
197
+ }
198
+ catch {
199
+ errorData = {
200
+ code: 'UNKNOWN_ERROR',
201
+ message: response.statusText,
202
+ };
203
+ }
204
+ throw new OrchestratorClientError(errorData.message, errorData.code, response.status, errorData.details);
205
+ }
206
+ yield* this.parseSSEStream(response, options?.signal);
207
+ }
208
+ /**
209
+ * Parse an SSE response stream into JobEvent objects.
210
+ * Handles `event:`, `id:`, `data:` fields and skips comment lines (heartbeats).
211
+ */
212
+ async *parseSSEStream(response, signal) {
213
+ const body = response.body;
214
+ if (!body)
215
+ return;
216
+ const reader = body.getReader();
217
+ const decoder = new TextDecoder();
218
+ let buffer = '';
219
+ let currentData = '';
220
+ // event and id fields tracked for completeness but data carries the full JobEvent
221
+ let _currentEvent = '';
222
+ let _currentId = '';
223
+ try {
224
+ while (true) {
225
+ if (signal?.aborted)
226
+ break;
227
+ const { done, value } = await reader.read();
228
+ if (done)
229
+ break;
230
+ buffer += decoder.decode(value, { stream: true });
231
+ // Process complete lines
232
+ const lines = buffer.split('\n');
233
+ // Keep the last potentially incomplete line in the buffer
234
+ buffer = lines.pop() ?? '';
235
+ for (const line of lines) {
236
+ if (line === '') {
237
+ // Empty line = end of event block — dispatch if we have data
238
+ if (currentData) {
239
+ try {
240
+ const event = JSON.parse(currentData);
241
+ yield event;
242
+ }
243
+ catch {
244
+ // Malformed data, skip
245
+ }
246
+ }
247
+ // Reset fields for next event
248
+ currentData = '';
249
+ _currentEvent = '';
250
+ _currentId = '';
251
+ }
252
+ else if (line.startsWith(':')) {
253
+ // Comment line (e.g. heartbeat `: ping`) — skip
254
+ }
255
+ else if (line.startsWith('data:')) {
256
+ currentData = line.slice(5).trimStart();
257
+ }
258
+ else if (line.startsWith('event:')) {
259
+ _currentEvent = line.slice(6).trimStart();
260
+ }
261
+ else if (line.startsWith('id:')) {
262
+ _currentId = line.slice(3).trimStart();
263
+ }
264
+ // Other fields (retry:, etc.) are ignored
265
+ }
266
+ }
267
+ }
268
+ finally {
269
+ reader.releaseLock();
270
+ }
271
+ }
272
+ }
273
+ /**
274
+ * Error class for orchestrator client errors
275
+ */
276
+ export class OrchestratorClientError extends Error {
277
+ code;
278
+ statusCode;
279
+ details;
280
+ constructor(message, code, statusCode, details) {
281
+ super(message);
282
+ this.code = code;
283
+ this.statusCode = statusCode;
284
+ this.details = details;
285
+ this.name = 'OrchestratorClientError';
286
+ }
287
+ }
288
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/orchestrator/client.ts"],"names":[],"mappings":"AAkCA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,SAAS,CAAU;IACnB,aAAa,C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,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;oBAC5C,CAAC;yBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;wBAClC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;oBACzC,CAAC;oBACD,0CAA0C;gBAC5C,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAG9B;IACA;IACA;IAJlB,YACE,OAAe,EACC,IAAY,EACZ,UAAkB,EAClB,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAQ;QAClB,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * EventBus module for SSE event buffering and broadcasting.
3
+ */
4
+ import type { ServerResponse } from 'node:http';
5
+ import type { JobEvent, EventFilters } from './types.js';
6
+ import type { JobQueue } from './job-queue.js';
7
+ import type { LogBufferManager } from './log-buffer.js';
8
+ /**
9
+ * A fixed-capacity circular buffer that evicts oldest items when full.
10
+ *
11
+ * Tracks a `baseIndex` representing the total number of items ever evicted,
12
+ * so callers can map external IDs (like monotonic counters) to buffer positions.
13
+ */
14
+ export declare class RingBuffer<T> {
15
+ private readonly _capacity;
16
+ private readonly buffer;
17
+ private head;
18
+ private _size;
19
+ private _baseIndex;
20
+ constructor(capacity?: number);
21
+ /** Number of items currently in the buffer. */
22
+ get size(): number;
23
+ /** Maximum number of items the buffer can hold. */
24
+ get capacity(): number;
25
+ /**
26
+ * The number of items that have been evicted over the buffer's lifetime.
27
+ * An item inserted at logical index N is at buffer position (N - baseIndex).
28
+ */
29
+ get baseIndex(): number;
30
+ /**
31
+ * Push an item into the buffer. O(1).
32
+ * When the buffer is full the oldest item is evicted.
33
+ */
34
+ push(item: T): void;
35
+ /**
36
+ * Return all buffered items in insertion order.
37
+ */
38
+ getAll(): T[];
39
+ /**
40
+ * Return all items whose logical index is strictly greater than `startIndex`.
41
+ *
42
+ * Logical index = baseIndex + position-in-current-buffer.
43
+ * The first item currently in the buffer has logical index `baseIndex`,
44
+ * the second has `baseIndex + 1`, etc.
45
+ *
46
+ * If `startIndex` is before the buffer's range (i.e. already evicted),
47
+ * all buffered items are returned.
48
+ */
49
+ getAfterIndex(startIndex: number): T[];
50
+ /**
51
+ * Remove all items and reset state.
52
+ */
53
+ clear(): void;
54
+ }
55
+ /**
56
+ * Configuration options for the EventBus.
57
+ */
58
+ export interface EventBusOptions {
59
+ /** Per-job ring buffer capacity (default: 1000) */
60
+ bufferSize?: number;
61
+ /** Milliseconds to keep buffers after a job reaches terminal state (default: 300000 / 5 min) */
62
+ gracePeriod?: number;
63
+ /** Milliseconds between SSE heartbeat pings (default: 30000 / 30s) */
64
+ heartbeatInterval?: number;
65
+ /** Job queue used for filter evaluation on global subscribers */
66
+ jobQueue: JobQueue;
67
+ /** Optional LogBufferManager for routing log:append events to a separate buffer */
68
+ logBufferManager?: LogBufferManager;
69
+ /** Optional logger */
70
+ logger?: {
71
+ info: (message: string, data?: Record<string, unknown>) => void;
72
+ warn: (message: string, data?: Record<string, unknown>) => void;
73
+ error: (message: string, data?: Record<string, unknown>) => void;
74
+ };
75
+ }
76
+ /**
77
+ * EventBus handles event buffering (per-job ring buffers) and broadcasting
78
+ * to SSE subscribers. It is the core publish/subscribe component for
79
+ * real-time job event streaming.
80
+ */
81
+ export declare class EventBus {
82
+ /** Per-job ring buffers */
83
+ private readonly buffers;
84
+ /** Per-job monotonic ID counters */
85
+ private readonly counters;
86
+ /** Per-job SSE subscriber connections */
87
+ private readonly subscribers;
88
+ /** Global SSE subscriber connections with filters */
89
+ private readonly globalSubscribers;
90
+ /** Grace period cleanup timers for terminal jobs */
91
+ private readonly cleanupTimers;
92
+ private readonly bufferSize;
93
+ private readonly gracePeriod;
94
+ private readonly heartbeatInterval;
95
+ private readonly jobQueue;
96
+ private readonly logBufferManager?;
97
+ private readonly logger?;
98
+ private heartbeatTimer;
99
+ constructor(options: EventBusOptions);
100
+ /**
101
+ * Publish an event for a job.
102
+ *
103
+ * Assigns a monotonic string ID, buffers the event in the job's ring buffer,
104
+ * and broadcasts to all per-job and matching global subscribers.
105
+ *
106
+ * Global subscribers are filtered by looking up the job's current metadata
107
+ * from the job queue. Filters combine with AND logic:
108
+ * - `tags`: job must have at least one matching tag
109
+ * - `workflow`: job's workflow must match (string comparison)
110
+ * - `status`: job's current status must be in the filter list
111
+ */
112
+ publish(jobId: string, event: Omit<JobEvent, 'id'>): Promise<JobEvent>;
113
+ /**
114
+ * Subscribe to a single job's event stream.
115
+ *
116
+ * If `lastEventId` is provided, replays buffered events after that ID
117
+ * before switching to live mode. If the ID is not found in the buffer,
118
+ * all buffered events are replayed.
119
+ *
120
+ * Automatically unsubscribes when the response connection closes.
121
+ */
122
+ subscribe(jobId: string, res: ServerResponse, lastEventId?: string): void;
123
+ /**
124
+ * Subscribe to events from all jobs, optionally filtered.
125
+ *
126
+ * If `lastEventId` is provided (format `{jobId}:{counter}`), replays
127
+ * buffered events after that ID from the specified job's buffer, then
128
+ * replays all buffered events from other jobs' buffers (filtered).
129
+ *
130
+ * Filter matching is applied during replay: only events from jobs that
131
+ * match the subscriber's filters are sent.
132
+ */
133
+ subscribeAll(res: ServerResponse, filters: EventFilters, lastEventId?: string): Promise<void>;
134
+ /**
135
+ * Remove a response from all subscriber sets (per-job and global).
136
+ */
137
+ unsubscribe(res: ServerResponse): void;
138
+ /**
139
+ * Schedule cleanup of a job's buffers and subscriber data after the grace period.
140
+ */
141
+ scheduleCleanup(jobId: string): void;
142
+ /**
143
+ * Close all per-job SSE connections for a job.
144
+ * Sends `res.end()` to each subscriber and removes them from the set.
145
+ */
146
+ closeJobSubscribers(jobId: string): void;
147
+ /**
148
+ * Return all buffered events for a job (for replay-and-close on terminal jobs).
149
+ */
150
+ getBufferedEvents(jobId: string): JobEvent[];
151
+ /**
152
+ * Start the heartbeat interval that sends `: ping\n\n` to all active SSE connections.
153
+ */
154
+ startHeartbeat(): void;
155
+ /**
156
+ * Stop the heartbeat interval.
157
+ */
158
+ stopHeartbeat(): void;
159
+ /**
160
+ * Clean shutdown: stop heartbeat, clear all timers, close all connections, clear state.
161
+ */
162
+ destroy(): void;
163
+ /**
164
+ * Replay events from a specific job's buffer after a given counter value,
165
+ * applying filter matching. Returns true if the connection died during replay.
166
+ */
167
+ private replayJobBuffer;
168
+ /**
169
+ * Send a list of events to a global subscriber, applying filter matching.
170
+ * Returns true if the connection died during replay (subscriber was removed).
171
+ */
172
+ private replayEventsFiltered;
173
+ /**
174
+ * Check whether any global subscriber has at least one filter set.
175
+ * Used to skip the async job lookup when no filters are active.
176
+ */
177
+ private anySubscriberHasFilters;
178
+ /**
179
+ * Evaluate whether a job matches a subscriber's filters.
180
+ *
181
+ * All specified filters combine with AND logic:
182
+ * - `tags`: job must have at least one matching tag
183
+ * - `workflow`: job's workflow must match (string comparison)
184
+ * - `status`: job's current status must be in the filter list
185
+ *
186
+ * If no filters are set (all fields undefined/empty), the event always matches.
187
+ * If the job is null (not found), events are skipped for subscribers with filters.
188
+ */
189
+ private matchesFilters;
190
+ /**
191
+ * Internal helper to remove a ServerResponse from all subscriber sets.
192
+ */
193
+ private removeSubscriber;
194
+ }
195
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/orchestrator/event-bus.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAO,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,C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