@agenticmail/enterprise 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +929 -0
- package/dashboards/dotnet/Program.cs +5 -5
- package/dashboards/express/app.js +5 -5
- package/dashboards/go/main.go +8 -8
- package/dashboards/html/index.html +41 -18
- package/dashboards/java/AgenticMailDashboard.java +5 -5
- package/dashboards/php/index.php +8 -8
- package/dashboards/python/app.py +8 -8
- package/dashboards/ruby/app.rb +7 -7
- package/dashboards/shared-styles.css +57 -0
- package/dist/{chunk-LCUZGIDH.js → chunk-BE7MXVLA.js} +48 -256
- package/dist/chunk-BS2WCSHO.js +48 -0
- package/dist/chunk-FL3VQBGL.js +757 -0
- package/dist/chunk-GXIEEA2T.js +48 -0
- package/dist/chunk-JLSQOQ5L.js +255 -0
- package/dist/{chunk-O462UJBH.js → chunk-TVF23PUW.js} +23 -48
- package/dist/{chunk-DXNKR3TG.js → chunk-YFDSE4BW.js} +1 -1
- package/dist/cli.js +305 -140
- package/dist/dashboard/index.html +833 -510
- package/dist/factory-HINWFYZ3.js +9 -0
- package/dist/factory-V37IG5AT.js +9 -0
- package/dist/index.js +18 -12
- package/dist/managed-RZITNPXG.js +14 -0
- package/dist/{server.js → server-32YYCI3A.js} +2 -1
- package/dist/server-H3C6WUOS.js +8 -0
- package/dist/sqlite-VLKVAJA4.js +442 -0
- package/package.json +18 -2
- package/src/cli.ts +15 -251
- package/src/dashboard/index.html +833 -510
- package/src/db/sqlite.ts +4 -1
- package/src/server.ts +1 -1
- package/src/setup/company.ts +64 -0
- package/src/setup/database.ts +119 -0
- package/src/setup/deployment.ts +50 -0
- package/src/setup/domain.ts +46 -0
- package/src/setup/index.ts +82 -0
- package/src/setup/provision.ts +226 -0
- package/test-integration.mjs +383 -0
- package/agenticmail-enterprise.db +0 -0
- package/dist/engine/index.js +0 -1261
- package/dist/routes-74ZLKJKP.js +0 -399
package/dist/routes-74ZLKJKP.js
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ActivityTracker,
|
|
3
|
-
AgentConfigGenerator,
|
|
4
|
-
AgentLifecycleManager,
|
|
5
|
-
ApprovalEngine,
|
|
6
|
-
BUILTIN_SKILLS,
|
|
7
|
-
DeploymentEngine,
|
|
8
|
-
KnowledgeBaseEngine,
|
|
9
|
-
PRESET_PROFILES,
|
|
10
|
-
PermissionEngine,
|
|
11
|
-
TenantManager
|
|
12
|
-
} from "./chunk-N2JVTNNJ.js";
|
|
13
|
-
import "./chunk-PNKVD2UK.js";
|
|
14
|
-
|
|
15
|
-
// src/engine/routes.ts
|
|
16
|
-
import { Hono } from "hono";
|
|
17
|
-
var engine = new Hono();
|
|
18
|
-
var permissionEngine = new PermissionEngine();
|
|
19
|
-
var configGen = new AgentConfigGenerator();
|
|
20
|
-
var deployer = new DeploymentEngine();
|
|
21
|
-
var approvals = new ApprovalEngine();
|
|
22
|
-
var lifecycle = new AgentLifecycleManager({ permissions: permissionEngine });
|
|
23
|
-
var knowledgeBase = new KnowledgeBaseEngine();
|
|
24
|
-
var tenants = new TenantManager();
|
|
25
|
-
var activity = new ActivityTracker();
|
|
26
|
-
lifecycle.onEvent((event) => {
|
|
27
|
-
activity.record({
|
|
28
|
-
agentId: event.agentId,
|
|
29
|
-
orgId: event.orgId,
|
|
30
|
-
type: event.type,
|
|
31
|
-
data: event.data
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
engine.get("/skills", (c) => {
|
|
35
|
-
return c.json({ skills: BUILTIN_SKILLS, categories: [...new Set(BUILTIN_SKILLS.map((s) => s.category))], total: BUILTIN_SKILLS.length });
|
|
36
|
-
});
|
|
37
|
-
engine.get("/skills/by-category", (c) => {
|
|
38
|
-
const grouped = {};
|
|
39
|
-
for (const skill of BUILTIN_SKILLS) {
|
|
40
|
-
if (!grouped[skill.category]) grouped[skill.category] = [];
|
|
41
|
-
grouped[skill.category].push(skill);
|
|
42
|
-
}
|
|
43
|
-
return c.json({ categories: grouped });
|
|
44
|
-
});
|
|
45
|
-
engine.get("/skills/:id", (c) => {
|
|
46
|
-
const skill = BUILTIN_SKILLS.find((s) => s.id === c.req.param("id"));
|
|
47
|
-
if (!skill) return c.json({ error: "Skill not found" }, 404);
|
|
48
|
-
return c.json({ skill });
|
|
49
|
-
});
|
|
50
|
-
engine.get("/profiles/presets", (c) => c.json({ presets: PRESET_PROFILES }));
|
|
51
|
-
engine.get("/profiles/:agentId", (c) => {
|
|
52
|
-
const profile = permissionEngine.getProfile(c.req.param("agentId"));
|
|
53
|
-
if (!profile) return c.json({ error: "No profile assigned" }, 404);
|
|
54
|
-
return c.json({ profile });
|
|
55
|
-
});
|
|
56
|
-
engine.put("/profiles/:agentId", async (c) => {
|
|
57
|
-
const agentId = c.req.param("agentId");
|
|
58
|
-
const profile = await c.req.json();
|
|
59
|
-
profile.id = profile.id || agentId;
|
|
60
|
-
profile.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
61
|
-
if (!profile.createdAt) profile.createdAt = profile.updatedAt;
|
|
62
|
-
permissionEngine.setProfile(agentId, profile);
|
|
63
|
-
return c.json({ success: true, profile });
|
|
64
|
-
});
|
|
65
|
-
engine.post("/profiles/:agentId/apply-preset", async (c) => {
|
|
66
|
-
const agentId = c.req.param("agentId");
|
|
67
|
-
const { presetName } = await c.req.json();
|
|
68
|
-
const preset = PRESET_PROFILES.find((p) => p.name === presetName);
|
|
69
|
-
if (!preset) return c.json({ error: "Preset not found" }, 404);
|
|
70
|
-
const profile = { ...preset, id: agentId, createdAt: (/* @__PURE__ */ new Date()).toISOString(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
71
|
-
permissionEngine.setProfile(agentId, profile);
|
|
72
|
-
return c.json({ success: true, profile });
|
|
73
|
-
});
|
|
74
|
-
engine.post("/permissions/check", async (c) => {
|
|
75
|
-
const { agentId, toolId } = await c.req.json();
|
|
76
|
-
return c.json(permissionEngine.checkPermission(agentId, toolId));
|
|
77
|
-
});
|
|
78
|
-
engine.get("/permissions/:agentId/tools", (c) => {
|
|
79
|
-
const tools = permissionEngine.getAvailableTools(c.req.param("agentId"));
|
|
80
|
-
return c.json({ tools, total: tools.length });
|
|
81
|
-
});
|
|
82
|
-
engine.get("/permissions/:agentId/policy", (c) => {
|
|
83
|
-
return c.json(permissionEngine.generateToolPolicy(c.req.param("agentId")));
|
|
84
|
-
});
|
|
85
|
-
engine.post("/agents", async (c) => {
|
|
86
|
-
const { orgId, config, createdBy } = await c.req.json();
|
|
87
|
-
try {
|
|
88
|
-
const agent = await lifecycle.createAgent(orgId, config, createdBy);
|
|
89
|
-
return c.json({ agent }, 201);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return c.json({ error: e.message }, 400);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
engine.get("/agents", (c) => {
|
|
95
|
-
const orgId = c.req.query("orgId");
|
|
96
|
-
if (!orgId) return c.json({ error: "orgId required" }, 400);
|
|
97
|
-
const agents = lifecycle.getAgentsByOrg(orgId);
|
|
98
|
-
return c.json({ agents, total: agents.length });
|
|
99
|
-
});
|
|
100
|
-
engine.get("/agents/:id", (c) => {
|
|
101
|
-
const agent = lifecycle.getAgent(c.req.param("id"));
|
|
102
|
-
if (!agent) return c.json({ error: "Agent not found" }, 404);
|
|
103
|
-
return c.json({ agent });
|
|
104
|
-
});
|
|
105
|
-
engine.patch("/agents/:id/config", async (c) => {
|
|
106
|
-
const { updates, updatedBy } = await c.req.json();
|
|
107
|
-
try {
|
|
108
|
-
const agent = await lifecycle.updateConfig(c.req.param("id"), updates, updatedBy);
|
|
109
|
-
return c.json({ agent });
|
|
110
|
-
} catch (e) {
|
|
111
|
-
return c.json({ error: e.message }, 400);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
engine.post("/agents/:id/deploy", async (c) => {
|
|
115
|
-
const { deployedBy } = await c.req.json();
|
|
116
|
-
try {
|
|
117
|
-
const agent = await lifecycle.deploy(c.req.param("id"), deployedBy);
|
|
118
|
-
return c.json({ agent });
|
|
119
|
-
} catch (e) {
|
|
120
|
-
return c.json({ error: e.message }, 400);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
engine.post("/agents/:id/stop", async (c) => {
|
|
124
|
-
const { stoppedBy, reason } = await c.req.json();
|
|
125
|
-
try {
|
|
126
|
-
const agent = await lifecycle.stop(c.req.param("id"), stoppedBy, reason);
|
|
127
|
-
return c.json({ agent });
|
|
128
|
-
} catch (e) {
|
|
129
|
-
return c.json({ error: e.message }, 400);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
engine.post("/agents/:id/restart", async (c) => {
|
|
133
|
-
const { restartedBy } = await c.req.json();
|
|
134
|
-
try {
|
|
135
|
-
const agent = await lifecycle.restart(c.req.param("id"), restartedBy);
|
|
136
|
-
return c.json({ agent });
|
|
137
|
-
} catch (e) {
|
|
138
|
-
return c.json({ error: e.message }, 400);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
engine.post("/agents/:id/hot-update", async (c) => {
|
|
142
|
-
const { updates, updatedBy } = await c.req.json();
|
|
143
|
-
try {
|
|
144
|
-
const agent = await lifecycle.hotUpdate(c.req.param("id"), updates, updatedBy);
|
|
145
|
-
return c.json({ agent });
|
|
146
|
-
} catch (e) {
|
|
147
|
-
return c.json({ error: e.message }, 400);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
engine.delete("/agents/:id", async (c) => {
|
|
151
|
-
const { destroyedBy } = await c.req.json().catch(() => ({ destroyedBy: "unknown" }));
|
|
152
|
-
try {
|
|
153
|
-
await lifecycle.destroy(c.req.param("id"), destroyedBy);
|
|
154
|
-
return c.json({ success: true });
|
|
155
|
-
} catch (e) {
|
|
156
|
-
return c.json({ error: e.message }, 400);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
engine.get("/agents/:id/usage", (c) => {
|
|
160
|
-
const agent = lifecycle.getAgent(c.req.param("id"));
|
|
161
|
-
if (!agent) return c.json({ error: "Agent not found" }, 404);
|
|
162
|
-
return c.json({ usage: agent.usage, health: agent.health, state: agent.state });
|
|
163
|
-
});
|
|
164
|
-
engine.get("/usage/:orgId", (c) => {
|
|
165
|
-
return c.json(lifecycle.getOrgUsage(c.req.param("orgId")));
|
|
166
|
-
});
|
|
167
|
-
engine.post("/config/workspace", async (c) => {
|
|
168
|
-
const config = await c.req.json();
|
|
169
|
-
return c.json({ files: configGen.generateWorkspace(config) });
|
|
170
|
-
});
|
|
171
|
-
engine.post("/config/gateway", async (c) => {
|
|
172
|
-
const config = await c.req.json();
|
|
173
|
-
return c.json({ config: configGen.generateGatewayConfig(config) });
|
|
174
|
-
});
|
|
175
|
-
engine.post("/config/docker-compose", async (c) => {
|
|
176
|
-
const config = await c.req.json();
|
|
177
|
-
return c.json({ compose: configGen.generateDockerCompose(config) });
|
|
178
|
-
});
|
|
179
|
-
engine.post("/config/systemd", async (c) => {
|
|
180
|
-
const config = await c.req.json();
|
|
181
|
-
return c.json({ unit: configGen.generateSystemdUnit(config) });
|
|
182
|
-
});
|
|
183
|
-
engine.post("/config/deploy-script", async (c) => {
|
|
184
|
-
const config = await c.req.json();
|
|
185
|
-
return c.json({ script: configGen.generateVPSDeployScript(config) });
|
|
186
|
-
});
|
|
187
|
-
engine.post("/knowledge-bases", async (c) => {
|
|
188
|
-
const { orgId, name, description, agentIds, config } = await c.req.json();
|
|
189
|
-
const kb = knowledgeBase.createKnowledgeBase(orgId, { name, description, agentIds, config });
|
|
190
|
-
return c.json({ knowledgeBase: kb }, 201);
|
|
191
|
-
});
|
|
192
|
-
engine.get("/knowledge-bases", (c) => {
|
|
193
|
-
const orgId = c.req.query("orgId");
|
|
194
|
-
const agentId = c.req.query("agentId");
|
|
195
|
-
if (agentId) return c.json({ knowledgeBases: knowledgeBase.getKnowledgeBasesForAgent(agentId) });
|
|
196
|
-
if (orgId) return c.json({ knowledgeBases: knowledgeBase.getKnowledgeBasesByOrg(orgId) });
|
|
197
|
-
return c.json({ error: "orgId or agentId required" }, 400);
|
|
198
|
-
});
|
|
199
|
-
engine.get("/knowledge-bases/:id", (c) => {
|
|
200
|
-
const kb = knowledgeBase.getKnowledgeBase(c.req.param("id"));
|
|
201
|
-
if (!kb) return c.json({ error: "Knowledge base not found" }, 404);
|
|
202
|
-
return c.json({ knowledgeBase: kb });
|
|
203
|
-
});
|
|
204
|
-
engine.post("/knowledge-bases/:id/documents", async (c) => {
|
|
205
|
-
const { name, content, sourceType, sourceUrl, mimeType, metadata } = await c.req.json();
|
|
206
|
-
try {
|
|
207
|
-
const doc = await knowledgeBase.ingestDocument(c.req.param("id"), { name, content, sourceType, sourceUrl, mimeType, metadata });
|
|
208
|
-
return c.json({ document: doc }, 201);
|
|
209
|
-
} catch (e) {
|
|
210
|
-
return c.json({ error: e.message }, 400);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
engine.delete("/knowledge-bases/:kbId/documents/:docId", (c) => {
|
|
214
|
-
const ok = knowledgeBase.deleteDocument(c.req.param("kbId"), c.req.param("docId"));
|
|
215
|
-
return ok ? c.json({ success: true }) : c.json({ error: "Not found" }, 404);
|
|
216
|
-
});
|
|
217
|
-
engine.post("/knowledge-bases/search", async (c) => {
|
|
218
|
-
const { agentId, query, kbIds, maxResults, minScore } = await c.req.json();
|
|
219
|
-
const results = await knowledgeBase.search(agentId, query, { kbIds, maxResults, minScore });
|
|
220
|
-
return c.json({ results, total: results.length });
|
|
221
|
-
});
|
|
222
|
-
engine.post("/knowledge-bases/context", async (c) => {
|
|
223
|
-
const { agentId, query, maxTokens } = await c.req.json();
|
|
224
|
-
const context = await knowledgeBase.getContext(agentId, query, maxTokens);
|
|
225
|
-
return c.json({ context });
|
|
226
|
-
});
|
|
227
|
-
engine.delete("/knowledge-bases/:id", (c) => {
|
|
228
|
-
const ok = knowledgeBase.deleteKnowledgeBase(c.req.param("id"));
|
|
229
|
-
return ok ? c.json({ success: true }) : c.json({ error: "Not found" }, 404);
|
|
230
|
-
});
|
|
231
|
-
engine.post("/orgs", async (c) => {
|
|
232
|
-
const { name, slug, plan, adminEmail, settings } = await c.req.json();
|
|
233
|
-
try {
|
|
234
|
-
const org = tenants.createOrg({ name, slug, plan: plan || "free", adminEmail, settings });
|
|
235
|
-
return c.json({ org }, 201);
|
|
236
|
-
} catch (e) {
|
|
237
|
-
return c.json({ error: e.message }, 400);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
engine.get("/orgs", (c) => c.json({ orgs: tenants.listOrgs() }));
|
|
241
|
-
engine.get("/orgs/:id", (c) => {
|
|
242
|
-
const org = tenants.getOrg(c.req.param("id"));
|
|
243
|
-
if (!org) return c.json({ error: "Org not found" }, 404);
|
|
244
|
-
return c.json({ org });
|
|
245
|
-
});
|
|
246
|
-
engine.get("/orgs/slug/:slug", (c) => {
|
|
247
|
-
const org = tenants.getOrgBySlug(c.req.param("slug"));
|
|
248
|
-
if (!org) return c.json({ error: "Org not found" }, 404);
|
|
249
|
-
return c.json({ org });
|
|
250
|
-
});
|
|
251
|
-
engine.post("/orgs/:id/check-limit", async (c) => {
|
|
252
|
-
const { resource, currentCount } = await c.req.json();
|
|
253
|
-
try {
|
|
254
|
-
return c.json(tenants.checkLimit(c.req.param("id"), resource, currentCount));
|
|
255
|
-
} catch (e) {
|
|
256
|
-
return c.json({ error: e.message }, 400);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
engine.post("/orgs/:id/check-feature", async (c) => {
|
|
260
|
-
const { feature } = await c.req.json();
|
|
261
|
-
return c.json({ allowed: tenants.hasFeature(c.req.param("id"), feature) });
|
|
262
|
-
});
|
|
263
|
-
engine.post("/orgs/:id/change-plan", async (c) => {
|
|
264
|
-
const { plan } = await c.req.json();
|
|
265
|
-
try {
|
|
266
|
-
const org = tenants.changePlan(c.req.param("id"), plan);
|
|
267
|
-
return c.json({ org });
|
|
268
|
-
} catch (e) {
|
|
269
|
-
return c.json({ error: e.message }, 400);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
engine.get("/approvals/pending", (c) => {
|
|
273
|
-
const agentId = c.req.query("agentId");
|
|
274
|
-
const requests = approvals.getPendingRequests(agentId || void 0);
|
|
275
|
-
return c.json({ requests, total: requests.length });
|
|
276
|
-
});
|
|
277
|
-
engine.get("/approvals/history", (c) => {
|
|
278
|
-
const agentId = c.req.query("agentId");
|
|
279
|
-
const limit = parseInt(c.req.query("limit") || "25");
|
|
280
|
-
const offset = parseInt(c.req.query("offset") || "0");
|
|
281
|
-
return c.json(approvals.getHistory({ agentId: agentId || void 0, limit, offset }));
|
|
282
|
-
});
|
|
283
|
-
engine.get("/approvals/:id", (c) => {
|
|
284
|
-
const request = approvals.getRequest(c.req.param("id"));
|
|
285
|
-
if (!request) return c.json({ error: "Not found" }, 404);
|
|
286
|
-
return c.json({ request });
|
|
287
|
-
});
|
|
288
|
-
engine.post("/approvals/:id/decide", async (c) => {
|
|
289
|
-
const { action, reason, by } = await c.req.json();
|
|
290
|
-
const result = approvals.decide(c.req.param("id"), { action, reason, by });
|
|
291
|
-
if (!result) return c.json({ error: "Not found or already decided" }, 404);
|
|
292
|
-
return c.json({ request: result });
|
|
293
|
-
});
|
|
294
|
-
engine.get("/approvals/policies", (c) => c.json({ policies: approvals.getPolicies() }));
|
|
295
|
-
engine.post("/approvals/policies", async (c) => {
|
|
296
|
-
const policy = await c.req.json();
|
|
297
|
-
policy.id = policy.id || crypto.randomUUID();
|
|
298
|
-
approvals.addPolicy(policy);
|
|
299
|
-
return c.json({ success: true, policy });
|
|
300
|
-
});
|
|
301
|
-
engine.delete("/approvals/policies/:id", (c) => {
|
|
302
|
-
approvals.removePolicy(c.req.param("id"));
|
|
303
|
-
return c.json({ success: true });
|
|
304
|
-
});
|
|
305
|
-
engine.get("/activity/events", (c) => {
|
|
306
|
-
const events = activity.getEvents({
|
|
307
|
-
agentId: c.req.query("agentId") || void 0,
|
|
308
|
-
orgId: c.req.query("orgId") || void 0,
|
|
309
|
-
since: c.req.query("since") || void 0,
|
|
310
|
-
limit: parseInt(c.req.query("limit") || "50")
|
|
311
|
-
});
|
|
312
|
-
return c.json({ events, total: events.length });
|
|
313
|
-
});
|
|
314
|
-
engine.get("/activity/tool-calls", (c) => {
|
|
315
|
-
const calls = activity.getToolCalls({
|
|
316
|
-
agentId: c.req.query("agentId") || void 0,
|
|
317
|
-
orgId: c.req.query("orgId") || void 0,
|
|
318
|
-
toolId: c.req.query("toolId") || void 0,
|
|
319
|
-
limit: parseInt(c.req.query("limit") || "50")
|
|
320
|
-
});
|
|
321
|
-
return c.json({ toolCalls: calls, total: calls.length });
|
|
322
|
-
});
|
|
323
|
-
engine.get("/activity/conversation/:sessionId", (c) => {
|
|
324
|
-
const entries = activity.getConversation(c.req.param("sessionId"));
|
|
325
|
-
return c.json({ entries, total: entries.length });
|
|
326
|
-
});
|
|
327
|
-
engine.get("/activity/timeline/:agentId/:date", (c) => {
|
|
328
|
-
const timeline = activity.getTimeline(c.req.param("agentId"), c.req.param("date"));
|
|
329
|
-
return c.json({ timeline });
|
|
330
|
-
});
|
|
331
|
-
engine.get("/activity/stats", (c) => {
|
|
332
|
-
const orgId = c.req.query("orgId");
|
|
333
|
-
return c.json(activity.getStats(orgId || void 0));
|
|
334
|
-
});
|
|
335
|
-
engine.get("/activity/stream", (c) => {
|
|
336
|
-
const orgId = c.req.query("orgId");
|
|
337
|
-
const agentId = c.req.query("agentId");
|
|
338
|
-
const stream = new ReadableStream({
|
|
339
|
-
start(controller) {
|
|
340
|
-
const encoder = new TextEncoder();
|
|
341
|
-
const send = (data) => {
|
|
342
|
-
try {
|
|
343
|
-
controller.enqueue(encoder.encode(`data: ${data}
|
|
344
|
-
|
|
345
|
-
`));
|
|
346
|
-
} catch {
|
|
347
|
-
unsubscribe();
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const heartbeat = setInterval(() => send(JSON.stringify({ type: "heartbeat" })), 3e4);
|
|
351
|
-
const unsubscribe = activity.subscribe((event) => {
|
|
352
|
-
if (orgId && event.orgId !== orgId) return;
|
|
353
|
-
if (agentId && event.agentId !== agentId) return;
|
|
354
|
-
send(JSON.stringify(event));
|
|
355
|
-
});
|
|
356
|
-
c.req.raw.signal.addEventListener("abort", () => {
|
|
357
|
-
unsubscribe();
|
|
358
|
-
clearInterval(heartbeat);
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
return new Response(stream, {
|
|
363
|
-
headers: {
|
|
364
|
-
"Content-Type": "text/event-stream",
|
|
365
|
-
"Cache-Control": "no-cache",
|
|
366
|
-
"Connection": "keep-alive"
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
engine.get("/stats/:orgId", (c) => {
|
|
371
|
-
const orgId = c.req.param("orgId");
|
|
372
|
-
const org = tenants.getOrg(orgId);
|
|
373
|
-
const agents = lifecycle.getAgentsByOrg(orgId);
|
|
374
|
-
const orgUsage = lifecycle.getOrgUsage(orgId);
|
|
375
|
-
const realTimeStats = activity.getStats(orgId);
|
|
376
|
-
return c.json({
|
|
377
|
-
org: org ? { name: org.name, plan: org.plan, limits: org.limits, usage: org.usage } : null,
|
|
378
|
-
agents: {
|
|
379
|
-
total: agents.length,
|
|
380
|
-
byState: agents.reduce((acc, a) => {
|
|
381
|
-
acc[a.state] = (acc[a.state] || 0) + 1;
|
|
382
|
-
return acc;
|
|
383
|
-
}, {})
|
|
384
|
-
},
|
|
385
|
-
usage: orgUsage,
|
|
386
|
-
realTime: realTimeStats
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
export {
|
|
390
|
-
activity,
|
|
391
|
-
approvals,
|
|
392
|
-
configGen,
|
|
393
|
-
deployer,
|
|
394
|
-
engine as engineRoutes,
|
|
395
|
-
knowledgeBase,
|
|
396
|
-
lifecycle,
|
|
397
|
-
permissionEngine,
|
|
398
|
-
tenants
|
|
399
|
-
};
|