@agenticmail/enterprise 0.5.207 → 0.5.208

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 (57) hide show
  1. package/dist/agent-heartbeat-2D43IBNA.js +510 -0
  2. package/dist/agent-heartbeat-AYOPPYNS.js +510 -0
  3. package/dist/agent-heartbeat-BLFZHGVH.js +510 -0
  4. package/dist/agent-heartbeat-FITCBARW.js +510 -0
  5. package/dist/chunk-2DJEQCRU.js +4457 -0
  6. package/dist/chunk-6PIWF5AC.js +1224 -0
  7. package/dist/chunk-APRK35OM.js +3685 -0
  8. package/dist/chunk-BTT3P4XP.js +3685 -0
  9. package/dist/chunk-D7SBTNBI.js +1224 -0
  10. package/dist/chunk-FEEHLIWF.js +1224 -0
  11. package/dist/chunk-JBLDCQSK.js +4457 -0
  12. package/dist/chunk-L72IFQCJ.js +1224 -0
  13. package/dist/chunk-LIHFQM2M.js +3685 -0
  14. package/dist/chunk-QVKIYQ5F.js +4494 -0
  15. package/dist/chunk-RTW7WNXZ.js +3685 -0
  16. package/dist/chunk-VBLS4HXF.js +4494 -0
  17. package/dist/chunk-W5MVEM4M.js +3685 -0
  18. package/dist/chunk-WZ4F4SYK.js +292 -0
  19. package/dist/chunk-ZJZ5N4SD.js +4494 -0
  20. package/dist/chunk-ZKSOJILT.js +1224 -0
  21. package/dist/cli-agent-ILMIH4Z4.js +1602 -0
  22. package/dist/cli-agent-MRGC2WFN.js +1602 -0
  23. package/dist/cli-agent-ND6P7N2G.js +1719 -0
  24. package/dist/cli-agent-OTZ6INTM.js +1602 -0
  25. package/dist/cli-agent-OXSEQWTQ.js +1602 -0
  26. package/dist/cli-serve-3M2FUSYX.js +114 -0
  27. package/dist/cli-serve-A4DRJBGH.js +114 -0
  28. package/dist/cli-serve-ASW2VFVZ.js +114 -0
  29. package/dist/cli-serve-MJSIZKOG.js +114 -0
  30. package/dist/cli-serve-V7JBBESA.js +114 -0
  31. package/dist/cli.js +3 -3
  32. package/dist/index.js +3 -3
  33. package/dist/routes-AAXSMKBT.js +13032 -0
  34. package/dist/routes-EZVM3AQW.js +13281 -0
  35. package/dist/routes-I7Z57PKK.js +13283 -0
  36. package/dist/routes-RGYOWZA6.js +13282 -0
  37. package/dist/runtime-CMOHWZTC.js +45 -0
  38. package/dist/runtime-DIE72WMW.js +45 -0
  39. package/dist/runtime-DVDGBQKF.js +45 -0
  40. package/dist/runtime-HWQ5ZXD3.js +45 -0
  41. package/dist/runtime-LRKG2KTN.js +45 -0
  42. package/dist/server-6L3RFC42.js +15 -0
  43. package/dist/server-7P67XIXT.js +15 -0
  44. package/dist/server-AB6BBV2H.js +15 -0
  45. package/dist/server-D2ZZ44LL.js +15 -0
  46. package/dist/server-UC23ZQIO.js +15 -0
  47. package/dist/setup-6UB3FST3.js +20 -0
  48. package/dist/setup-BW5BWSG2.js +20 -0
  49. package/dist/setup-KXN6MGWO.js +20 -0
  50. package/dist/setup-SZK7GYJE.js +20 -0
  51. package/dist/setup-X6CIHPCV.js +20 -0
  52. package/package.json +1 -1
  53. package/src/cli-agent.ts +43 -0
  54. package/src/engine/agent-routes.ts +32 -2
  55. package/src/engine/messaging-poller.ts +17 -1
  56. package/src/engine/routes.ts +2 -1
  57. package/src/runtime/gateway.ts +0 -45
@@ -0,0 +1,292 @@
1
+ // src/engine/task-queue.ts
2
+ import { randomUUID } from "crypto";
3
+ var TaskQueueManager = class {
4
+ tasks = /* @__PURE__ */ new Map();
5
+ listeners = /* @__PURE__ */ new Set();
6
+ db;
7
+ initialized = false;
8
+ constructor(db) {
9
+ this.db = db;
10
+ }
11
+ async init() {
12
+ if (this.initialized) return;
13
+ if (this.db) {
14
+ try {
15
+ await this.db.run(`CREATE TABLE IF NOT EXISTS task_pipeline (
16
+ id TEXT PRIMARY KEY,
17
+ org_id TEXT NOT NULL,
18
+ assigned_to TEXT NOT NULL,
19
+ assigned_to_name TEXT NOT NULL DEFAULT '',
20
+ created_by TEXT NOT NULL DEFAULT 'system',
21
+ created_by_name TEXT NOT NULL DEFAULT '',
22
+ title TEXT NOT NULL,
23
+ description TEXT NOT NULL DEFAULT '',
24
+ category TEXT NOT NULL DEFAULT 'custom',
25
+ tags TEXT NOT NULL DEFAULT '[]',
26
+ status TEXT NOT NULL DEFAULT 'created',
27
+ priority TEXT NOT NULL DEFAULT 'normal',
28
+ progress INTEGER NOT NULL DEFAULT 0,
29
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
30
+ assigned_at TEXT,
31
+ started_at TEXT,
32
+ completed_at TEXT,
33
+ estimated_duration_ms INTEGER,
34
+ actual_duration_ms INTEGER,
35
+ result TEXT,
36
+ error TEXT,
37
+ parent_task_id TEXT,
38
+ related_agent_ids TEXT NOT NULL DEFAULT '[]',
39
+ session_id TEXT,
40
+ model TEXT,
41
+ fallback_model TEXT,
42
+ model_used TEXT,
43
+ tokens_used INTEGER NOT NULL DEFAULT 0,
44
+ cost_usd REAL NOT NULL DEFAULT 0
45
+ )`);
46
+ await this.db.run(`CREATE INDEX IF NOT EXISTS idx_task_pipeline_org ON task_pipeline(org_id)`);
47
+ await this.db.run(`CREATE INDEX IF NOT EXISTS idx_task_pipeline_agent ON task_pipeline(assigned_to)`);
48
+ await this.db.run(`CREATE INDEX IF NOT EXISTS idx_task_pipeline_status ON task_pipeline(status)`);
49
+ await this.db.run(`CREATE INDEX IF NOT EXISTS idx_task_pipeline_created ON task_pipeline(created_at)`);
50
+ const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1e3).toISOString();
51
+ const rows = await this.db.all(`SELECT * FROM task_pipeline WHERE status IN ('created','assigned','in_progress') OR created_at > ? ORDER BY created_at DESC LIMIT 500`, [cutoff]);
52
+ for (const row of rows || []) {
53
+ this.tasks.set(row.id, this.rowToTask(row));
54
+ }
55
+ } catch (e) {
56
+ console.error("[TaskQueue] DB init error:", e.message);
57
+ }
58
+ }
59
+ this.initialized = true;
60
+ }
61
+ // ─── CRUD ─────────────────────────────────────────────
62
+ async createTask(opts) {
63
+ await this.init();
64
+ const now = (/* @__PURE__ */ new Date()).toISOString();
65
+ const task = {
66
+ id: randomUUID(),
67
+ orgId: opts.orgId,
68
+ assignedTo: opts.assignedTo,
69
+ assignedToName: opts.assignedToName,
70
+ createdBy: opts.createdBy || "system",
71
+ createdByName: opts.createdByName || "System",
72
+ title: opts.title,
73
+ description: opts.description || "",
74
+ category: opts.category || "custom",
75
+ tags: opts.tags || [],
76
+ status: "created",
77
+ priority: opts.priority || "normal",
78
+ progress: 0,
79
+ createdAt: now,
80
+ assignedAt: null,
81
+ startedAt: null,
82
+ completedAt: null,
83
+ estimatedDurationMs: opts.estimatedDurationMs || null,
84
+ actualDurationMs: null,
85
+ result: null,
86
+ error: null,
87
+ parentTaskId: opts.parentTaskId || null,
88
+ relatedAgentIds: opts.relatedAgentIds || [],
89
+ sessionId: opts.sessionId || null,
90
+ model: opts.model || null,
91
+ fallbackModel: opts.fallbackModel || null,
92
+ modelUsed: null,
93
+ tokensUsed: 0,
94
+ costUsd: 0
95
+ };
96
+ this.tasks.set(task.id, task);
97
+ await this.persist(task);
98
+ this.emit({ type: "task_created", task, timestamp: now });
99
+ return task;
100
+ }
101
+ async updateTask(taskId, updates) {
102
+ await this.init();
103
+ const task = this.tasks.get(taskId);
104
+ if (!task) return null;
105
+ const now = (/* @__PURE__ */ new Date()).toISOString();
106
+ if (updates.status === "assigned" && !task.assignedAt) task.assignedAt = now;
107
+ if (updates.status === "in_progress" && !task.startedAt) task.startedAt = now;
108
+ if (updates.status === "completed" || updates.status === "failed" || updates.status === "cancelled") {
109
+ task.completedAt = now;
110
+ if (task.startedAt) task.actualDurationMs = new Date(now).getTime() - new Date(task.startedAt).getTime();
111
+ if (updates.status === "completed") task.progress = 100;
112
+ }
113
+ Object.assign(task, updates);
114
+ await this.persist(task);
115
+ const eventType = updates.status === "completed" ? "task_completed" : updates.status === "failed" ? "task_failed" : updates.status === "cancelled" ? "task_cancelled" : updates.progress !== void 0 ? "task_progress" : "task_updated";
116
+ this.emit({ type: eventType, task, timestamp: now });
117
+ return task;
118
+ }
119
+ getTask(taskId) {
120
+ return this.tasks.get(taskId);
121
+ }
122
+ // ─── Queries ──────────────────────────────────────────
123
+ getActiveTasks(orgId) {
124
+ const active = [];
125
+ for (const t of this.tasks.values()) {
126
+ if (t.status === "created" || t.status === "assigned" || t.status === "in_progress") {
127
+ if (!orgId || t.orgId === orgId) active.push(t);
128
+ }
129
+ }
130
+ return active.sort((a, b) => {
131
+ const pri = { urgent: 0, high: 1, normal: 2, low: 3 };
132
+ return pri[a.priority] - pri[b.priority] || new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
133
+ });
134
+ }
135
+ getAllTasks(orgId, limit = 100) {
136
+ const all = [];
137
+ for (const t of this.tasks.values()) {
138
+ if (!orgId || t.orgId === orgId) all.push(t);
139
+ }
140
+ return all.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
141
+ }
142
+ getAgentTasks(agentId, includeCompleted = false) {
143
+ const res = [];
144
+ for (const t of this.tasks.values()) {
145
+ if (t.assignedTo === agentId) {
146
+ if (includeCompleted || t.status === "created" || t.status === "assigned" || t.status === "in_progress") {
147
+ res.push(t);
148
+ }
149
+ }
150
+ }
151
+ return res.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
152
+ }
153
+ async getTaskHistory(orgId, limit = 50, offset = 0) {
154
+ if (this.db) {
155
+ try {
156
+ const rows = await this.db.all(
157
+ `SELECT * FROM task_pipeline WHERE org_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?`,
158
+ [orgId, limit, offset]
159
+ );
160
+ return (rows || []).map((r) => this.rowToTask(r));
161
+ } catch {
162
+ }
163
+ }
164
+ return this.getAllTasks(orgId, limit);
165
+ }
166
+ getPipelineStats(orgId) {
167
+ const stats = { created: 0, assigned: 0, inProgress: 0, completed: 0, failed: 0, cancelled: 0, total: 0 };
168
+ for (const t of this.tasks.values()) {
169
+ if (orgId && t.orgId !== orgId) continue;
170
+ stats.total++;
171
+ if (t.status === "created") stats.created++;
172
+ else if (t.status === "assigned") stats.assigned++;
173
+ else if (t.status === "in_progress") stats.inProgress++;
174
+ else if (t.status === "completed") stats.completed++;
175
+ else if (t.status === "failed") stats.failed++;
176
+ else if (t.status === "cancelled") stats.cancelled++;
177
+ }
178
+ return stats;
179
+ }
180
+ // ─── SSE Subscriptions ────────────────────────────────
181
+ subscribe(listener) {
182
+ this.listeners.add(listener);
183
+ return () => {
184
+ this.listeners.delete(listener);
185
+ };
186
+ }
187
+ emit(event) {
188
+ for (const l of this.listeners) {
189
+ try {
190
+ l(event);
191
+ } catch {
192
+ }
193
+ }
194
+ }
195
+ // ─── Persistence ──────────────────────────────────────
196
+ async persist(task) {
197
+ if (!this.db) return;
198
+ try {
199
+ await this.db.run(`INSERT INTO task_pipeline (
200
+ id, org_id, assigned_to, assigned_to_name, created_by, created_by_name,
201
+ title, description, category, tags, status, priority, progress,
202
+ created_at, assigned_at, started_at, completed_at,
203
+ estimated_duration_ms, actual_duration_ms, result, error,
204
+ parent_task_id, related_agent_ids, session_id,
205
+ model, fallback_model, model_used, tokens_used, cost_usd
206
+ ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
207
+ ON CONFLICT (id) DO UPDATE SET
208
+ status=EXCLUDED.status, priority=EXCLUDED.priority, progress=EXCLUDED.progress,
209
+ assigned_at=EXCLUDED.assigned_at, started_at=EXCLUDED.started_at, completed_at=EXCLUDED.completed_at,
210
+ actual_duration_ms=EXCLUDED.actual_duration_ms, result=EXCLUDED.result, error=EXCLUDED.error,
211
+ model_used=EXCLUDED.model_used, tokens_used=EXCLUDED.tokens_used, cost_usd=EXCLUDED.cost_usd,
212
+ session_id=EXCLUDED.session_id, title=EXCLUDED.title, description=EXCLUDED.description`, [
213
+ task.id,
214
+ task.orgId,
215
+ task.assignedTo,
216
+ task.assignedToName,
217
+ task.createdBy,
218
+ task.createdByName,
219
+ task.title,
220
+ task.description,
221
+ task.category,
222
+ JSON.stringify(task.tags),
223
+ task.status,
224
+ task.priority,
225
+ task.progress,
226
+ task.createdAt,
227
+ task.assignedAt,
228
+ task.startedAt,
229
+ task.completedAt,
230
+ task.estimatedDurationMs,
231
+ task.actualDurationMs,
232
+ task.result ? JSON.stringify(task.result) : null,
233
+ task.error,
234
+ task.parentTaskId,
235
+ JSON.stringify(task.relatedAgentIds),
236
+ task.sessionId,
237
+ task.model,
238
+ task.fallbackModel,
239
+ task.modelUsed,
240
+ task.tokensUsed,
241
+ task.costUsd
242
+ ]);
243
+ } catch (e) {
244
+ console.error("[TaskQueue] persist error:", e.message);
245
+ }
246
+ }
247
+ rowToTask(row) {
248
+ return {
249
+ id: row.id,
250
+ orgId: row.org_id,
251
+ assignedTo: row.assigned_to,
252
+ assignedToName: row.assigned_to_name || "",
253
+ createdBy: row.created_by || "system",
254
+ createdByName: row.created_by_name || "",
255
+ title: row.title,
256
+ description: row.description || "",
257
+ category: row.category || "custom",
258
+ tags: safeJson(row.tags, []),
259
+ status: row.status,
260
+ priority: row.priority || "normal",
261
+ progress: row.progress || 0,
262
+ createdAt: row.created_at,
263
+ assignedAt: row.assigned_at || null,
264
+ startedAt: row.started_at || null,
265
+ completedAt: row.completed_at || null,
266
+ estimatedDurationMs: row.estimated_duration_ms || null,
267
+ actualDurationMs: row.actual_duration_ms || null,
268
+ result: safeJson(row.result, null),
269
+ error: row.error || null,
270
+ parentTaskId: row.parent_task_id || null,
271
+ relatedAgentIds: safeJson(row.related_agent_ids, []),
272
+ sessionId: row.session_id || null,
273
+ model: row.model || null,
274
+ fallbackModel: row.fallback_model || null,
275
+ modelUsed: row.model_used || null,
276
+ tokensUsed: row.tokens_used || 0,
277
+ costUsd: row.cost_usd || 0
278
+ };
279
+ }
280
+ };
281
+ function safeJson(v, fallback) {
282
+ if (!v || typeof v !== "string") return fallback;
283
+ try {
284
+ return JSON.parse(v);
285
+ } catch {
286
+ return fallback;
287
+ }
288
+ }
289
+
290
+ export {
291
+ TaskQueueManager
292
+ };