agentflow-dashboard 0.6.0 → 0.7.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/dist/index.cjs CHANGED
@@ -45,6 +45,422 @@ var import_agentflow_core3 = require("agentflow-core");
45
45
  var import_express = __toESM(require("express"), 1);
46
46
  var import_ws = require("ws");
47
47
 
48
+ // src/adapters/agentflow.ts
49
+ var SKIP_FILES = /* @__PURE__ */ new Set([
50
+ "workers.json",
51
+ "package.json",
52
+ "package-lock.json",
53
+ "tsconfig.json",
54
+ "biome.json",
55
+ "auth.json",
56
+ "models.json",
57
+ "config.json"
58
+ ]);
59
+ var SKIP_SUFFIXES = ["-state.json", "-config.json", "-watch-state.json", ".tmp", ".bak", ".backup"];
60
+ var AgentFlowAdapter = class {
61
+ name = "agentflow";
62
+ detect(_dirPath) {
63
+ return true;
64
+ }
65
+ canHandle(filePath) {
66
+ const filename = filePath.split("/").pop() ?? "";
67
+ if (SKIP_FILES.has(filename)) return false;
68
+ if (SKIP_SUFFIXES.some((s) => filename.endsWith(s))) return false;
69
+ return filename.endsWith(".json") || filename.endsWith(".jsonl") || filename.endsWith(".log") || filename.endsWith(".trace");
70
+ }
71
+ parse(_filePath) {
72
+ return [];
73
+ }
74
+ };
75
+
76
+ // src/adapters/openclaw.ts
77
+ var import_node_fs = require("fs");
78
+ var import_node_path = require("path");
79
+ var jobCache = /* @__PURE__ */ new Map();
80
+ function loadJobs(openclawDir) {
81
+ const cached = jobCache.get(openclawDir);
82
+ if (cached) return cached;
83
+ const jobsPath = (0, import_node_path.join)(openclawDir, "cron", "jobs.json");
84
+ const map = /* @__PURE__ */ new Map();
85
+ try {
86
+ if ((0, import_node_fs.existsSync)(jobsPath)) {
87
+ const data = JSON.parse((0, import_node_fs.readFileSync)(jobsPath, "utf-8"));
88
+ const jobs = Array.isArray(data) ? data : data.jobs ?? [];
89
+ for (const job of jobs) {
90
+ if (job.id) map.set(job.id, job);
91
+ }
92
+ }
93
+ } catch {
94
+ }
95
+ jobCache.set(openclawDir, map);
96
+ return map;
97
+ }
98
+ function findOpenClawRoot(filePath) {
99
+ let dir = (0, import_node_path.dirname)(filePath);
100
+ for (let i = 0; i < 5; i++) {
101
+ if ((0, import_node_fs.existsSync)((0, import_node_path.join)(dir, "cron", "jobs.json")) || (0, import_node_path.basename)(dir) === ".openclaw") {
102
+ return dir;
103
+ }
104
+ dir = (0, import_node_path.dirname)(dir);
105
+ }
106
+ return null;
107
+ }
108
+ var OpenClawAdapter = class {
109
+ name = "openclaw";
110
+ detect(dirPath) {
111
+ return (0, import_node_fs.existsSync)((0, import_node_path.join)(dirPath, "cron", "jobs.json")) || dirPath.includes(".openclaw") || (0, import_node_fs.existsSync)((0, import_node_path.join)(dirPath, "cron", "runs"));
112
+ }
113
+ canHandle(filePath) {
114
+ if (!filePath.endsWith(".jsonl")) return false;
115
+ return filePath.includes("/cron/runs/") || filePath.includes("\\cron\\runs\\");
116
+ }
117
+ parse(filePath) {
118
+ const traces = [];
119
+ try {
120
+ const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
121
+ const root = findOpenClawRoot(filePath);
122
+ const jobs = root ? loadJobs(root) : /* @__PURE__ */ new Map();
123
+ for (const line of content.split("\n")) {
124
+ if (!line.trim()) continue;
125
+ let entry;
126
+ try {
127
+ entry = JSON.parse(line);
128
+ } catch {
129
+ continue;
130
+ }
131
+ if (entry.action !== "finished") continue;
132
+ const jobId = entry.jobId ?? (0, import_node_path.basename)(filePath, ".jsonl");
133
+ const job = jobs.get(jobId);
134
+ const jobName = (job == null ? void 0 : job.name) ?? jobId;
135
+ const startTime = entry.runAtMs ?? entry.ts;
136
+ const duration = entry.durationMs ?? 0;
137
+ const trace = {
138
+ id: entry.sessionId ?? `${jobId}-${entry.ts}`,
139
+ agentId: `openclaw:${jobId}`,
140
+ name: jobName,
141
+ status: entry.status === "ok" ? "completed" : entry.status === "error" ? "failed" : "unknown",
142
+ startTime,
143
+ endTime: startTime + duration,
144
+ trigger: "cron",
145
+ source: "openclaw",
146
+ nodes: {
147
+ root: {
148
+ id: "root",
149
+ type: "cron-job",
150
+ name: jobName,
151
+ status: entry.status === "ok" ? "completed" : entry.status === "error" ? "failed" : "unknown",
152
+ startTime,
153
+ endTime: startTime + duration,
154
+ parentId: null,
155
+ children: [],
156
+ metadata: {
157
+ jobId,
158
+ summary: entry.summary,
159
+ error: entry.error,
160
+ delivered: entry.delivered,
161
+ deliveryStatus: entry.deliveryStatus
162
+ }
163
+ }
164
+ },
165
+ metadata: {
166
+ model: entry.model,
167
+ provider: entry.provider,
168
+ usage: entry.usage,
169
+ sessionId: entry.sessionId,
170
+ sessionKey: entry.sessionKey,
171
+ nextRunAtMs: entry.nextRunAtMs
172
+ },
173
+ filePath
174
+ };
175
+ traces.push(trace);
176
+ }
177
+ } catch {
178
+ }
179
+ return traces;
180
+ }
181
+ };
182
+
183
+ // src/adapters/otel.ts
184
+ var import_node_fs2 = require("fs");
185
+ var import_node_path2 = require("path");
186
+ var SPAN_TYPE_MAP = {
187
+ "gen_ai.chat": "llm",
188
+ "gen_ai.completion": "llm",
189
+ "gen_ai.embeddings": "embedding",
190
+ "gen_ai.content.prompt": "llm",
191
+ "gen_ai.content.completion": "llm"
192
+ };
193
+ function mapSpanType(spanName, attributes) {
194
+ for (const [prefix, type] of Object.entries(SPAN_TYPE_MAP)) {
195
+ if (spanName.startsWith(prefix)) return type;
196
+ }
197
+ if (attributes["tool.name"] || attributes["code.function"]) return "tool";
198
+ if (attributes["gen_ai.system"] || attributes["llm.vendor"]) return "llm";
199
+ if (attributes["db.system"]) return "database";
200
+ if (attributes["http.method"] || attributes["http.request.method"]) return "http";
201
+ return "span";
202
+ }
203
+ function extractAttributes(attrs) {
204
+ const result = {};
205
+ if (!Array.isArray(attrs)) return result;
206
+ for (const attr of attrs) {
207
+ const a = attr;
208
+ if (!a.key || !a.value) continue;
209
+ result[a.key] = a.value.stringValue ?? a.value.intValue ?? a.value.doubleValue ?? a.value.boolValue;
210
+ }
211
+ return result;
212
+ }
213
+ function parseOtlpPayload(payload) {
214
+ var _a, _b, _c;
215
+ const traceMap = /* @__PURE__ */ new Map();
216
+ for (const rs of payload.resourceSpans ?? []) {
217
+ const resourceAttrs = extractAttributes(((_a = rs.resource) == null ? void 0 : _a.attributes) ?? []);
218
+ for (const ss of rs.scopeSpans ?? []) {
219
+ for (const span of ss.spans ?? []) {
220
+ if (!span.traceId) continue;
221
+ let entry = traceMap.get(span.traceId);
222
+ if (!entry) {
223
+ entry = { spans: [], resource: resourceAttrs };
224
+ traceMap.set(span.traceId, entry);
225
+ }
226
+ entry.spans.push(span);
227
+ }
228
+ }
229
+ }
230
+ const traces = [];
231
+ for (const [traceId, { spans, resource }] of traceMap) {
232
+ const nodes = {};
233
+ const childMap = /* @__PURE__ */ new Map();
234
+ let traceStart = Number.MAX_SAFE_INTEGER;
235
+ let traceEnd = 0;
236
+ let hasFailed = false;
237
+ for (const span of spans) {
238
+ const attrs = extractAttributes(span.attributes ?? []);
239
+ const startNs = span.startTimeUnixNano ? Number(BigInt(span.startTimeUnixNano) / 1000000n) : 0;
240
+ const endNs = span.endTimeUnixNano ? Number(BigInt(span.endTimeUnixNano) / 1000000n) : null;
241
+ const failed = ((_b = span.status) == null ? void 0 : _b.code) === 2;
242
+ if (failed) hasFailed = true;
243
+ if (startNs < traceStart) traceStart = startNs;
244
+ if (endNs && endNs > traceEnd) traceEnd = endNs;
245
+ nodes[span.spanId] = {
246
+ id: span.spanId,
247
+ type: mapSpanType(span.name, attrs),
248
+ name: span.name,
249
+ status: failed ? "failed" : endNs ? "completed" : "running",
250
+ startTime: startNs,
251
+ endTime: endNs,
252
+ parentId: span.parentSpanId ?? null,
253
+ children: [],
254
+ metadata: {
255
+ ...attrs,
256
+ model: attrs["gen_ai.request.model"] ?? attrs["llm.request.model"],
257
+ inputTokens: attrs["gen_ai.usage.input_tokens"] ?? attrs["llm.usage.input_tokens"],
258
+ outputTokens: attrs["gen_ai.usage.output_tokens"] ?? attrs["llm.usage.output_tokens"]
259
+ }
260
+ };
261
+ if (span.parentSpanId) {
262
+ const siblings = childMap.get(span.parentSpanId) ?? [];
263
+ siblings.push(span.spanId);
264
+ childMap.set(span.parentSpanId, siblings);
265
+ }
266
+ }
267
+ for (const [parentId, children] of childMap) {
268
+ if (nodes[parentId]) {
269
+ nodes[parentId].children = children;
270
+ }
271
+ }
272
+ const serviceName = resource["service.name"] ?? "unknown-service";
273
+ traces.push({
274
+ id: traceId,
275
+ agentId: `otel:${serviceName}`,
276
+ name: ((_c = spans.find((s) => !s.parentSpanId)) == null ? void 0 : _c.name) ?? traceId,
277
+ status: hasFailed ? "failed" : "completed",
278
+ startTime: traceStart === Number.MAX_SAFE_INTEGER ? 0 : traceStart,
279
+ endTime: traceEnd,
280
+ trigger: "otel",
281
+ source: "otel",
282
+ nodes,
283
+ metadata: { ...resource }
284
+ });
285
+ }
286
+ return traces;
287
+ }
288
+ var OTelAdapter = class {
289
+ name = "otel";
290
+ detect(dirPath) {
291
+ try {
292
+ if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(dirPath, "otel-traces"))) return true;
293
+ const files = (0, import_node_fs2.readdirSync)(dirPath);
294
+ return files.some((f) => f.endsWith(".otlp.json"));
295
+ } catch {
296
+ return false;
297
+ }
298
+ }
299
+ canHandle(filePath) {
300
+ return filePath.endsWith(".otlp.json");
301
+ }
302
+ parse(filePath) {
303
+ try {
304
+ const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
305
+ const payload = JSON.parse(content);
306
+ const traces = parseOtlpPayload(payload);
307
+ for (const t of traces) t.filePath = filePath;
308
+ return traces;
309
+ } catch {
310
+ return [];
311
+ }
312
+ }
313
+ };
314
+
315
+ // src/adapters/registry.ts
316
+ var adapters = [];
317
+ function registerAdapter(adapter) {
318
+ adapters.push(adapter);
319
+ }
320
+ function findAdapter(filePath) {
321
+ for (const adapter of adapters) {
322
+ if (adapter.canHandle(filePath)) return adapter;
323
+ }
324
+ return null;
325
+ }
326
+
327
+ // src/adapters/index.ts
328
+ registerAdapter(new OpenClawAdapter());
329
+ registerAdapter(new OTelAdapter());
330
+ registerAdapter(new AgentFlowAdapter());
331
+
332
+ // src/agent-clustering.ts
333
+ var PURPOSE_KEYWORDS = [
334
+ { keywords: ["email", "mail", "inbox", "smtp"], group: "Email Processors" },
335
+ { keywords: ["monitor", "watch", "alert", "surveillance"], group: "Monitors" },
336
+ { keywords: ["digest", "newsletter", "summary", "report", "briefing"], group: "Digests & Reports" },
337
+ { keywords: ["curator", "janitor", "distiller", "surveyor", "worker", "indexer"], group: "Workers" },
338
+ { keywords: ["cron", "schedule", "timer", "periodic"], group: "Scheduled Jobs" },
339
+ { keywords: ["search", "scrape", "crawl", "fetch"], group: "Data Collection" },
340
+ { keywords: ["embed", "vector", "index"], group: "Embeddings" }
341
+ ];
342
+ function extractSource(agentId) {
343
+ const colonIdx = agentId.indexOf(":");
344
+ if (colonIdx > 0 && colonIdx < 20) {
345
+ const prefix = agentId.slice(0, colonIdx);
346
+ if (["openclaw", "otel", "langchain", "crewai", "mastra"].includes(prefix)) {
347
+ return { source: prefix, localId: agentId.slice(colonIdx + 1) };
348
+ }
349
+ }
350
+ return { source: "agentflow", localId: agentId };
351
+ }
352
+ function extractSuffix(localId) {
353
+ const dashIdx = localId.indexOf("-");
354
+ if (dashIdx > 0 && dashIdx < localId.length - 1) {
355
+ const suffix = localId.slice(dashIdx + 1);
356
+ if (suffix.length >= 4) return suffix;
357
+ }
358
+ return null;
359
+ }
360
+ function findPurpose(name) {
361
+ const lower = name.toLowerCase();
362
+ for (const { keywords, group } of PURPOSE_KEYWORDS) {
363
+ if (keywords.some((kw) => lower.includes(kw))) return group;
364
+ }
365
+ return "General";
366
+ }
367
+ function capitalize(s) {
368
+ return s.charAt(0).toUpperCase() + s.slice(1);
369
+ }
370
+ function deduplicateAgents(agents) {
371
+ const tagged = agents.map((a) => ({
372
+ ...a,
373
+ ...extractSource(a.agentId)
374
+ }));
375
+ const suffixGroups = /* @__PURE__ */ new Map();
376
+ for (const a of tagged) {
377
+ const suffix = extractSuffix(a.localId);
378
+ if (!suffix) continue;
379
+ const group = suffixGroups.get(suffix) ?? [];
380
+ group.push(a);
381
+ suffixGroups.set(suffix, group);
382
+ }
383
+ const mergedIds = /* @__PURE__ */ new Set();
384
+ const mergedAgents = [];
385
+ for (const [suffix, group] of suffixGroups) {
386
+ if (group.length < 2) continue;
387
+ const prefixes = new Set(group.map((a) => a.localId.split("-")[0]));
388
+ if (prefixes.size < 2) continue;
389
+ const merged = {
390
+ agentId: group[0].source === "agentflow" ? suffix : `${group[0].source}:${suffix}`,
391
+ displayName: suffix,
392
+ totalExecutions: group.reduce((s, a) => s + a.totalExecutions, 0),
393
+ successfulExecutions: group.reduce((s, a) => s + a.successfulExecutions, 0),
394
+ failedExecutions: group.reduce((s, a) => s + a.failedExecutions, 0),
395
+ successRate: 0,
396
+ avgExecutionTime: 0,
397
+ lastExecution: Math.max(...group.map((a) => a.lastExecution)),
398
+ triggers: {},
399
+ recentActivity: group.flatMap((a) => a.recentActivity).sort((a, b) => b.timestamp - a.timestamp).slice(0, 50),
400
+ sources: group.map((a) => a.agentId),
401
+ adapterSource: group[0].source
402
+ };
403
+ merged.successRate = merged.totalExecutions > 0 ? merged.successfulExecutions / merged.totalExecutions * 100 : 0;
404
+ const totalExecTime = group.reduce((s, a) => s + a.avgExecutionTime * a.totalExecutions, 0);
405
+ merged.avgExecutionTime = merged.totalExecutions > 0 ? totalExecTime / merged.totalExecutions : 0;
406
+ for (const a of group) {
407
+ for (const [k, v] of Object.entries(a.triggers)) {
408
+ merged.triggers[k] = (merged.triggers[k] ?? 0) + v;
409
+ }
410
+ }
411
+ mergedAgents.push(merged);
412
+ for (const a of group) mergedIds.add(a.agentId);
413
+ }
414
+ const result = [];
415
+ for (const a of agents) {
416
+ if (mergedIds.has(a.agentId)) continue;
417
+ const { source, localId } = extractSource(a.agentId);
418
+ result.push({
419
+ ...a,
420
+ displayName: a.displayName ?? localId,
421
+ adapterSource: source
422
+ });
423
+ }
424
+ return [...result, ...mergedAgents];
425
+ }
426
+ function groupAgents(agents) {
427
+ const sourceMap = /* @__PURE__ */ new Map();
428
+ for (const a of agents) {
429
+ const source = a.adapterSource ?? extractSource(a.agentId).source;
430
+ const list = sourceMap.get(source) ?? [];
431
+ list.push(a);
432
+ sourceMap.set(source, list);
433
+ }
434
+ const SOURCE_DISPLAY = {
435
+ agentflow: "AgentFlow",
436
+ openclaw: "OpenClaw",
437
+ otel: "OpenTelemetry",
438
+ langchain: "LangChain",
439
+ crewai: "CrewAI"
440
+ };
441
+ const groups = [];
442
+ for (const [source, sourceAgents] of sourceMap) {
443
+ const subMap = /* @__PURE__ */ new Map();
444
+ for (const a of sourceAgents) {
445
+ const purpose = findPurpose(a.displayName ?? a.agentId);
446
+ const list = subMap.get(purpose) ?? [];
447
+ list.push(a.agentId);
448
+ subMap.set(purpose, list);
449
+ }
450
+ const subGroups = [...subMap.entries()].map(([name, agentIds]) => ({ name, agentIds })).sort((a, b) => b.agentIds.length - a.agentIds.length);
451
+ groups.push({
452
+ name: source,
453
+ displayName: SOURCE_DISPLAY[source] ?? capitalize(source),
454
+ totalExecutions: sourceAgents.reduce((s, a) => s + a.totalExecutions, 0),
455
+ failedExecutions: sourceAgents.reduce((s, a) => s + a.failedExecutions, 0),
456
+ agents: sourceAgents.sort((a, b) => b.totalExecutions - a.totalExecutions),
457
+ subGroups
458
+ });
459
+ }
460
+ groups.sort((a, b) => b.totalExecutions - a.totalExecutions);
461
+ return { groups };
462
+ }
463
+
48
464
  // src/stats.ts
49
465
  var import_agentflow_core = require("agentflow-core");
50
466
  var AgentStats = class {
@@ -369,7 +785,7 @@ function openClawSessionIdToAgent(sessionId) {
369
785
  if (sessionId.startsWith("janitor-")) return "vault-janitor";
370
786
  if (sessionId.startsWith("curator-")) return "vault-curator";
371
787
  if (sessionId.startsWith("distiller-")) return "vault-distiller";
372
- if (sessionId.startsWith("main-")) return "main";
788
+ if (sessionId.startsWith("main-")) return "alfred-main";
373
789
  const firstSegment = sessionId.split("-")[0];
374
790
  if (firstSegment) return firstSegment;
375
791
  return "openclaw";
@@ -454,10 +870,14 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
454
870
  "package-lock.json",
455
871
  "tsconfig.json",
456
872
  "biome.json",
457
- "jobs.json",
458
873
  "auth.json",
459
874
  "models.json",
460
- "config.json"
875
+ "config.json",
876
+ "runs.json",
877
+ "sessions.json",
878
+ "containers.json",
879
+ "update-check.json",
880
+ "exec-approvals.json"
461
881
  ]);
462
882
  static SKIP_SUFFIXES = [
463
883
  "-state.json",
@@ -467,11 +887,15 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
467
887
  ".bak",
468
888
  ".backup"
469
889
  ];
470
- /** Load a .json trace, .jsonl session file, or .log file. */
890
+ /** Load a file using the adapter registry, falling back to built-in parsing. */
471
891
  loadFile(filePath) {
472
892
  const filename = path.basename(filePath);
473
893
  if (_TraceWatcher.SKIP_FILES.has(filename)) return false;
474
894
  if (_TraceWatcher.SKIP_SUFFIXES.some((s) => filename.endsWith(s))) return false;
895
+ const adapter = findAdapter(filePath);
896
+ if (adapter && adapter.name !== "agentflow") {
897
+ return this.loadViaAdapter(filePath, adapter.name);
898
+ }
475
899
  if (filePath.endsWith(".jsonl")) {
476
900
  return this.loadSessionFile(filePath);
477
901
  }
@@ -480,6 +904,57 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
480
904
  }
481
905
  return this.loadTraceFile(filePath);
482
906
  }
907
+ /** Load a file using a specific adapter and store normalized traces. */
908
+ loadViaAdapter(filePath, adapterName) {
909
+ try {
910
+ const adapter = findAdapter(filePath);
911
+ if (!adapter) return false;
912
+ const normalized = adapter.parse(filePath);
913
+ if (normalized.length === 0) return false;
914
+ for (const trace of normalized) {
915
+ const nodes = /* @__PURE__ */ new Map();
916
+ for (const [id, node] of Object.entries(trace.nodes)) {
917
+ nodes.set(id, {
918
+ id: node.id,
919
+ type: node.type,
920
+ name: node.name,
921
+ status: node.status,
922
+ startTime: node.startTime,
923
+ endTime: node.endTime,
924
+ parentId: node.parentId,
925
+ children: node.children,
926
+ metadata: node.metadata,
927
+ state: {}
928
+ });
929
+ }
930
+ const watched = {
931
+ id: trace.id,
932
+ rootNodeId: Object.keys(trace.nodes)[0] ?? "",
933
+ agentId: trace.agentId,
934
+ name: trace.name,
935
+ trigger: trace.trigger,
936
+ startTime: trace.startTime,
937
+ endTime: trace.endTime,
938
+ status: trace.status,
939
+ nodes,
940
+ edges: [],
941
+ events: [],
942
+ metadata: { ...trace.metadata, adapterSource: adapterName },
943
+ sessionEvents: trace.sessionEvents ?? [],
944
+ sourceType: "session",
945
+ filename: path.basename(filePath),
946
+ lastModified: Date.now(),
947
+ sourceDir: path.dirname(filePath)
948
+ };
949
+ const key = `${adapterName}:${trace.id}`;
950
+ this.traces.set(key, watched);
951
+ }
952
+ return true;
953
+ } catch (error) {
954
+ console.error(`Adapter ${adapterName} failed for ${filePath}:`, error);
955
+ return false;
956
+ }
957
+ }
483
958
  loadLogFile(filePath) {
484
959
  try {
485
960
  const content = fs.readFileSync(filePath, "utf8");
@@ -592,21 +1067,46 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
592
1067
  }
593
1068
  return traces;
594
1069
  }
1070
+ /**
1071
+ * Normalise agent identifiers so that the same worker is never shown
1072
+ * under two different names (e.g. "vault-curator" vs "openclaw-vault-curator").
1073
+ *
1074
+ * Canonical names: alfred-main, vault-curator, vault-janitor,
1075
+ * vault-distiller, vault-surveyor
1076
+ */
1077
+ static AGENT_ALIASES = {
1078
+ "openclaw-main": "alfred-main",
1079
+ "openclaw-vault-curator": "vault-curator",
1080
+ "openclaw-vault-janitor": "vault-janitor",
1081
+ "openclaw-vault-distiller": "vault-distiller",
1082
+ "openclaw-vault-surveyor": "vault-surveyor",
1083
+ "alfred-curator": "vault-curator",
1084
+ "alfred-janitor": "vault-janitor",
1085
+ "alfred-distiller": "vault-distiller",
1086
+ "alfred-surveyor": "vault-surveyor",
1087
+ curator: "vault-curator",
1088
+ janitor: "vault-janitor",
1089
+ distiller: "vault-distiller",
1090
+ surveyor: "vault-surveyor"
1091
+ };
1092
+ normaliseAgentId(raw) {
1093
+ return _TraceWatcher.AGENT_ALIASES[raw] ?? raw;
1094
+ }
595
1095
  detectAgentIdentifier(activity, _filename, filePath) {
596
1096
  if (activity.agent_id) {
597
1097
  const agentId = activity.agent_id;
598
- if (agentId.startsWith("vault-")) return agentId;
599
- if (agentId === "main" && filePath.includes(".alfred/")) return "alfred-main";
600
- return agentId;
1098
+ if (agentId === "main" && filePath.includes(".alfred/")) return this.normaliseAgentId("alfred-main");
1099
+ return this.normaliseAgentId(agentId);
601
1100
  }
602
1101
  const pathAgent = this.extractAgentFromPath(filePath);
603
1102
  if (filePath.includes(".alfred/") && !pathAgent.startsWith("alfred-")) {
604
- const basename2 = path.basename(filePath, path.extname(filePath));
605
- if (basename2.match(/^(janitor|curator|distiller|surveyor|alfred)$/)) {
606
- return basename2 === "alfred" ? "alfred" : `alfred-${basename2}`;
1103
+ const basename3 = path.basename(filePath, path.extname(filePath));
1104
+ if (basename3.match(/^(janitor|curator|distiller|surveyor|alfred)$/)) {
1105
+ const raw = basename3 === "alfred" ? "alfred" : `alfred-${basename3}`;
1106
+ return this.normaliseAgentId(raw);
607
1107
  }
608
1108
  }
609
- return pathAgent;
1109
+ return this.normaliseAgentId(pathAgent);
610
1110
  }
611
1111
  extractAgentFromPath(filePath) {
612
1112
  const filename = path.basename(filePath, path.extname(filePath));
@@ -1437,8 +1937,23 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1437
1937
  getTrace(filename) {
1438
1938
  const exact = this.traces.get(filename);
1439
1939
  if (exact) return exact;
1940
+ if (filename.includes("::")) {
1941
+ const [fname, startTimeStr] = filename.split("::");
1942
+ const startTime = Number(startTimeStr);
1943
+ if (fname && !Number.isNaN(startTime)) {
1944
+ for (const trace of this.traces.values()) {
1945
+ if (trace.filename === fname && trace.startTime === startTime) {
1946
+ return trace;
1947
+ }
1948
+ }
1949
+ }
1950
+ }
1951
+ for (const prefix of ["openclaw:", "otel:", ""]) {
1952
+ const prefixed = this.traces.get(prefix + filename);
1953
+ if (prefixed) return prefixed;
1954
+ }
1440
1955
  for (const [key, trace] of this.traces) {
1441
- if (trace.filename === filename || key.endsWith(filename)) {
1956
+ if (trace.filename === filename || trace.id === filename || key.endsWith(filename)) {
1442
1957
  return trace;
1443
1958
  }
1444
1959
  }
@@ -1650,6 +2165,31 @@ function serializeTrace(trace) {
1650
2165
  var DashboardServer = class {
1651
2166
  constructor(config) {
1652
2167
  this.config = config;
2168
+ const home = process.env.HOME ?? "/home/trader";
2169
+ const configPath = path3.join(home, ".agentflow/dashboard-config.json");
2170
+ if (!config.dataDirs) config.dataDirs = [];
2171
+ try {
2172
+ if (fs3.existsSync(configPath)) {
2173
+ const saved = JSON.parse(fs3.readFileSync(configPath, "utf-8"));
2174
+ const extraDirs = saved.extraDirs ?? [];
2175
+ for (const d of extraDirs) {
2176
+ if (!config.dataDirs.includes(d)) config.dataDirs.push(d);
2177
+ }
2178
+ }
2179
+ } catch {
2180
+ }
2181
+ const autoDiscoverPaths = [
2182
+ path3.join(home, ".openclaw/cron/runs"),
2183
+ path3.join(home, ".openclaw/workspace/traces"),
2184
+ path3.join(home, ".openclaw/subagents"),
2185
+ path3.join(home, ".openclaw/agents/main/sessions"),
2186
+ path3.join(home, ".agentflow/traces")
2187
+ ];
2188
+ for (const p of autoDiscoverPaths) {
2189
+ if (fs3.existsSync(p) && !config.dataDirs.includes(p)) {
2190
+ config.dataDirs.push(p);
2191
+ }
2192
+ }
1653
2193
  this.watcher = new TraceWatcher({
1654
2194
  tracesDir: config.tracesDir,
1655
2195
  dataDirs: config.dataDirs
@@ -1698,9 +2238,13 @@ var DashboardServer = class {
1698
2238
  next();
1699
2239
  });
1700
2240
  }
2241
+ const clientDir = path3.join(__dirname, "../dist/client");
2242
+ if (fs3.existsSync(clientDir)) {
2243
+ this.app.use(import_express.default.static(clientDir));
2244
+ }
1701
2245
  const publicDir = path3.join(__dirname, "../public");
1702
2246
  if (fs3.existsSync(publicDir)) {
1703
- this.app.use(import_express.default.static(publicDir));
2247
+ this.app.use("/v1", import_express.default.static(publicDir));
1704
2248
  }
1705
2249
  this.app.get("/api/traces", (_req, res) => {
1706
2250
  try {
@@ -1736,10 +2280,28 @@ var DashboardServer = class {
1736
2280
  res.status(500).json({ error: "Failed to load trace events" });
1737
2281
  }
1738
2282
  });
1739
- this.app.get("/api/agents", (_req, res) => {
2283
+ this.app.get("/api/agents", (req, res) => {
1740
2284
  try {
1741
- const agents = this.stats.getAgentsList();
1742
- res.json(agents);
2285
+ const raw = this.stats.getAgentsList();
2286
+ for (const agent of raw) {
2287
+ if (!agent.displayName) {
2288
+ const traces = this.watcher.getTracesByAgent(agent.agentId);
2289
+ if (traces.length > 0) {
2290
+ const latest = traces[traces.length - 1];
2291
+ const name = latest == null ? void 0 : latest.name;
2292
+ if (name && name !== "default" && name !== agent.agentId && !name.startsWith("pipeline:") && name.length < 40) {
2293
+ agent.displayName = name;
2294
+ }
2295
+ }
2296
+ if (!agent.displayName) agent.displayName = agent.agentId;
2297
+ }
2298
+ }
2299
+ if (req.query.flat === "true") {
2300
+ return res.json(raw);
2301
+ }
2302
+ const deduped = deduplicateAgents(raw);
2303
+ const grouped = groupAgents(deduped);
2304
+ res.json(grouped);
1743
2305
  } catch (_error) {
1744
2306
  res.status(500).json({ error: "Failed to load agents" });
1745
2307
  }
@@ -1889,6 +2451,84 @@ var DashboardServer = class {
1889
2451
  res.status(500).json({ error: "Failed to load agent profile" });
1890
2452
  }
1891
2453
  });
2454
+ this.app.get("/api/process-model/:agentId", (req, res) => {
2455
+ try {
2456
+ const agentId = req.params.agentId;
2457
+ const allTraces = this.watcher.getTracesByAgent(agentId);
2458
+ if (allTraces.length === 0) {
2459
+ return res.status(404).json({ error: "No traces for agent" });
2460
+ }
2461
+ const transMap = /* @__PURE__ */ new Map();
2462
+ const nodeTypeMap = /* @__PURE__ */ new Map();
2463
+ const variantMap = /* @__PURE__ */ new Map();
2464
+ const durationMap = /* @__PURE__ */ new Map();
2465
+ for (const trace of allTraces) {
2466
+ const serialized = serializeTrace(trace);
2467
+ const nodes = serialized.nodes;
2468
+ if (!nodes || typeof nodes !== "object") continue;
2469
+ const nodeArr = Object.values(nodes);
2470
+ const sorted = nodeArr.filter((n) => n.name && typeof n.startTime === "number" && n.startTime > 0).sort((a, b) => (a.startTime ?? 0) - (b.startTime ?? 0));
2471
+ for (let i = 0; i < sorted.length - 1; i++) {
2472
+ const from = sorted[i].name;
2473
+ const to = sorted[i + 1].name;
2474
+ const key = `${from}|||${to}`;
2475
+ transMap.set(key, (transMap.get(key) ?? 0) + 1);
2476
+ }
2477
+ for (const n of sorted) {
2478
+ if (n.name && n.type) nodeTypeMap.set(n.name, n.type);
2479
+ }
2480
+ const sig = sorted.map((n) => n.name).join("\u2192");
2481
+ if (sig) variantMap.set(sig, (variantMap.get(sig) ?? 0) + 1);
2482
+ for (const n of sorted) {
2483
+ if (n.name && n.endTime && n.startTime) {
2484
+ const dur = n.endTime - n.startTime;
2485
+ if (dur > 0) {
2486
+ const arr = durationMap.get(n.name) ?? [];
2487
+ arr.push(dur);
2488
+ durationMap.set(n.name, arr);
2489
+ }
2490
+ }
2491
+ }
2492
+ }
2493
+ const model = {
2494
+ transitions: [...transMap.entries()].map(([key, count]) => {
2495
+ const [from, to] = key.split("|||");
2496
+ return { from, to, count };
2497
+ }),
2498
+ nodeTypes: Object.fromEntries(nodeTypeMap)
2499
+ };
2500
+ const totalTraces = allTraces.length;
2501
+ const variants = [...variantMap.entries()].sort((a, b) => b[1] - a[1]).slice(0, 20).map(([sig, count]) => ({
2502
+ pathSignature: sig,
2503
+ count,
2504
+ percentage: totalTraces > 0 ? count / totalTraces * 100 : 0
2505
+ }));
2506
+ const bottlenecks = [...durationMap.entries()].map(([name, durations]) => {
2507
+ const sorted = durations.sort((a, b) => a - b);
2508
+ const p95 = sorted[Math.floor(sorted.length * 0.95)] ?? 0;
2509
+ return { nodeName: name, nodeType: nodeTypeMap.get(name) ?? "unknown", p95 };
2510
+ }).sort((a, b) => b.p95 - a.p95).slice(0, 15);
2511
+ const graphs = this.getGraphTraces(agentId);
2512
+ if (graphs.length > 0) {
2513
+ try {
2514
+ const coreBottlenecks = (0, import_agentflow_core3.getBottlenecks)(graphs).map((b) => ({
2515
+ nodeName: b.nodeName,
2516
+ nodeType: b.nodeType,
2517
+ p95: b.durations.sort((a, b2) => a - b2)[Math.floor(b.durations.length * 0.95)] ?? 0
2518
+ }));
2519
+ if (coreBottlenecks.length > bottlenecks.length) {
2520
+ bottlenecks.length = 0;
2521
+ bottlenecks.push(...coreBottlenecks);
2522
+ }
2523
+ } catch {
2524
+ }
2525
+ }
2526
+ res.json({ model, variants, bottlenecks });
2527
+ } catch (error) {
2528
+ console.error("Process model error:", error);
2529
+ res.status(500).json({ error: "Failed to compute process model" });
2530
+ }
2531
+ });
1892
2532
  this.app.get("/api/stats/:agentId", (req, res) => {
1893
2533
  try {
1894
2534
  const agentStats = this.stats.getAgentStats(req.params.agentId);
@@ -1901,6 +2541,7 @@ var DashboardServer = class {
1901
2541
  }
1902
2542
  });
1903
2543
  this.app.get("/api/process-health", (_req, res) => {
2544
+ var _a, _b;
1904
2545
  try {
1905
2546
  const now = Date.now();
1906
2547
  if (this.processHealthCache.result && now - this.processHealthCache.ts < 1e4) {
@@ -1911,67 +2552,203 @@ var DashboardServer = class {
1911
2552
  path3.dirname(this.config.tracesDir),
1912
2553
  ...this.config.dataDirs || []
1913
2554
  ];
1914
- const processConfig = (0, import_agentflow_core3.discoverProcessConfig)(discoveryDirs);
1915
- if (!processConfig) {
2555
+ const configs = (0, import_agentflow_core3.discoverAllProcessConfigs)(discoveryDirs);
2556
+ if (configs.length === 0) {
1916
2557
  return res.json(null);
1917
2558
  }
1918
- const alfredResult = (0, import_agentflow_core3.auditProcesses)(processConfig);
1919
- const openclawConfig = {
1920
- processName: "openclaw",
1921
- pidFile: void 0,
1922
- workersFile: void 0,
1923
- systemdUnit: null
1924
- };
1925
- const openclawResult = (0, import_agentflow_core3.auditProcesses)(openclawConfig);
1926
- const clawmetryConfig = {
1927
- processName: "clawmetry",
1928
- pidFile: void 0,
1929
- workersFile: void 0,
1930
- systemdUnit: null
1931
- };
1932
- const clawmetryResult = (0, import_agentflow_core3.auditProcesses)(clawmetryConfig);
1933
- const allOsProcesses = [
1934
- ...alfredResult.osProcesses,
1935
- ...openclawResult.osProcesses,
1936
- ...clawmetryResult.osProcesses
1937
- ];
2559
+ const services = [];
2560
+ const allKnownPids = /* @__PURE__ */ new Set();
2561
+ for (const config of configs) {
2562
+ const audit = (0, import_agentflow_core3.auditProcesses)(config);
2563
+ services.push({ name: config.processName, audit });
2564
+ if (((_a = audit.pidFile) == null ? void 0 : _a.pid) && !audit.pidFile.stale) allKnownPids.add(audit.pidFile.pid);
2565
+ if ((_b = audit.systemd) == null ? void 0 : _b.mainPid) allKnownPids.add(audit.systemd.mainPid);
2566
+ if (audit.workers) {
2567
+ if (audit.workers.orchestratorPid) allKnownPids.add(audit.workers.orchestratorPid);
2568
+ for (const w of audit.workers.workers) {
2569
+ if (w.pid) allKnownPids.add(w.pid);
2570
+ }
2571
+ }
2572
+ for (const p of audit.osProcesses) allKnownPids.add(p.pid);
2573
+ }
2574
+ const primary = services.find((s) => s.audit.pidFile) ?? services[0];
2575
+ const allOsProcesses = services.flatMap((s) => s.audit.osProcesses);
1938
2576
  const uniqueProcesses = allOsProcesses.filter(
1939
2577
  (proc, index, arr) => arr.findIndex((p) => p.pid === proc.pid) === index
1940
2578
  );
2579
+ const orphans = uniqueProcesses.filter(
2580
+ (p) => !allKnownPids.has(p.pid) && p.pid !== process.pid && p.pid !== process.ppid
2581
+ );
2582
+ const problems = services.flatMap(
2583
+ (s) => s.audit.problems.map((p) => `[${s.name}] ${p}`)
2584
+ );
1941
2585
  const result = {
1942
- ...alfredResult,
2586
+ // Backward-compatible fields from primary service
2587
+ pidFile: (primary == null ? void 0 : primary.audit.pidFile) ?? null,
2588
+ systemd: (primary == null ? void 0 : primary.audit.systemd) ?? null,
2589
+ workers: (primary == null ? void 0 : primary.audit.workers) ?? null,
1943
2590
  osProcesses: uniqueProcesses,
1944
- // Recalculate orphans based on all processes
1945
- orphans: uniqueProcesses.filter((p) => {
1946
- var _a;
1947
- const alfredKnownPids = /* @__PURE__ */ new Set();
1948
- if (((_a = alfredResult.pidFile) == null ? void 0 : _a.pid) && !alfredResult.pidFile.stale)
1949
- alfredKnownPids.add(alfredResult.pidFile.pid);
1950
- if (alfredResult.workers) {
1951
- if (alfredResult.workers.orchestratorPid)
1952
- alfredKnownPids.add(alfredResult.workers.orchestratorPid);
1953
- for (const w of alfredResult.workers.workers) {
1954
- if (w.pid) alfredKnownPids.add(w.pid);
2591
+ orphans,
2592
+ problems,
2593
+ // All discovered services with their individual audit results + metrics
2594
+ services: services.map((s) => {
2595
+ var _a2, _b2;
2596
+ const mainPid = ((_a2 = s.audit.pidFile) == null ? void 0 : _a2.pid) ?? ((_b2 = s.audit.systemd) == null ? void 0 : _b2.mainPid);
2597
+ const osProc = mainPid ? uniqueProcesses.find((p) => p.pid === mainPid) : void 0;
2598
+ return {
2599
+ name: s.name,
2600
+ pidFile: s.audit.pidFile,
2601
+ systemd: s.audit.systemd,
2602
+ workers: s.audit.workers,
2603
+ problems: s.audit.problems,
2604
+ metrics: osProc ? { cpu: osProc.cpu, mem: osProc.mem, elapsed: osProc.elapsed } : void 0
2605
+ };
2606
+ }),
2607
+ // Topology edges: parent-child relationships from process ppid
2608
+ topology: uniqueProcesses.map((p) => {
2609
+ try {
2610
+ const statusContent = fs3.readFileSync(`/proc/${p.pid}/status`, "utf8");
2611
+ const ppidMatch = statusContent.match(/^PPid:\s+(\d+)/m);
2612
+ const ppid = ppidMatch ? parseInt(ppidMatch[1] ?? "0", 10) : 0;
2613
+ if (ppid > 1 && allKnownPids.has(ppid)) {
2614
+ return { source: ppid, target: p.pid };
1955
2615
  }
2616
+ } catch {
1956
2617
  }
1957
- const isOpenClawProcess = p.cmdline.includes("openclaw") || p.cmdline.includes("clawmetry");
1958
- return !alfredKnownPids.has(p.pid) && !isOpenClawProcess && p.pid !== process.pid && p.pid !== process.ppid;
1959
- })
2618
+ return null;
2619
+ }).filter(Boolean)
1960
2620
  };
1961
- const openclawProblems = [];
1962
- if (openclawResult.osProcesses.length === 0) {
1963
- openclawProblems.push("No OpenClaw gateway processes detected");
1964
- }
1965
- if (clawmetryResult.osProcesses.length === 0) {
1966
- openclawProblems.push("No clawmetry processes detected");
1967
- }
1968
- result.problems = [...alfredResult.problems || [], ...openclawProblems];
1969
2621
  this.processHealthCache = { result, ts: now };
1970
2622
  res.json(result);
1971
2623
  } catch (_error) {
1972
2624
  res.status(500).json({ error: "Failed to audit processes" });
1973
2625
  }
1974
2626
  });
2627
+ this.app.get("/api/directories", (_req, res) => {
2628
+ try {
2629
+ const home = process.env.HOME ?? "/home/trader";
2630
+ const configPath = path3.join(home, ".agentflow/dashboard-config.json");
2631
+ let extraDirs = [];
2632
+ try {
2633
+ if (fs3.existsSync(configPath)) {
2634
+ const cfg = JSON.parse(fs3.readFileSync(configPath, "utf-8"));
2635
+ extraDirs = cfg.extraDirs ?? [];
2636
+ }
2637
+ } catch {
2638
+ }
2639
+ const watched = [
2640
+ this.config.tracesDir,
2641
+ ...this.config.dataDirs || [],
2642
+ ...extraDirs
2643
+ ];
2644
+ const discovered = [];
2645
+ try {
2646
+ const { execSync } = require("child_process");
2647
+ const raw = execSync(
2648
+ "systemctl --user show --property=ExecStart --no-pager alfred.service openclaw-gateway.service 2>/dev/null",
2649
+ { encoding: "utf8", timeout: 5e3 }
2650
+ );
2651
+ for (const line of raw.split("\n")) {
2652
+ const match = line.match(/path=([^\s;]+)/);
2653
+ if (match == null ? void 0 : match[1]) {
2654
+ const dir = path3.dirname(match[1]);
2655
+ if (fs3.existsSync(dir)) discovered.push(dir);
2656
+ }
2657
+ }
2658
+ } catch {
2659
+ }
2660
+ const commonPaths = [
2661
+ path3.join(home, ".alfred/traces"),
2662
+ path3.join(home, ".alfred/data"),
2663
+ path3.join(home, ".openclaw/workspace/traces"),
2664
+ path3.join(home, ".openclaw/subagents"),
2665
+ path3.join(home, ".openclaw/cron/runs"),
2666
+ path3.join(home, ".openclaw/cron"),
2667
+ path3.join(home, ".openclaw/agents/main/sessions"),
2668
+ path3.join(home, ".agentflow/traces")
2669
+ ];
2670
+ for (const p of commonPaths) {
2671
+ if (fs3.existsSync(p) && !discovered.includes(p)) {
2672
+ discovered.push(p);
2673
+ }
2674
+ }
2675
+ const watchedSet = new Set(watched.map((w) => path3.resolve(w)));
2676
+ const suggested = discovered.filter((d) => !watchedSet.has(path3.resolve(d)));
2677
+ res.json({ watched, discovered, suggested });
2678
+ } catch (error) {
2679
+ console.error("Directory discovery error:", error);
2680
+ res.status(500).json({ error: "Failed to discover directories" });
2681
+ }
2682
+ });
2683
+ this.app.post("/api/directories", import_express.default.json(), (req, res) => {
2684
+ try {
2685
+ const { add, remove } = req.body;
2686
+ if (add && !fs3.existsSync(add)) {
2687
+ return res.status(400).json({ error: `Directory does not exist: ${add}` });
2688
+ }
2689
+ const configPath = path3.join(process.env.HOME ?? "/home/trader", ".agentflow/dashboard-config.json");
2690
+ let config = {};
2691
+ try {
2692
+ if (fs3.existsSync(configPath)) {
2693
+ config = JSON.parse(fs3.readFileSync(configPath, "utf-8"));
2694
+ }
2695
+ } catch {
2696
+ }
2697
+ if (!config.extraDirs) config.extraDirs = [];
2698
+ if (add && !config.extraDirs.includes(add)) {
2699
+ config.extraDirs.push(add);
2700
+ }
2701
+ if (remove) {
2702
+ config.extraDirs = config.extraDirs.filter((d) => d !== remove);
2703
+ }
2704
+ fs3.mkdirSync(path3.dirname(configPath), { recursive: true });
2705
+ fs3.writeFileSync(configPath, JSON.stringify(config, null, 2));
2706
+ res.json({ ok: true, extraDirs: config.extraDirs });
2707
+ } catch (error) {
2708
+ console.error("Directory config error:", error);
2709
+ res.status(500).json({ error: "Failed to update directory config" });
2710
+ }
2711
+ });
2712
+ this.app.post("/v1/traces", import_express.default.json({ limit: "10mb" }), (req, res) => {
2713
+ try {
2714
+ const traces = parseOtlpPayload(req.body);
2715
+ let ingested = 0;
2716
+ for (const trace of traces) {
2717
+ const nodes = /* @__PURE__ */ new Map();
2718
+ for (const [id, node] of Object.entries(trace.nodes)) {
2719
+ nodes.set(id, { ...node, state: {} });
2720
+ }
2721
+ const watched = {
2722
+ id: trace.id,
2723
+ rootNodeId: Object.keys(trace.nodes)[0] ?? "",
2724
+ agentId: trace.agentId,
2725
+ name: trace.name,
2726
+ trigger: trace.trigger,
2727
+ startTime: trace.startTime,
2728
+ endTime: trace.endTime,
2729
+ status: trace.status,
2730
+ nodes,
2731
+ edges: [],
2732
+ events: [],
2733
+ metadata: { ...trace.metadata, adapterSource: "otel" },
2734
+ sessionEvents: [],
2735
+ sourceType: "session",
2736
+ filename: `otel-${trace.id}`,
2737
+ lastModified: Date.now(),
2738
+ sourceDir: "http-collector"
2739
+ };
2740
+ this.watcher.traces.set(`otel:${trace.id}`, watched);
2741
+ ingested++;
2742
+ }
2743
+ if (ingested > 0) {
2744
+ this.broadcast({ type: "traces-updated", count: ingested });
2745
+ }
2746
+ res.json({ ok: true, tracesIngested: ingested });
2747
+ } catch (error) {
2748
+ console.error("OTLP collector error:", error);
2749
+ res.status(400).json({ error: "Failed to parse OTLP payload" });
2750
+ }
2751
+ });
1975
2752
  this.app.get("/health", (_req, res) => {
1976
2753
  res.json({
1977
2754
  status: "ok",
@@ -1983,10 +2760,18 @@ var DashboardServer = class {
1983
2760
  this.app.get("/ready", (_req, res) => {
1984
2761
  res.json({ status: "ready" });
1985
2762
  });
2763
+ this.app.get("/v1/*", (_req, res) => {
2764
+ const legacyIndex = path3.join(__dirname, "../public/index.html");
2765
+ if (fs3.existsSync(legacyIndex)) {
2766
+ res.sendFile(legacyIndex);
2767
+ } else {
2768
+ res.status(404).send("Legacy dashboard not found");
2769
+ }
2770
+ });
1986
2771
  this.app.get("*", (_req, res) => {
1987
- const indexPath = path3.join(__dirname, "../public/index.html");
1988
- if (fs3.existsSync(indexPath)) {
1989
- res.sendFile(indexPath);
2772
+ const clientIndex = path3.join(__dirname, "../dist/client/index.html");
2773
+ if (fs3.existsSync(clientIndex)) {
2774
+ res.sendFile(clientIndex);
1990
2775
  } else {
1991
2776
  res.status(404).send("Dashboard not found - public files may not be built");
1992
2777
  }
@@ -2233,21 +3018,21 @@ var DashboardServer = class {
2233
3018
  });
2234
3019
  }
2235
3020
  async start() {
2236
- return new Promise((resolve3) => {
3021
+ return new Promise((resolve4) => {
2237
3022
  const host = this.config.host || "localhost";
2238
3023
  this.server.listen(this.config.port, host, () => {
2239
3024
  console.log(`AgentFlow Dashboard running at http://${host}:${this.config.port}`);
2240
3025
  console.log(`Watching traces in: ${this.config.tracesDir}`);
2241
- resolve3();
3026
+ resolve4();
2242
3027
  });
2243
3028
  });
2244
3029
  }
2245
3030
  async stop() {
2246
- return new Promise((resolve3) => {
3031
+ return new Promise((resolve4) => {
2247
3032
  this.watcher.stop();
2248
3033
  this.server.close(() => {
2249
3034
  console.log("Dashboard server stopped");
2250
- resolve3();
3035
+ resolve4();
2251
3036
  });
2252
3037
  });
2253
3038
  }