morpheus-cli 0.9.32 → 0.9.40

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 (62) hide show
  1. package/dist/channels/telegram.js +1 -1
  2. package/dist/cli/commands/start.js +7 -0
  3. package/dist/config/paths.js +1 -0
  4. package/dist/config/schemas.js +7 -0
  5. package/dist/http/api.js +5 -0
  6. package/dist/http/routers/model-presets.js +169 -0
  7. package/dist/http/routers/oauth.js +93 -0
  8. package/dist/http/server.js +4 -0
  9. package/dist/runtime/memory/sati/service.js +13 -3
  10. package/dist/runtime/memory/sqlite.js +162 -20
  11. package/dist/runtime/oauth/manager.js +218 -0
  12. package/dist/runtime/oauth/provider.js +90 -0
  13. package/dist/runtime/oauth/store.js +118 -0
  14. package/dist/runtime/oauth/types.js +1 -0
  15. package/dist/runtime/oracle.js +18 -7
  16. package/dist/runtime/providers/factory.js +93 -1
  17. package/dist/runtime/tasks/event-bus.js +11 -0
  18. package/dist/runtime/tasks/notifier.js +57 -31
  19. package/dist/runtime/tasks/repository.js +21 -0
  20. package/dist/runtime/tasks/worker.js +11 -7
  21. package/dist/runtime/tools/cache.js +66 -47
  22. package/dist/ui/assets/{AuditDashboard-rap15I-4.js → AuditDashboard-EvtKjy5H.js} +1 -1
  23. package/dist/ui/assets/{Chat-CnuRZFBT.js → Chat-yptierPt.js} +3 -3
  24. package/dist/ui/assets/{Chronos-C81_HP6e.js → Chronos-BA77MYbp.js} +1 -1
  25. package/dist/ui/assets/{ConfirmationModal-CT_v8cAi.js → ConfirmationModal-NOZr-ipQ.js} +1 -1
  26. package/dist/ui/assets/{Dashboard-0VfNJ9BZ.js → Dashboard-ly1MJiB4.js} +1 -1
  27. package/dist/ui/assets/{DeleteConfirmationModal-P2foiqon.js → DeleteConfirmationModal-2HMraacH.js} +1 -1
  28. package/dist/ui/assets/{Documents-C8UfbcGD.js → Documents-C31fAm0Z.js} +2 -2
  29. package/dist/ui/assets/{Logs-qdsCW9u9.js → Logs-BiajoLAB.js} +1 -1
  30. package/dist/ui/assets/{MCPManager-CaZLnrKz.js → MCPManager-DS9jfiZT.js} +1 -1
  31. package/dist/ui/assets/ModelPresets-CxhKcalw.js +1 -0
  32. package/dist/ui/assets/{ModelPricing-C73OfGhc.js → ModelPricing-CN8flHnP.js} +1 -1
  33. package/dist/ui/assets/{Notifications-CwqeagwF.js → Notifications-BfP1_CM3.js} +1 -1
  34. package/dist/ui/assets/{Pagination-3P6KG-u6.js → Pagination-Doam4_qd.js} +1 -1
  35. package/dist/ui/assets/SatiMemories-Bk4_ubo7.js +1 -0
  36. package/dist/ui/assets/{SessionAudit-Cykp4Sv_.js → SessionAudit-D3E6QSQw.js} +2 -2
  37. package/dist/ui/assets/Settings-3VBK8muv.js +49 -0
  38. package/dist/ui/assets/{Skills-B6io4GZh.js → Skills-Dp0_GwiW.js} +1 -1
  39. package/dist/ui/assets/{Smiths-XoDzX1K0.js → Smiths-COTgI2R4.js} +1 -1
  40. package/dist/ui/assets/{Tasks-vui0C_76.js → Tasks-COe4lIJ7.js} +1 -1
  41. package/dist/ui/assets/{TrinityDatabases-Dp71dyUn.js → TrinityDatabases-BEU4mmyW.js} +1 -1
  42. package/dist/ui/assets/{UsageStats-Dz4LXfr4.js → UsageStats-BTmDeG2V.js} +1 -1
  43. package/dist/ui/assets/{WebhookManager-CC4Mbo2v.js → WebhookManager-FQVyKyW-.js} +2 -2
  44. package/dist/ui/assets/{agents-DV1oGA7P.js → agents-B6e9N0QI.js} +1 -1
  45. package/dist/ui/assets/{audit-DnegNntR.js → audit-giQG2WRk.js} +1 -1
  46. package/dist/ui/assets/{chronos-BDlP8kzg.js → chronos-sweaRcNj.js} +1 -1
  47. package/dist/ui/assets/{config-BhjCL4aM.js → config-CbUdj76n.js} +1 -1
  48. package/dist/ui/assets/index-CRPT77Yo.css +1 -0
  49. package/dist/ui/assets/{index-C3qfojVn.js → index-yu2c4ry1.js} +7 -7
  50. package/dist/ui/assets/{mcp-uYhIyjyx.js → mcp-v64BBpUk.js} +1 -1
  51. package/dist/ui/assets/modelPresets-BaNh-gxn.js +1 -0
  52. package/dist/ui/assets/{skills-_9hplz7d.js → skills-ClRXBlVt.js} +1 -1
  53. package/dist/ui/assets/{stats-BwaWi9yN.js → stats-nI-89hEX.js} +1 -1
  54. package/dist/ui/assets/{useCurrency-RBarItCC.js → useCurrency-D5An8I2f.js} +1 -1
  55. package/dist/ui/assets/vendor-icons-LSkmAkBj.js +1 -0
  56. package/dist/ui/index.html +3 -3
  57. package/dist/ui/sw.js +1 -1
  58. package/package.json +1 -1
  59. package/dist/ui/assets/SatiMemories-CVhOdyAk.js +0 -1
  60. package/dist/ui/assets/Settings-DnyG6tDx.js +0 -49
  61. package/dist/ui/assets/index-gx__iEcl.css +0 -1
  62. package/dist/ui/assets/vendor-icons-tocJCdt5.js +0 -1
@@ -1,20 +1,20 @@
1
1
  import { DisplayManager } from '../display.js';
2
2
  import { TaskDispatcher } from './dispatcher.js';
3
3
  import { TaskRepository } from './repository.js';
4
+ import { taskEventBus } from './event-bus.js';
4
5
  export class TaskNotifier {
5
- pollIntervalMs;
6
6
  maxAttempts;
7
7
  staleSendingMs;
8
- notificationGraceMs;
8
+ recoveryPollMs;
9
9
  repository = TaskRepository.getInstance();
10
10
  display = DisplayManager.getInstance();
11
11
  timer = null;
12
- running = false;
12
+ inFlight = new Set(); // task IDs currently being dispatched
13
13
  constructor(opts) {
14
- this.pollIntervalMs = opts?.pollIntervalMs ?? 1200;
15
14
  this.maxAttempts = opts?.maxAttempts ?? 5;
16
15
  this.staleSendingMs = opts?.staleSendingMs ?? 30_000;
17
- this.notificationGraceMs = opts?.notificationGraceMs ?? 2000;
16
+ // Slow poll only for orphan recovery (process restarts, crash scenarios)
17
+ this.recoveryPollMs = opts?.recoveryPollMs ?? 30_000;
18
18
  }
19
19
  start() {
20
20
  if (this.timer)
@@ -26,43 +26,69 @@ export class TaskNotifier {
26
26
  level: 'warning',
27
27
  });
28
28
  }
29
+ // Primary path: event-driven — fires immediately when TaskWorker completes a task
30
+ taskEventBus.on('task:ready', (taskId) => {
31
+ this.dispatchById(taskId);
32
+ });
33
+ // Fallback path: slow poll for orphaned tasks (e.g. completed before notifier started,
34
+ // or process restarted mid-notification)
29
35
  this.timer = setInterval(() => {
30
- void this.tick();
31
- }, this.pollIntervalMs);
32
- this.display.log('Task notifier started.', { source: 'TaskNotifier' });
36
+ void this.recoveryTick();
37
+ }, this.recoveryPollMs);
38
+ this.display.log('Task notifier started (event-driven + 30s recovery poll).', { source: 'TaskNotifier' });
33
39
  }
34
40
  stop() {
41
+ taskEventBus.removeAllListeners('task:ready');
35
42
  if (this.timer) {
36
43
  clearInterval(this.timer);
37
44
  this.timer = null;
38
- this.display.log('Task notifier stopped.', { source: 'TaskNotifier' });
39
45
  }
46
+ this.display.log('Task notifier stopped.', { source: 'TaskNotifier' });
40
47
  }
41
- async tick() {
42
- if (this.running)
48
+ /**
49
+ * Event-driven dispatch: called immediately when a task is marked complete/failed.
50
+ * Uses claimNotificationById to atomically claim — prevents double-dispatch with recovery poll.
51
+ */
52
+ dispatchById(taskId) {
53
+ if (this.inFlight.has(taskId))
43
54
  return;
44
- this.running = true;
45
- try {
46
- const task = this.repository.claimNextNotificationCandidate(this.notificationGraceMs);
55
+ this.inFlight.add(taskId);
56
+ const task = this.repository.claimNotificationById(taskId);
57
+ if (!task) {
58
+ // Already claimed by recovery poll or another path
59
+ this.inFlight.delete(taskId);
60
+ return;
61
+ }
62
+ void this.dispatch(task).finally(() => this.inFlight.delete(taskId));
63
+ }
64
+ /**
65
+ * Fallback recovery: picks up any orphaned completed tasks not yet notified.
66
+ */
67
+ async recoveryTick() {
68
+ // Drain all pending orphans in one recovery sweep
69
+ while (true) {
70
+ const task = this.repository.claimNextNotificationCandidate(0);
47
71
  if (!task)
48
- return;
49
- try {
50
- await TaskDispatcher.onTaskFinished(task);
51
- this.repository.markNotificationSent(task.id);
52
- }
53
- catch (err) {
54
- const latest = this.repository.getTaskById(task.id);
55
- const attempts = (latest?.notify_attempts ?? 0) + 1;
56
- const retry = attempts < this.maxAttempts;
57
- this.repository.markNotificationFailed(task.id, err?.message ?? String(err), retry);
58
- this.display.log(`Task notification failed (${task.id}): ${err?.message ?? err}`, {
59
- source: 'TaskNotifier',
60
- level: retry ? 'warning' : 'error',
61
- });
62
- }
72
+ break;
73
+ if (this.inFlight.has(task.id))
74
+ break; // already being dispatched via event
75
+ await this.dispatch(task);
63
76
  }
64
- finally {
65
- this.running = false;
77
+ }
78
+ async dispatch(task) {
79
+ try {
80
+ await TaskDispatcher.onTaskFinished(task);
81
+ this.repository.markNotificationSent(task.id);
82
+ }
83
+ catch (err) {
84
+ const latest = this.repository.getTaskById(task.id);
85
+ const attempts = (latest?.notify_attempts ?? 0) + 1;
86
+ const retry = attempts < this.maxAttempts;
87
+ this.repository.markNotificationFailed(task.id, err?.message ?? String(err), retry);
88
+ this.display.log(`Task notification failed (${task.id}): ${err?.message ?? err}`, {
89
+ source: 'TaskNotifier',
90
+ level: retry ? 'warning' : 'error',
91
+ });
66
92
  }
67
93
  }
68
94
  }
@@ -393,6 +393,27 @@ export class TaskRepository {
393
393
  `).run(now, now, now - staleMs);
394
394
  return result.changes;
395
395
  }
396
+ /**
397
+ * Atomically claim a specific task for notification by ID.
398
+ * Returns the task record if successfully claimed, null if already claimed or not eligible.
399
+ */
400
+ claimNotificationById(taskId) {
401
+ const tx = this.db.transaction(() => {
402
+ const changed = this.db.prepare(`
403
+ UPDATE tasks
404
+ SET notify_status = 'sending',
405
+ notify_last_error = NULL,
406
+ updated_at = ?
407
+ WHERE id = ?
408
+ AND status IN ('completed', 'failed', 'cancelled')
409
+ AND notify_status = 'pending'
410
+ `).run(Date.now(), taskId);
411
+ if (changed.changes === 0)
412
+ return null;
413
+ return this.getTaskById(taskId);
414
+ });
415
+ return tx();
416
+ }
396
417
  claimNextNotificationCandidate(minFinishedAgeMs = 0) {
397
418
  const now = Date.now();
398
419
  const tx = this.db.transaction(() => {
@@ -3,6 +3,7 @@ import { DisplayManager } from '../display.js';
3
3
  import { SubagentRegistry } from '../subagents/registry.js';
4
4
  import { TaskRepository } from './repository.js';
5
5
  import { AuditRepository } from '../audit/repository.js';
6
+ import { taskEventBus } from './event-bus.js';
6
7
  export class TaskWorker {
7
8
  workerId;
8
9
  pollIntervalMs;
@@ -38,13 +39,14 @@ export class TaskWorker {
38
39
  }
39
40
  }
40
41
  tick() {
41
- if (this.activeTasks.size >= this.maxConcurrent)
42
- return;
43
- const task = this.repository.claimNextPending(this.workerId);
44
- if (!task)
45
- return;
46
- this.activeTasks.add(task.id);
47
- this.executeTask(task).finally(() => this.activeTasks.delete(task.id));
42
+ // Claim as many tasks as concurrency allows per tick
43
+ while (this.activeTasks.size < this.maxConcurrent) {
44
+ const task = this.repository.claimNextPending(this.workerId);
45
+ if (!task)
46
+ break;
47
+ this.activeTasks.add(task.id);
48
+ this.executeTask(task).finally(() => this.activeTasks.delete(task.id));
49
+ }
48
50
  }
49
51
  async executeTask(task) {
50
52
  const audit = AuditRepository.getInstance();
@@ -94,6 +96,7 @@ export class TaskWorker {
94
96
  });
95
97
  }
96
98
  this.display.log(`Task completed: ${task.id}`, { source: 'TaskWorker', level: 'success' });
99
+ taskEventBus.emit('task:ready', task.id);
97
100
  }
98
101
  catch (err) {
99
102
  const latest = this.repository.getTaskById(task.id);
@@ -116,6 +119,7 @@ export class TaskWorker {
116
119
  metadata: { error: errorMessage },
117
120
  });
118
121
  this.display.log(`Task failed: ${task.id} (${errorMessage})`, { source: 'TaskWorker', level: 'error' });
122
+ taskEventBus.emit('task:ready', task.id);
119
123
  }
120
124
  }
121
125
  }
@@ -1,35 +1,8 @@
1
1
  import { MultiServerMCPClient } from "@langchain/mcp-adapters";
2
2
  import { loadMCPConfig } from "../../config/mcp-loader.js";
3
3
  import { DisplayManager } from "../display.js";
4
+ import { OAuthManager } from "../oauth/manager.js";
4
5
  const display = DisplayManager.getInstance();
5
- /** Fields not supported by Google Gemini API */
6
- const UNSUPPORTED_SCHEMA_FIELDS = ['examples', 'additionalInfo', 'default', '$schema'];
7
- /**
8
- * Recursively removes unsupported fields from JSON schema objects.
9
- */
10
- function sanitizeSchema(obj) {
11
- if (obj === null || typeof obj !== 'object')
12
- return obj;
13
- if (Array.isArray(obj))
14
- return obj.map(sanitizeSchema);
15
- const sanitized = {};
16
- for (const [key, value] of Object.entries(obj)) {
17
- if (!UNSUPPORTED_SCHEMA_FIELDS.includes(key)) {
18
- sanitized[key] = sanitizeSchema(value);
19
- }
20
- }
21
- return sanitized;
22
- }
23
- /**
24
- * Wraps a tool to sanitize its schema for Gemini compatibility.
25
- */
26
- function wrapToolWithSanitizedSchema(tool) {
27
- const originalSchema = tool.schema;
28
- if (originalSchema && typeof originalSchema === 'object') {
29
- tool.schema = sanitizeSchema(originalSchema);
30
- }
31
- return tool;
32
- }
33
6
  /** Timeout (ms) for connecting to each MCP server */
34
7
  const MCP_CONNECT_TIMEOUT_MS = 60_000;
35
8
  function connectTimeout(serverName, ms) {
@@ -118,31 +91,31 @@ export class MCPToolCache {
118
91
  source: 'MCPToolCache',
119
92
  meta: { server: serverName, transport: serverConfig.transport }
120
93
  });
121
- const client = new MultiServerMCPClient({
122
- mcpServers: { [serverName]: serverConfig },
123
- onConnectionError: "ignore",
124
- });
125
- const tools = await Promise.race([
126
- client.getTools(),
127
- connectTimeout(serverName, MCP_CONNECT_TIMEOUT_MS),
128
- ]);
129
- // Rename tools with server prefix to avoid collisions
130
- tools.forEach(tool => {
131
- const newName = `${serverName}_${tool.name}`;
132
- Object.defineProperty(tool, "name", { value: newName });
133
- });
134
- // Sanitize schemas for Gemini compatibility
135
- const sanitizedTools = tools.map(wrapToolWithSanitizedSchema);
136
- newTools.push(...sanitizedTools);
94
+ let serverTools;
95
+ if (serverConfig.transport === 'http') {
96
+ // HTTP MCPs: use MCP SDK directly (supports OAuth auto-discovery)
97
+ serverTools = await Promise.race([
98
+ this.loadHttpMcpServer(serverName, serverConfig),
99
+ connectTimeout(serverName, MCP_CONNECT_TIMEOUT_MS),
100
+ ]);
101
+ }
102
+ else {
103
+ // stdio MCPs: use MultiServerMCPClient as before
104
+ serverTools = await Promise.race([
105
+ this.loadStdioMcpServer(serverName, serverConfig),
106
+ connectTimeout(serverName, MCP_CONNECT_TIMEOUT_MS),
107
+ ]);
108
+ }
109
+ newTools.push(...serverTools);
137
110
  newServerInfos.push({
138
111
  name: serverName,
139
- toolCount: sanitizedTools.length,
140
- tools: sanitizedTools,
112
+ toolCount: serverTools.length,
113
+ tools: serverTools,
141
114
  ok: true,
142
115
  loadedAt: new Date(),
143
116
  });
144
117
  const elapsed = Date.now() - serverStart;
145
- display.log(`Loaded ${sanitizedTools.length} tools from '${serverName}' in ${elapsed}ms`, {
118
+ display.log(`Loaded ${serverTools.length} tools from '${serverName}' in ${elapsed}ms`, {
146
119
  level: 'info',
147
120
  source: 'MCPToolCache'
148
121
  });
@@ -174,6 +147,52 @@ export class MCPToolCache {
174
147
  source: 'MCPToolCache'
175
148
  });
176
149
  }
150
+ /**
151
+ * Load tools from an HTTP MCP server using MCP SDK directly.
152
+ * Supports OAuth auto-discovery — if the server returns 401,
153
+ * the SDK triggers authorization and the user gets a link.
154
+ */
155
+ async loadHttpMcpServer(serverName, serverConfig) {
156
+ let oauthManager;
157
+ try {
158
+ oauthManager = OAuthManager.getInstance();
159
+ }
160
+ catch {
161
+ // OAuthManager not initialized (no port yet) — fall back to basic HTTP
162
+ return this.loadViaMultiServerClient(serverName, serverConfig);
163
+ }
164
+ const { tools, authPending } = await oauthManager.connectHttpMcp(serverName, serverConfig.url, serverConfig.oauth2, serverConfig.headers);
165
+ if (authPending) {
166
+ display.log(`MCP '${serverName}': OAuth authorization pending — tools will load after user authorizes`, {
167
+ level: 'info',
168
+ source: 'MCPToolCache',
169
+ });
170
+ return [];
171
+ }
172
+ return tools;
173
+ }
174
+ /**
175
+ * Load tools from a stdio MCP server using MultiServerMCPClient.
176
+ */
177
+ async loadStdioMcpServer(serverName, serverConfig) {
178
+ return this.loadViaMultiServerClient(serverName, serverConfig);
179
+ }
180
+ /**
181
+ * Shared fallback: load tools via @langchain/mcp-adapters MultiServerMCPClient.
182
+ */
183
+ async loadViaMultiServerClient(serverName, serverConfig) {
184
+ const client = new MultiServerMCPClient({
185
+ mcpServers: { [serverName]: serverConfig },
186
+ onConnectionError: "ignore",
187
+ });
188
+ const tools = await client.getTools();
189
+ // Rename tools with server prefix to avoid collisions
190
+ tools.forEach(tool => {
191
+ const newName = `${serverName}_${tool.name}`;
192
+ Object.defineProperty(tool, "name", { value: newName });
193
+ });
194
+ return tools;
195
+ }
177
196
  /**
178
197
  * Force reload tools from MCP servers.
179
198
  * Clears the cache and loads fresh tools.
@@ -1 +1 @@
1
- import{j as e,m as o}from"./vendor-motion-C3CZ8ZlO.js";import{L as E,r as B}from"./vendor-react-DikRIOlj.js";import{a as D}from"./audit-DnegNntR.js";import{u as R}from"./agents-DV1oGA7P.js";import{u as F}from"./useCurrency-RBarItCC.js";import{Y as _,V as O,h as L,i as I,au as v,I as j,o as N,A as z,g as S,ay as U,k as W,N as w,az as V,Q as A,r as P,ak as H}from"./vendor-icons-tocJCdt5.js";import"./vendor-utils-BIYveU_1.js";import"./index-C3qfojVn.js";import"./config-BhjCL4aM.js";function m(r){return r>=1e6?`${(r/1e6).toFixed(1)}M`:r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}function k(r){if(r<1e3)return`${r}ms`;if(r<6e4)return`${(r/1e3).toFixed(1)}s`;const i=Math.floor(r/6e4),l=Math.floor(r%6e4/1e3);return`${i}m ${l}s`}function G(r){return r?new Date(r).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function T(r,i){return i?`${Math.round(r/i*100)}%`:"0%"}function J({data:r,fmtCost:i}){const[l,d]=B.useState(null);if(!r.length)return e.jsx("p",{className:"text-xs text-gray-400 dark:text-matrix-secondary/50 py-4",children:"No activity in the last 30 days."});const s=Math.max(...r.map(a=>a.eventCount),1);return e.jsx("div",{className:"flex items-end gap-0.5 h-24 w-full relative",children:r.map((a,g)=>{const y=Math.max(4,Math.round(a.eventCount/s*88)),p=l===g;return e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end group",onMouseEnter:()=>d(g),onMouseLeave:()=>d(null),children:[p&&e.jsxs("div",{className:"absolute -top-10 left-1/2 -translate-x-1/2 z-10 bg-gray-900 dark:bg-zinc-800 text-white text-[10px] rounded px-2 py-1 whitespace-nowrap pointer-events-none shadow-lg",children:[a.date,": ",a.eventCount," events · ",i(a.estimatedCostUsd)]}),e.jsx("div",{style:{height:y},className:`w-full rounded-t transition-colors ${p?"bg-blue-500 dark:bg-matrix-highlight":"bg-blue-300/70 dark:bg-matrix-highlight/40 group-hover:bg-blue-400 dark:group-hover:bg-matrix-highlight/60"}`})]},a.date)})})}function h({icon:r,label:i,value:l,sub:d,color:s="blue"}){const a={blue:"bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 border-blue-200 dark:border-blue-800/40",green:"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-matrix-highlight border-green-200 dark:border-green-800/40",amber:"bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-800/40",purple:"bg-purple-50 dark:bg-purple-900/20 text-purple-600 dark:text-purple-400 border-purple-200 dark:border-purple-800/40",rose:"bg-rose-50 dark:bg-rose-900/20 text-rose-600 dark:text-rose-400 border-rose-200 dark:border-rose-800/40",teal:"bg-teal-50 dark:bg-teal-900/20 text-teal-600 dark:text-teal-400 border-teal-200 dark:border-teal-800/40"};return e.jsxs("div",{className:`rounded-lg border p-4 flex gap-3 items-start ${a[s]}`,children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:r}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium opacity-70 uppercase tracking-wider mb-0.5",children:i}),e.jsx("p",{className:"text-xl font-bold font-mono leading-tight",children:l}),d&&e.jsx("div",{className:"text-[11px] opacity-60 mt-0.5 leading-snug",children:d})]})]})}function x({title:r,icon:i,children:l}){return e.jsxs("div",{className:"rounded-lg border border-gray-200 dark:border-matrix-primary overflow-hidden bg-white dark:bg-zinc-900 shadow-sm",children:[e.jsxs("div",{className:"px-4 py-3 bg-gray-50 dark:bg-zinc-900 border-b border-gray-200 dark:border-matrix-primary flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-matrix-secondary/70",children:i}),e.jsx("h2",{className:"text-sm font-semibold text-gray-700 dark:text-matrix-secondary uppercase tracking-wider",children:r})]}),e.jsx("div",{className:"p-4",children:l})]})}function M({agent:r}){const{getByKey:i}=R(),l=i(r);return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] font-semibold px-1.5 py-0.5 rounded ${l.badgeClass}`,children:[l.emoji," ",r.toUpperCase()]})}function K({status:r}){const i={active:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-matrix-highlight",paused:"bg-gray-100 text-gray-600 dark:bg-zinc-800 dark:text-matrix-secondary",archived:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",deleted:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",unknown:"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-secondary/60"};return e.jsx("span",{className:`text-[10px] font-semibold uppercase px-1.5 py-0.5 rounded ${i[r]??i.unknown}`,children:r})}const Q={llm_call:e.jsx(v,{size:13}),tool_call:e.jsx(j,{size:13}),mcp_tool:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M3.49994 11.7501L11.6717 3.57855C12.7762 2.47398 14.5672 2.47398 15.6717 3.57855C16.7762 4.68312 16.7762 6.47398 15.6717 7.57855M15.6717 7.57855L9.49994 13.7501M15.6717 7.57855C16.7762 6.47398 18.5672 6.47398 19.6717 7.57855C20.7762 8.68312 20.7762 10.474 19.6717 11.5785L12.7072 18.543C12.3167 18.9335 12.3167 19.5667 12.7072 19.9572L13.9999 21.2499",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M17.4999 9.74921L11.3282 15.921C10.2237 17.0255 8.43272 17.0255 7.32823 15.921C6.22373 14.8164 6.22373 13.0255 7.32823 11.921L13.4999 5.74939",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),memory_recovery:e.jsx(N,{size:13}),memory_persist:e.jsx(N,{size:13}),telephonist:e.jsx(A,{size:13}),skill_loaded:e.jsx(w,{size:13}),chronos_job:e.jsx(S,{size:13}),task_created:e.jsx(H,{size:13}),task_completed:e.jsx(P,{size:13})},Y={llm_call:"text-blue-500 dark:text-blue-400",tool_call:"text-amber-500 dark:text-amber-400",mcp_tool:"text-purple-500 dark:text-purple-400",memory_recovery:"text-emerald-500 dark:text-emerald-400",memory_persist:"text-violet-500 dark:text-violet-400",telephonist:"text-rose-500 dark:text-rose-400",skill_loaded:"text-teal-500 dark:text-teal-400",chronos_job:"text-orange-500 dark:text-orange-400",task_created:"text-gray-500 dark:text-matrix-secondary",task_completed:"text-green-600 dark:text-matrix-highlight"};function Z({eventType:r}){return r==="mcp_tool"?e.jsx("span",{className:"flex-shrink-0 text-purple-500 dark:text-purple-400",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M3.49994 11.7501L11.6717 3.57855C12.7762 2.47398 14.5672 2.47398 15.6717 3.57855C16.7762 4.68312 16.7762 6.47398 15.6717 7.57855M15.6717 7.57855L9.49994 13.7501M15.6717 7.57855C16.7762 6.47398 18.5672 6.47398 19.6717 7.57855C20.7762 8.68312 20.7762 10.474 19.6717 11.5785L12.7072 18.543C12.3167 18.9335 12.3167 19.5667 12.7072 19.9572L13.9999 21.2499",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M17.4999 9.74921L11.3282 15.921C10.2237 17.0255 8.43272 17.0255 7.32823 15.921C6.22373 14.8164 6.22373 13.0255 7.32823 11.921L13.4999 5.74939",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}):e.jsx(j,{size:13,className:"flex-shrink-0 text-amber-500 dark:text-amber-400"})}const q={llm_call:"bg-blue-400 dark:bg-blue-500",tool_call:"bg-amber-400 dark:bg-amber-500",mcp_tool:"bg-purple-400 dark:bg-purple-500",memory_recovery:"bg-emerald-400 dark:bg-emerald-500",memory_persist:"bg-violet-400 dark:bg-violet-500",telephonist:"bg-rose-400 dark:bg-rose-500",skill_loaded:"bg-teal-400 dark:bg-teal-500",chronos_job:"bg-orange-400 dark:bg-orange-500",task_created:"bg-gray-300 dark:bg-matrix-secondary/50",task_completed:"bg-green-400 dark:bg-matrix-highlight/70"},X={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.04}}},c={hidden:{opacity:0,y:12},show:{opacity:1,y:0}},oe=()=>{const{data:r,isLoading:i,mutate:l}=D(),{fmtCost:d}=F();if(i)return e.jsxs("div",{className:"flex items-center justify-center h-64 gap-3 text-gray-400 dark:text-matrix-secondary",children:[e.jsx(_,{size:20,className:"animate-spin"}),e.jsx("span",{className:"text-sm font-mono",children:"Loading audit data…"})]});if(!r)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-2 text-gray-400 dark:text-matrix-secondary",children:[e.jsx(O,{size:24}),e.jsx("span",{className:"text-sm",children:"Failed to load audit data."})]});const{sessions:s,totals:a,byAgent:g,byModel:y,topTools:p,recentSessions:f,dailyActivity:b}=r,C=[["llm_call",a.llmCallCount],["tool_call",a.toolCallCount],["mcp_tool",a.mcpToolCount],["memory_recovery",a.memoryRecoveryCount],["memory_persist",a.memoryPersistCount],["telephonist",a.telephonistCount],["skill_loaded",a.skillCount],["chronos_job",a.chronosJobCount],["task_created",a.taskCreatedCount],["task_completed",a.taskCompletedCount]].filter(([,t])=>t>0).sort((t,n)=>n[1]-t[1]),$=Math.max(...C.map(([,t])=>t),1);return e.jsxs(o.div,{variants:X,initial:"hidden",animate:"show",className:"space-y-6",children:[e.jsxs(o.div,{variants:c,className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/10 dark:bg-blue-500/20 border border-blue-200 dark:border-blue-800/40 flex items-center justify-center",children:e.jsx(L,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 dark:text-matrix-highlight",children:"Global Audit"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-matrix-secondary/60 mt-0.5",children:[s.withAudit," sessions with audit data · ",a.totalEventCount.toLocaleString()," events total"]})]})]}),e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-gray-200 dark:border-matrix-primary text-sm text-gray-500 dark:text-matrix-secondary hover:bg-gray-50 dark:hover:bg-zinc-900 transition-colors",children:[e.jsx(_,{size:14})," Refresh"]})]}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(h,{icon:e.jsx(I,{size:16}),label:"Total Cost",value:d(a.estimatedCostUsd),color:"green"}),e.jsx(h,{icon:e.jsx(v,{size:16}),label:"LLM Calls",value:a.llmCallCount.toLocaleString(),color:"blue"}),e.jsx(h,{icon:e.jsx(j,{size:16}),label:"Tool Calls",value:(a.toolCallCount+a.mcpToolCount).toLocaleString(),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[a.toolCallCount," native"]}),e.jsx("br",{}),e.jsxs("span",{children:[a.mcpToolCount," MCP"]})]}),color:"amber"}),e.jsx(h,{icon:e.jsx(N,{size:16}),label:"Memory Hits",value:a.memoryRecoveryCount.toLocaleString(),color:"teal"}),e.jsx(h,{icon:e.jsx(z,{size:16}),label:"Total Tokens",value:m(a.totalInputTokens+a.totalOutputTokens),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["↑",m(a.totalInputTokens)," in"]}),e.jsx("br",{}),e.jsxs("span",{children:["↓",m(a.totalOutputTokens)," out"]})]}),color:"purple"}),e.jsx(h,{icon:e.jsx(S,{size:16}),label:"Total Time",value:k(a.totalDurationMs),color:"rose"})]}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(x,{title:"Sessions",icon:e.jsx(U,{size:14}),children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[{label:"Total",value:s.total,cls:"text-gray-700 dark:text-matrix-secondary"},{label:"With Audit",value:s.withAudit,cls:"text-blue-600 dark:text-blue-400"},{label:"Active",value:s.active,cls:"text-green-600 dark:text-matrix-highlight"},{label:"Paused",value:s.paused,cls:"text-gray-500 dark:text-matrix-secondary"},{label:"Archived",value:s.archived,cls:"text-amber-600 dark:text-amber-400"},{label:"Deleted",value:s.deleted,cls:"text-red-500 dark:text-red-400"}].map(({label:t,value:n,cls:u})=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50",children:t}),e.jsx("span",{className:`text-2xl font-bold font-mono ${u}`,children:n})]},t))}),s.total>0&&e.jsxs("div",{className:"h-2 rounded-full overflow-hidden flex gap-px",children:[s.active>0&&e.jsx("div",{className:"bg-green-400 dark:bg-matrix-highlight/70",style:{flex:s.active}}),s.paused>0&&e.jsx("div",{className:"bg-gray-300 dark:bg-matrix-primary/50",style:{flex:s.paused}}),s.archived>0&&e.jsx("div",{className:"bg-amber-400 dark:bg-amber-500/70",style:{flex:s.archived}}),s.deleted>0&&e.jsx("div",{className:"bg-red-400 dark:bg-red-500/70",style:{flex:s.deleted}})]})]}),e.jsxs(x,{title:"Activity — Last 30 Days",icon:e.jsx(W,{size:14}),children:[e.jsx(J,{data:b,fmtCost:d}),b.length>0&&e.jsxs("div",{className:"flex gap-4 mt-2 text-[11px] text-gray-400 dark:text-matrix-secondary/50 font-mono",children:[e.jsx("span",{children:b[0]?.date}),e.jsx("span",{className:"flex-1 text-right",children:b[b.length-1]?.date})]})]})]}),e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Events by Type",icon:e.jsx(z,{size:14}),children:e.jsx("div",{className:"space-y-2",children:C.map(([t,n])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-5 flex justify-center ${Y[t]??"text-gray-400"}`,children:Q[t]}),e.jsx("span",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary w-32 flex-shrink-0",children:t}),e.jsx("div",{className:"flex-1 h-2 bg-gray-100 dark:bg-zinc-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${q[t]??"bg-gray-400"}`,style:{width:T(n,$)}})}),e.jsx("span",{className:"text-xs font-mono text-gray-500 dark:text-matrix-secondary w-16 text-right",children:n.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/50 w-10 text-right",children:T(n,a.totalEventCount)})]},t))})})}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(x,{title:"By Agent",icon:e.jsx(w,{size:14}),children:g.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No agent data."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Agent"}),e.jsx("th",{className:"pb-2 text-right",children:"LLM"}),e.jsx("th",{className:"pb-2 text-right",children:"Tools"}),e.jsx("th",{className:"pb-2 text-right",children:"Tokens"}),e.jsx("th",{className:"pb-2 text-right",children:"Time"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:g.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsx("td",{className:"py-1.5",children:e.jsx(M,{agent:t.agent})}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.llmCalls.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.toolCalls.toLocaleString()}),e.jsxs("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:["↑",m(t.inputTokens)," ↓",m(t.outputTokens)]}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:k(t.totalDurationMs)}),e.jsx("td",{className:"py-1.5 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)})]},t.agent))})]})})}),e.jsx(x,{title:"By Model",icon:e.jsx(v,{size:14}),children:y.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No model data."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Model"}),e.jsx("th",{className:"pb-2 text-right",children:"Calls"}),e.jsx("th",{className:"pb-2 text-right",children:"In"}),e.jsx("th",{className:"pb-2 text-right",children:"Out"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:y.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsxs("td",{className:"py-1.5",children:[e.jsx("div",{className:"text-gray-700 dark:text-matrix-secondary break-all leading-tight",children:t.model}),e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40",children:t.provider})]}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.calls.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:m(t.inputTokens)}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:m(t.outputTokens)}),e.jsx("td",{className:"py-1.5 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)})]},`${t.provider}/${t.model}`))})]})})})]}),p.length>0&&e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Top Tools",icon:e.jsx(j,{size:14}),children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Tool"}),e.jsx("th",{className:"pb-2 text-left",children:"Agent"}),e.jsx("th",{className:"pb-2 text-right",children:"Calls"}),e.jsx("th",{className:"pb-2 text-right",children:"Errors"}),e.jsx("th",{className:"pb-2 text-right",children:"Error rate"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:p.map((t,n)=>{const u=t.count?t.errorCount/t.count:0;return e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsx("td",{className:"py-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Z,{eventType:t.event_type}),e.jsx("span",{className:"text-gray-700 dark:text-matrix-secondary break-all",children:t.tool_name})]})}),e.jsx("td",{className:"py-1.5",children:t.agent?e.jsx(M,{agent:t.agent}):e.jsx("span",{className:"text-gray-400",children:"—"})}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.count.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right",children:e.jsx("span",{className:t.errorCount>0?"text-red-500 dark:text-red-400":"text-gray-400 dark:text-matrix-secondary/50",children:t.errorCount})}),e.jsx("td",{className:"py-1.5 text-right",children:e.jsx("span",{className:u>.1?"text-red-500 dark:text-red-400":u>0?"text-amber-500 dark:text-amber-400":"text-gray-400 dark:text-matrix-secondary/50",children:t.count>0?`${Math.round(u*100)}%`:"—"})})]},n)})})]})})})}),e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Recent Sessions with Audit",icon:e.jsx(L,{size:14}),children:f.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No sessions with audit data yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Session"}),e.jsx("th",{className:"pb-2 text-left",children:"Status"}),e.jsx("th",{className:"pb-2 text-right",children:"Events"}),e.jsx("th",{className:"pb-2 text-right",children:"LLM"}),e.jsx("th",{className:"pb-2 text-right",children:"Duration"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"}),e.jsx("th",{className:"pb-2"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:f.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsxs("td",{className:"py-2",children:[e.jsx("div",{className:"text-gray-700 dark:text-matrix-secondary truncate max-w-[160px]",title:t.title??t.session_id,children:t.title??e.jsxs("span",{className:"text-gray-400 dark:text-matrix-secondary/40 font-mono text-[10px]",children:[t.session_id.slice(0,12),"…"]})}),t.started_at&&e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40",children:G(t.started_at)})]}),e.jsx("td",{className:"py-2",children:e.jsx(K,{status:t.status})}),e.jsx("td",{className:"py-2 text-right text-gray-600 dark:text-matrix-secondary",children:t.event_count.toLocaleString()}),e.jsx("td",{className:"py-2 text-right text-gray-500 dark:text-matrix-secondary/70",children:t.llmCallCount.toLocaleString()}),e.jsx("td",{className:"py-2 text-right text-gray-500 dark:text-matrix-secondary/70",children:k(t.totalDurationMs)}),e.jsx("td",{className:"py-2 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)}),e.jsx("td",{className:"py-2 text-right",children:e.jsx(E,{to:`/sessions/${t.session_id}/audit`,className:"inline-flex items-center gap-1 px-2 py-1 rounded border border-gray-200 dark:border-matrix-primary text-gray-400 dark:text-matrix-secondary hover:text-blue-600 dark:hover:text-matrix-highlight hover:border-blue-300 dark:hover:border-matrix-highlight/50 transition-colors",title:"View session audit",children:e.jsx(V,{size:11})})})]},t.session_id))})]})})})}),a.telephonistCount>0&&e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Audio / Telephonist",icon:e.jsx(A,{size:14}),children:e.jsxs("div",{className:"flex flex-wrap gap-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50 mb-0.5",children:"Calls"}),e.jsx("p",{className:"text-2xl font-bold font-mono text-rose-500 dark:text-rose-400",children:a.telephonistCount.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50 mb-0.5",children:"Total Audio"}),e.jsx("p",{className:"text-2xl font-bold font-mono text-rose-500 dark:text-rose-400",children:a.totalAudioSeconds<60?`${a.totalAudioSeconds.toFixed(1)}s`:`${(a.totalAudioSeconds/60).toFixed(1)}m`})]})]})})})]})};export{oe as AuditDashboard};
1
+ import{j as e,m as o}from"./vendor-motion-C3CZ8ZlO.js";import{L as E,r as B}from"./vendor-react-DikRIOlj.js";import{a as D}from"./audit-giQG2WRk.js";import{u as R}from"./agents-B6e9N0QI.js";import{u as O}from"./useCurrency-D5An8I2f.js";import{Z as _,Y as F,h as L,i as U,aw as v,J as j,p as N,A as z,g as w,aA as W,l as I,O as S,aB as P,U as A,s as V,an as H}from"./vendor-icons-LSkmAkBj.js";import"./vendor-utils-BIYveU_1.js";import"./index-yu2c4ry1.js";import"./config-CbUdj76n.js";function m(r){return r>=1e6?`${(r/1e6).toFixed(1)}M`:r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}function k(r){if(r<1e3)return`${r}ms`;if(r<6e4)return`${(r/1e3).toFixed(1)}s`;const i=Math.floor(r/6e4),l=Math.floor(r%6e4/1e3);return`${i}m ${l}s`}function G(r){return r?new Date(r).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function T(r,i){return i?`${Math.round(r/i*100)}%`:"0%"}function J({data:r,fmtCost:i}){const[l,d]=B.useState(null);if(!r.length)return e.jsx("p",{className:"text-xs text-gray-400 dark:text-matrix-secondary/50 py-4",children:"No activity in the last 30 days."});const s=Math.max(...r.map(a=>a.eventCount),1);return e.jsx("div",{className:"flex items-end gap-0.5 h-24 w-full relative",children:r.map((a,g)=>{const y=Math.max(4,Math.round(a.eventCount/s*88)),p=l===g;return e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end group",onMouseEnter:()=>d(g),onMouseLeave:()=>d(null),children:[p&&e.jsxs("div",{className:"absolute -top-10 left-1/2 -translate-x-1/2 z-10 bg-gray-900 dark:bg-zinc-800 text-white text-[10px] rounded px-2 py-1 whitespace-nowrap pointer-events-none shadow-lg",children:[a.date,": ",a.eventCount," events · ",i(a.estimatedCostUsd)]}),e.jsx("div",{style:{height:y},className:`w-full rounded-t transition-colors ${p?"bg-blue-500 dark:bg-matrix-highlight":"bg-blue-300/70 dark:bg-matrix-highlight/40 group-hover:bg-blue-400 dark:group-hover:bg-matrix-highlight/60"}`})]},a.date)})})}function h({icon:r,label:i,value:l,sub:d,color:s="blue"}){const a={blue:"bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 border-blue-200 dark:border-blue-800/40",green:"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-matrix-highlight border-green-200 dark:border-green-800/40",amber:"bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-800/40",purple:"bg-purple-50 dark:bg-purple-900/20 text-purple-600 dark:text-purple-400 border-purple-200 dark:border-purple-800/40",rose:"bg-rose-50 dark:bg-rose-900/20 text-rose-600 dark:text-rose-400 border-rose-200 dark:border-rose-800/40",teal:"bg-teal-50 dark:bg-teal-900/20 text-teal-600 dark:text-teal-400 border-teal-200 dark:border-teal-800/40"};return e.jsxs("div",{className:`rounded-lg border p-4 flex gap-3 items-start ${a[s]}`,children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:r}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium opacity-70 uppercase tracking-wider mb-0.5",children:i}),e.jsx("p",{className:"text-xl font-bold font-mono leading-tight",children:l}),d&&e.jsx("div",{className:"text-[11px] opacity-60 mt-0.5 leading-snug",children:d})]})]})}function x({title:r,icon:i,children:l}){return e.jsxs("div",{className:"rounded-lg border border-gray-200 dark:border-matrix-primary overflow-hidden bg-white dark:bg-zinc-900 shadow-sm",children:[e.jsxs("div",{className:"px-4 py-3 bg-gray-50 dark:bg-zinc-900 border-b border-gray-200 dark:border-matrix-primary flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-matrix-secondary/70",children:i}),e.jsx("h2",{className:"text-sm font-semibold text-gray-700 dark:text-matrix-secondary uppercase tracking-wider",children:r})]}),e.jsx("div",{className:"p-4",children:l})]})}function M({agent:r}){const{getByKey:i}=R(),l=i(r);return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] font-semibold px-1.5 py-0.5 rounded ${l.badgeClass}`,children:[l.emoji," ",r.toUpperCase()]})}function Z({status:r}){const i={active:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-matrix-highlight",paused:"bg-gray-100 text-gray-600 dark:bg-zinc-800 dark:text-matrix-secondary",archived:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300",deleted:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",unknown:"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-secondary/60"};return e.jsx("span",{className:`text-[10px] font-semibold uppercase px-1.5 py-0.5 rounded ${i[r]??i.unknown}`,children:r})}const K={llm_call:e.jsx(v,{size:13}),tool_call:e.jsx(j,{size:13}),mcp_tool:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M3.49994 11.7501L11.6717 3.57855C12.7762 2.47398 14.5672 2.47398 15.6717 3.57855C16.7762 4.68312 16.7762 6.47398 15.6717 7.57855M15.6717 7.57855L9.49994 13.7501M15.6717 7.57855C16.7762 6.47398 18.5672 6.47398 19.6717 7.57855C20.7762 8.68312 20.7762 10.474 19.6717 11.5785L12.7072 18.543C12.3167 18.9335 12.3167 19.5667 12.7072 19.9572L13.9999 21.2499",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M17.4999 9.74921L11.3282 15.921C10.2237 17.0255 8.43272 17.0255 7.32823 15.921C6.22373 14.8164 6.22373 13.0255 7.32823 11.921L13.4999 5.74939",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),memory_recovery:e.jsx(N,{size:13}),memory_persist:e.jsx(N,{size:13}),telephonist:e.jsx(A,{size:13}),skill_loaded:e.jsx(S,{size:13}),chronos_job:e.jsx(w,{size:13}),task_created:e.jsx(H,{size:13}),task_completed:e.jsx(V,{size:13})},Y={llm_call:"text-blue-500 dark:text-blue-400",tool_call:"text-amber-500 dark:text-amber-400",mcp_tool:"text-purple-500 dark:text-purple-400",memory_recovery:"text-emerald-500 dark:text-emerald-400",memory_persist:"text-violet-500 dark:text-violet-400",telephonist:"text-rose-500 dark:text-rose-400",skill_loaded:"text-teal-500 dark:text-teal-400",chronos_job:"text-orange-500 dark:text-orange-400",task_created:"text-gray-500 dark:text-matrix-secondary",task_completed:"text-green-600 dark:text-matrix-highlight"};function q({eventType:r}){return r==="mcp_tool"?e.jsx("span",{className:"flex-shrink-0 text-purple-500 dark:text-purple-400",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M3.49994 11.7501L11.6717 3.57855C12.7762 2.47398 14.5672 2.47398 15.6717 3.57855C16.7762 4.68312 16.7762 6.47398 15.6717 7.57855M15.6717 7.57855L9.49994 13.7501M15.6717 7.57855C16.7762 6.47398 18.5672 6.47398 19.6717 7.57855C20.7762 8.68312 20.7762 10.474 19.6717 11.5785L12.7072 18.543C12.3167 18.9335 12.3167 19.5667 12.7072 19.9572L13.9999 21.2499",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M17.4999 9.74921L11.3282 15.921C10.2237 17.0255 8.43272 17.0255 7.32823 15.921C6.22373 14.8164 6.22373 13.0255 7.32823 11.921L13.4999 5.74939",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}):e.jsx(j,{size:13,className:"flex-shrink-0 text-amber-500 dark:text-amber-400"})}const Q={llm_call:"bg-blue-400 dark:bg-blue-500",tool_call:"bg-amber-400 dark:bg-amber-500",mcp_tool:"bg-purple-400 dark:bg-purple-500",memory_recovery:"bg-emerald-400 dark:bg-emerald-500",memory_persist:"bg-violet-400 dark:bg-violet-500",telephonist:"bg-rose-400 dark:bg-rose-500",skill_loaded:"bg-teal-400 dark:bg-teal-500",chronos_job:"bg-orange-400 dark:bg-orange-500",task_created:"bg-gray-300 dark:bg-matrix-secondary/50",task_completed:"bg-green-400 dark:bg-matrix-highlight/70"},X={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.04}}},c={hidden:{opacity:0,y:12},show:{opacity:1,y:0}},oe=()=>{const{data:r,isLoading:i,mutate:l}=D(),{fmtCost:d}=O();if(i)return e.jsxs("div",{className:"flex items-center justify-center h-64 gap-3 text-gray-400 dark:text-matrix-secondary",children:[e.jsx(_,{size:20,className:"animate-spin"}),e.jsx("span",{className:"text-sm font-mono",children:"Loading audit data…"})]});if(!r)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-2 text-gray-400 dark:text-matrix-secondary",children:[e.jsx(F,{size:24}),e.jsx("span",{className:"text-sm",children:"Failed to load audit data."})]});const{sessions:s,totals:a,byAgent:g,byModel:y,topTools:p,recentSessions:f,dailyActivity:b}=r,C=[["llm_call",a.llmCallCount],["tool_call",a.toolCallCount],["mcp_tool",a.mcpToolCount],["memory_recovery",a.memoryRecoveryCount],["memory_persist",a.memoryPersistCount],["telephonist",a.telephonistCount],["skill_loaded",a.skillCount],["chronos_job",a.chronosJobCount],["task_created",a.taskCreatedCount],["task_completed",a.taskCompletedCount]].filter(([,t])=>t>0).sort((t,n)=>n[1]-t[1]),$=Math.max(...C.map(([,t])=>t),1);return e.jsxs(o.div,{variants:X,initial:"hidden",animate:"show",className:"space-y-6",children:[e.jsxs(o.div,{variants:c,className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/10 dark:bg-blue-500/20 border border-blue-200 dark:border-blue-800/40 flex items-center justify-center",children:e.jsx(L,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 dark:text-matrix-highlight",children:"Global Audit"}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-matrix-secondary/60 mt-0.5",children:[s.withAudit," sessions with audit data · ",a.totalEventCount.toLocaleString()," events total"]})]})]}),e.jsxs("button",{onClick:()=>l(),className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-gray-200 dark:border-matrix-primary text-sm text-gray-500 dark:text-matrix-secondary hover:bg-gray-50 dark:hover:bg-zinc-900 transition-colors",children:[e.jsx(_,{size:14})," Refresh"]})]}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(h,{icon:e.jsx(U,{size:16}),label:"Total Cost",value:d(a.estimatedCostUsd),color:"green"}),e.jsx(h,{icon:e.jsx(v,{size:16}),label:"LLM Calls",value:a.llmCallCount.toLocaleString(),color:"blue"}),e.jsx(h,{icon:e.jsx(j,{size:16}),label:"Tool Calls",value:(a.toolCallCount+a.mcpToolCount).toLocaleString(),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[a.toolCallCount," native"]}),e.jsx("br",{}),e.jsxs("span",{children:[a.mcpToolCount," MCP"]})]}),color:"amber"}),e.jsx(h,{icon:e.jsx(N,{size:16}),label:"Memory Hits",value:a.memoryRecoveryCount.toLocaleString(),color:"teal"}),e.jsx(h,{icon:e.jsx(z,{size:16}),label:"Total Tokens",value:m(a.totalInputTokens+a.totalOutputTokens),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["↑",m(a.totalInputTokens)," in"]}),e.jsx("br",{}),e.jsxs("span",{children:["↓",m(a.totalOutputTokens)," out"]})]}),color:"purple"}),e.jsx(h,{icon:e.jsx(w,{size:16}),label:"Total Time",value:k(a.totalDurationMs),color:"rose"})]}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(x,{title:"Sessions",icon:e.jsx(W,{size:14}),children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[{label:"Total",value:s.total,cls:"text-gray-700 dark:text-matrix-secondary"},{label:"With Audit",value:s.withAudit,cls:"text-blue-600 dark:text-blue-400"},{label:"Active",value:s.active,cls:"text-green-600 dark:text-matrix-highlight"},{label:"Paused",value:s.paused,cls:"text-gray-500 dark:text-matrix-secondary"},{label:"Archived",value:s.archived,cls:"text-amber-600 dark:text-amber-400"},{label:"Deleted",value:s.deleted,cls:"text-red-500 dark:text-red-400"}].map(({label:t,value:n,cls:u})=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50",children:t}),e.jsx("span",{className:`text-2xl font-bold font-mono ${u}`,children:n})]},t))}),s.total>0&&e.jsxs("div",{className:"h-2 rounded-full overflow-hidden flex gap-px",children:[s.active>0&&e.jsx("div",{className:"bg-green-400 dark:bg-matrix-highlight/70",style:{flex:s.active}}),s.paused>0&&e.jsx("div",{className:"bg-gray-300 dark:bg-matrix-primary/50",style:{flex:s.paused}}),s.archived>0&&e.jsx("div",{className:"bg-amber-400 dark:bg-amber-500/70",style:{flex:s.archived}}),s.deleted>0&&e.jsx("div",{className:"bg-red-400 dark:bg-red-500/70",style:{flex:s.deleted}})]})]}),e.jsxs(x,{title:"Activity — Last 30 Days",icon:e.jsx(I,{size:14}),children:[e.jsx(J,{data:b,fmtCost:d}),b.length>0&&e.jsxs("div",{className:"flex gap-4 mt-2 text-[11px] text-gray-400 dark:text-matrix-secondary/50 font-mono",children:[e.jsx("span",{children:b[0]?.date}),e.jsx("span",{className:"flex-1 text-right",children:b[b.length-1]?.date})]})]})]}),e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Events by Type",icon:e.jsx(z,{size:14}),children:e.jsx("div",{className:"space-y-2",children:C.map(([t,n])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-5 flex justify-center ${Y[t]??"text-gray-400"}`,children:K[t]}),e.jsx("span",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary w-32 flex-shrink-0",children:t}),e.jsx("div",{className:"flex-1 h-2 bg-gray-100 dark:bg-zinc-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${Q[t]??"bg-gray-400"}`,style:{width:T(n,$)}})}),e.jsx("span",{className:"text-xs font-mono text-gray-500 dark:text-matrix-secondary w-16 text-right",children:n.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/50 w-10 text-right",children:T(n,a.totalEventCount)})]},t))})})}),e.jsxs(o.div,{variants:c,className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(x,{title:"By Agent",icon:e.jsx(S,{size:14}),children:g.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No agent data."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Agent"}),e.jsx("th",{className:"pb-2 text-right",children:"LLM"}),e.jsx("th",{className:"pb-2 text-right",children:"Tools"}),e.jsx("th",{className:"pb-2 text-right",children:"Tokens"}),e.jsx("th",{className:"pb-2 text-right",children:"Time"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:g.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsx("td",{className:"py-1.5",children:e.jsx(M,{agent:t.agent})}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.llmCalls.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.toolCalls.toLocaleString()}),e.jsxs("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:["↑",m(t.inputTokens)," ↓",m(t.outputTokens)]}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:k(t.totalDurationMs)}),e.jsx("td",{className:"py-1.5 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)})]},t.agent))})]})})}),e.jsx(x,{title:"By Model",icon:e.jsx(v,{size:14}),children:y.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No model data."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Model"}),e.jsx("th",{className:"pb-2 text-right",children:"Calls"}),e.jsx("th",{className:"pb-2 text-right",children:"In"}),e.jsx("th",{className:"pb-2 text-right",children:"Out"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:y.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsxs("td",{className:"py-1.5",children:[e.jsx("div",{className:"text-gray-700 dark:text-matrix-secondary break-all leading-tight",children:t.model}),e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40",children:t.provider})]}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.calls.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:m(t.inputTokens)}),e.jsx("td",{className:"py-1.5 text-right text-gray-500 dark:text-matrix-secondary/70",children:m(t.outputTokens)}),e.jsx("td",{className:"py-1.5 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)})]},`${t.provider}/${t.model}`))})]})})})]}),p.length>0&&e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Top Tools",icon:e.jsx(j,{size:14}),children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Tool"}),e.jsx("th",{className:"pb-2 text-left",children:"Agent"}),e.jsx("th",{className:"pb-2 text-right",children:"Calls"}),e.jsx("th",{className:"pb-2 text-right",children:"Errors"}),e.jsx("th",{className:"pb-2 text-right",children:"Error rate"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:p.map((t,n)=>{const u=t.count?t.errorCount/t.count:0;return e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsx("td",{className:"py-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(q,{eventType:t.event_type}),e.jsx("span",{className:"text-gray-700 dark:text-matrix-secondary break-all",children:t.tool_name})]})}),e.jsx("td",{className:"py-1.5",children:t.agent?e.jsx(M,{agent:t.agent}):e.jsx("span",{className:"text-gray-400",children:"—"})}),e.jsx("td",{className:"py-1.5 text-right text-gray-600 dark:text-matrix-secondary",children:t.count.toLocaleString()}),e.jsx("td",{className:"py-1.5 text-right",children:e.jsx("span",{className:t.errorCount>0?"text-red-500 dark:text-red-400":"text-gray-400 dark:text-matrix-secondary/50",children:t.errorCount})}),e.jsx("td",{className:"py-1.5 text-right",children:e.jsx("span",{className:u>.1?"text-red-500 dark:text-red-400":u>0?"text-amber-500 dark:text-amber-400":"text-gray-400 dark:text-matrix-secondary/50",children:t.count>0?`${Math.round(u*100)}%`:"—"})})]},n)})})]})})})}),e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Recent Sessions with Audit",icon:e.jsx(L,{size:14}),children:f.length===0?e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/50",children:"No sessions with audit data yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50 border-b border-gray-100 dark:border-matrix-primary/30",children:[e.jsx("th",{className:"pb-2 text-left",children:"Session"}),e.jsx("th",{className:"pb-2 text-left",children:"Status"}),e.jsx("th",{className:"pb-2 text-right",children:"Events"}),e.jsx("th",{className:"pb-2 text-right",children:"LLM"}),e.jsx("th",{className:"pb-2 text-right",children:"Duration"}),e.jsx("th",{className:"pb-2 text-right",children:"Cost"}),e.jsx("th",{className:"pb-2"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 dark:divide-matrix-primary/20",children:f.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/50",children:[e.jsxs("td",{className:"py-2",children:[e.jsx("div",{className:"text-gray-700 dark:text-matrix-secondary truncate max-w-[160px]",title:t.title??t.session_id,children:t.title??e.jsxs("span",{className:"text-gray-400 dark:text-matrix-secondary/40 font-mono text-[10px]",children:[t.session_id.slice(0,12),"…"]})}),t.started_at&&e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40",children:G(t.started_at)})]}),e.jsx("td",{className:"py-2",children:e.jsx(Z,{status:t.status})}),e.jsx("td",{className:"py-2 text-right text-gray-600 dark:text-matrix-secondary",children:t.event_count.toLocaleString()}),e.jsx("td",{className:"py-2 text-right text-gray-500 dark:text-matrix-secondary/70",children:t.llmCallCount.toLocaleString()}),e.jsx("td",{className:"py-2 text-right text-gray-500 dark:text-matrix-secondary/70",children:k(t.totalDurationMs)}),e.jsx("td",{className:"py-2 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:d(t.estimatedCostUsd)}),e.jsx("td",{className:"py-2 text-right",children:e.jsx(E,{to:`/sessions/${t.session_id}/audit`,className:"inline-flex items-center gap-1 px-2 py-1 rounded border border-gray-200 dark:border-matrix-primary text-gray-400 dark:text-matrix-secondary hover:text-blue-600 dark:hover:text-matrix-highlight hover:border-blue-300 dark:hover:border-matrix-highlight/50 transition-colors",title:"View session audit",children:e.jsx(P,{size:11})})})]},t.session_id))})]})})})}),a.telephonistCount>0&&e.jsx(o.div,{variants:c,children:e.jsx(x,{title:"Audio / Telephonist",icon:e.jsx(A,{size:14}),children:e.jsxs("div",{className:"flex flex-wrap gap-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50 mb-0.5",children:"Calls"}),e.jsx("p",{className:"text-2xl font-bold font-mono text-rose-500 dark:text-rose-400",children:a.telephonistCount.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-gray-400 dark:text-matrix-secondary/50 mb-0.5",children:"Total Audio"}),e.jsx("p",{className:"text-2xl font-bold font-mono text-rose-500 dark:text-rose-400",children:a.totalAudioSeconds<60?`${a.totalAudioSeconds.toFixed(1)}s`:`${(a.totalAudioSeconds/60).toFixed(1)}m`})]})]})})})]})};export{oe as AuditDashboard};
@@ -1,7 +1,7 @@
1
- import{j as e,A as H,m as X}from"./vendor-motion-C3CZ8ZlO.js";import{c as te,r as a,R as F}from"./vendor-react-DikRIOlj.js";import{u as ae,v as U,w as se,x as ne,X as Q,y as ie,z as oe,E as le,G as de,I as ce,s as V,J as Y,t as Z,K as W,o as xe,M as me,N as B,O as he,e as ue,g as pe,Q as ge,U as be}from"./vendor-icons-tocJCdt5.js";import{h as ye,g as fe,i as ke,a as R}from"./index-C3qfojVn.js";import{u as ee}from"./agents-DV1oGA7P.js";import{M as je,r as ve}from"./vendor-markdown-BN_Np5Ta.js";import{C as we}from"./ConfirmationModal-CT_v8cAi.js";import"./vendor-utils-BIYveU_1.js";function Ne(r){const o=Date.now()-r;return o<6e4?"just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:new Date(r).toLocaleDateString()}const Se=({sessions:r,activeSessionId:o,onSelectSession:s,onCreateSession:x,onArchiveSession:u,onDeleteSession:n,onRenameSession:p,isOpen:b,toggleSidebar:m})=>{const g=te(),[c,S]=a.useState(null),[y,C]=a.useState(""),v=a.useRef(null);a.useEffect(()=>{c&&v.current&&v.current.focus()},[c]);const z=(l,k)=>{l.stopPropagation(),S(k.id),C(k.title||"Untitled Session")},I=l=>{l?.stopPropagation(),c&&y.trim()&&(p(c,y.trim()),S(null))},M=l=>{l?.stopPropagation(),S(null)},D=l=>{l.key==="Enter"?I():l.key==="Escape"&&M()};return b?e.jsxs("div",{className:"w-72 bg-white dark:bg-black border-r border-gray-300 dark:border-matrix-primary flex flex-col h-full shrink-0 transition-colors duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-300 dark:border-matrix-primary shrink-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-800 dark:text-matrix-highlight",children:"Sessions"}),e.jsx("button",{onClick:m,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-matrix-primary/20 text-gray-400 dark:text-matrix-secondary/60 transition-colors",title:"Collapse sidebar",children:e.jsx(se,{size:16})})]}),e.jsx("div",{className:"px-3 py-2.5 shrink-0",children:e.jsxs("button",{onClick:x,className:"w-full flex items-center justify-center gap-2 bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black py-2 px-4 rounded-xl hover:bg-azure-secondary dark:hover:bg-matrix-secondary transition-colors text-sm font-medium shadow-sm",children:[e.jsx(U,{size:16}),"New Chat"]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:[r.length===0&&e.jsx("div",{className:"text-center text-gray-400 dark:text-matrix-secondary/40 mt-12 text-sm px-4",children:"No sessions yet. Start a new chat!"}),r.map(l=>{const k=o===l.id,A=c===l.id;return e.jsxs("div",{onClick:()=>!A&&s(l.id),className:`
1
+ import{j as e,A as H,m as V}from"./vendor-motion-C3CZ8ZlO.js";import{c as te,r as a,R as F}from"./vendor-react-DikRIOlj.js";import{v as ae,w as U,x as se,y as ne,X,z as ie,E as oe,G as le,I as de,J as ce,t as Q,K as Y,u as Z,N as W,p as xe,M as me,O as B,Q as he,e as ue,g as pe,U as ge,V as be}from"./vendor-icons-LSkmAkBj.js";import{h as ye,g as fe,i as ke,a as R}from"./index-yu2c4ry1.js";import{u as ee}from"./agents-B6e9N0QI.js";import{M as je,r as ve}from"./vendor-markdown-BN_Np5Ta.js";import{C as we}from"./ConfirmationModal-NOZr-ipQ.js";import"./vendor-utils-BIYveU_1.js";function Ne(r){const o=Date.now()-r;return o<6e4?"just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:o<6048e5?`${Math.floor(o/864e5)}d ago`:new Date(r).toLocaleDateString()}const Se=({sessions:r,activeSessionId:o,onSelectSession:s,onCreateSession:x,onArchiveSession:u,onDeleteSession:n,onRenameSession:p,isOpen:b,toggleSidebar:m})=>{const g=te(),[c,S]=a.useState(null),[y,C]=a.useState(""),v=a.useRef(null);a.useEffect(()=>{c&&v.current&&v.current.focus()},[c]);const z=(l,k)=>{l.stopPropagation(),S(k.id),C(k.title||"Untitled Session")},I=l=>{l?.stopPropagation(),c&&y.trim()&&(p(c,y.trim()),S(null))},M=l=>{l?.stopPropagation(),S(null)},D=l=>{l.key==="Enter"?I():l.key==="Escape"&&M()};return b?e.jsxs("div",{className:"w-72 bg-white dark:bg-black border-r border-gray-300 dark:border-matrix-primary flex flex-col h-full shrink-0 transition-colors duration-300",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-300 dark:border-matrix-primary shrink-0",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-800 dark:text-matrix-highlight",children:"Sessions"}),e.jsx("button",{onClick:m,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-matrix-primary/20 text-gray-400 dark:text-matrix-secondary/60 transition-colors",title:"Collapse sidebar",children:e.jsx(se,{size:16})})]}),e.jsx("div",{className:"px-3 py-2.5 shrink-0",children:e.jsxs("button",{onClick:x,className:"w-full flex items-center justify-center gap-2 bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black py-2 px-4 rounded-xl hover:bg-azure-secondary dark:hover:bg-matrix-secondary transition-colors text-sm font-medium shadow-sm",children:[e.jsx(U,{size:16}),"New Chat"]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:[r.length===0&&e.jsx("div",{className:"text-center text-gray-400 dark:text-matrix-secondary/40 mt-12 text-sm px-4",children:"No sessions yet. Start a new chat!"}),r.map(l=>{const k=o===l.id,A=c===l.id;return e.jsxs("div",{onClick:()=>!A&&s(l.id),className:`
2
2
  group relative flex items-center gap-2 px-3 py-2.5 rounded-xl cursor-pointer transition-all
3
3
  ${k?"bg-azure-primary/10 dark:bg-matrix-primary/15 text-azure-primary dark:text-matrix-highlight":"hover:bg-gray-100 dark:hover:bg-matrix-primary/10 text-gray-700 dark:text-matrix-secondary"}
4
- `,children:[e.jsx("div",{className:"flex-1 min-w-0",children:A?e.jsx("div",{onClick:w=>w.stopPropagation(),children:e.jsx("input",{ref:v,type:"text",value:y,onChange:w=>C(w.target.value),onKeyDown:D,className:"w-full text-sm px-1.5 py-0.5 bg-white dark:bg-black border border-azure-primary dark:border-matrix-highlight rounded-lg focus:outline-none dark:text-matrix-highlight"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-medium truncate leading-snug",children:l.title||"Untitled Session"}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-matrix-secondary/50 mt-0.5",children:Ne(l.last_message_at??l.started_at)})]})}),e.jsx("div",{className:`flex items-center gap-0.5 shrink-0 transition-opacity ${k||A?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:w=>w.stopPropagation(),children:A?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:I,className:"p-1.5 rounded-lg text-emerald-600 hover:bg-emerald-50 dark:text-emerald-400 dark:hover:bg-emerald-900/20 transition-colors",title:"Save",children:e.jsx(ne,{size:13})}),e.jsx("button",{onClick:M,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",title:"Cancel",children:e.jsx(Q,{size:13})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:w=>z(w,l),className:"p-1.5 rounded-lg text-gray-400 hover:text-blue-500 hover:bg-blue-50 dark:text-matrix-secondary/50 dark:hover:text-blue-400 dark:hover:bg-blue-900/20 transition-colors",title:"Rename",children:e.jsx(ie,{size:13})}),e.jsx("button",{onClick:()=>g(`/sessions/${l.id}/audit`),className:"p-1.5 rounded-lg text-gray-400 hover:text-violet-500 hover:bg-violet-50 dark:text-matrix-secondary/50 dark:hover:text-violet-400 dark:hover:bg-violet-900/20 transition-colors",title:"Audit",children:e.jsx(oe,{size:13})}),e.jsx("button",{onClick:()=>u(l.id),className:"p-1.5 rounded-lg text-gray-400 hover:text-amber-500 hover:bg-amber-50 dark:text-matrix-secondary/50 dark:hover:text-amber-400 dark:hover:bg-amber-900/20 transition-colors",title:"Archive",children:e.jsx(le,{size:13})}),e.jsx("button",{onClick:()=>n(l.id),className:"p-1.5 rounded-lg text-gray-400 hover:text-red-500 hover:bg-red-50 dark:text-matrix-secondary/50 dark:hover:text-red-400 dark:hover:bg-red-900/20 transition-colors",title:"Delete",children:e.jsx(de,{size:13})})]})})]},l.id)})]})]}):e.jsxs("div",{className:"w-14 bg-white dark:bg-black border-r border-gray-300 dark:border-matrix-primary flex flex-col items-center py-3 gap-3 shrink-0 transition-colors duration-300",children:[e.jsx("button",{onClick:m,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-matrix-primary/20 text-gray-400 dark:text-matrix-secondary/60 transition-colors",title:"Expand sidebar",children:e.jsx(ae,{size:18})}),e.jsx("div",{className:"w-8 h-px bg-gray-200 dark:bg-matrix-primary/20"}),e.jsx("button",{onClick:x,className:"p-2.5 bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black rounded-xl hover:bg-azure-secondary dark:hover:bg-matrix-secondary shadow-sm transition-colors",title:"New chat",children:e.jsx(U,{size:18})})]})};function K(r){if(r==null)return"";if(typeof r=="string")try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}try{return JSON.stringify(r,null,2)}catch{return String(r)}}const Ce=F.memo(({group:r})=>{const[o,s]=a.useState(!1),x=r.result!==null,u=r.result?.content??"",n=u.startsWith("Error")||u.startsWith("❌");return e.jsxs("div",{className:"rounded-lg border border-gray-300 dark:border-matrix-primary/70 bg-white dark:bg-black overflow-hidden text-sm mb-1",children:[e.jsxs("button",{onClick:()=>s(!o),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-50 dark:hover:bg-zinc-900/60 transition-colors",children:[e.jsx(ce,{size:12,className:"text-amber-500 dark:text-amber-400/80 flex-shrink-0"}),e.jsx("span",{className:"flex-1 font-mono text-xs text-gray-600 dark:text-matrix-secondary/80 truncate",children:r.call.name}),x?n?e.jsx(V,{size:12,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(Y,{size:12,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(Z,{size:12,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx(W,{size:12,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx(H,{initial:!1,children:o&&e.jsx(X.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15,ease:"easeInOut"},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-2.5 pt-1 border-t border-gray-100 dark:border-matrix-primary/20 space-y-2",children:[Object.keys(r.call.args??{}).length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"args"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-gray-50 dark:bg-zinc-900 rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-36 overflow-y-auto",children:K(r.call.args)})]}),x&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"result"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-gray-50 dark:bg-zinc-900 rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-44 overflow-y-auto",children:K(u)})]})]})})})]})});function J(r){return r?.task??r?.prompt??""}function ze(r){if(typeof r!="string")return String(r);try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}}const Me=F.memo(({group:r})=>{const[o,s]=a.useState(!1),{getByToolName:x}=ee(),u=x(r.call.name),n={label:u.label,emoji:u.emoji,colorClass:u.colorClass,bgClass:u.bgClass},p=r.result!==null,b=r.result?.content??"",m=b.startsWith("❌")||b.toLowerCase().startsWith("error"),g=J(r.call.args).slice(0,100),c=r.call.args?.smith??null;return e.jsxs("div",{className:`rounded-lg border border-gray-300 dark:border-matrix-primary/70 overflow-hidden text-sm mb-1 ${n.bgClass}`,children:[e.jsxs("button",{onClick:()=>s(!o),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:brightness-95 dark:hover:brightness-110 transition-all",children:[e.jsx("span",{className:"text-base flex-shrink-0 leading-none",children:n.emoji}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:`text-xs font-semibold ${n.colorClass}`,children:[n.label,c?` · ${c}`:""]}),g&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-matrix-secondary/60 truncate mt-0.5",children:g})]}),p?m?e.jsx(V,{size:14,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(Y,{size:14,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(Z,{size:14,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx(W,{size:13,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx(H,{initial:!1,children:o&&e.jsx(X.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.18,ease:"easeInOut"},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-2.5 pt-1 border-t border-gray-200 dark:border-matrix-primary/20 space-y-2",children:[J(r.call.args)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"task"}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-matrix-secondary/80 bg-white dark:bg-black rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 whitespace-pre-wrap",children:J(r.call.args)})]}),p&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"result"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-white dark:bg-black rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-56 overflow-y-auto",children:ze(b)})]})]})})})]})});function Ee(r){return r==null||r===0?null:r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function q(r){return r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}const Ae=F.memo(({message:r})=>{const o=r.usage_metadata,s=o?.input_tokens??o?.prompt_tokens??0,x=o?.output_tokens??o?.completion_tokens??0,u=s>0||x>0,n=Ee(r.duration_ms),p=r.model,b=r.sati_memories_count??null;if(!u&&!n&&!p&&b==null)return null;const m=p?(p.includes(":")?p.split(":").pop():p)?.split("-").slice(0,4).join("-")??p:null;return e.jsxs("div",{className:"mt-2 pt-1.5 border-t border-gray-100 dark:border-matrix-primary/20 flex flex-wrap items-center gap-x-3 gap-y-0.5",children:[m&&e.jsx("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40 truncate max-w-[180px]",title:p??"",children:m}),u&&e.jsxs("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:["↑",q(s)," ↓",q(x)]}),n&&e.jsx("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:n}),b!=null&&b>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-mono text-purple-400 dark:text-purple-400/70",children:[e.jsx(xe,{size:10}),b]})]})}),G={amber:"bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-900/30 dark:text-amber-300 dark:border-amber-700/60",purple:"bg-purple-100 text-purple-800 border-purple-300 dark:bg-purple-900/30 dark:text-purple-300 dark:border-purple-700/60",violet:"bg-violet-100 text-violet-800 border-violet-300 dark:bg-violet-900/30 dark:text-violet-300 dark:border-violet-700/60",teal:"bg-teal-100 text-teal-800 border-teal-300 dark:bg-teal-900/30 dark:text-teal-300 dark:border-teal-700/60",gray:"bg-zinc-100 text-zinc-700 border-zinc-300 dark:bg-zinc-800 dark:text-zinc-300 dark:border-zinc-600",indigo:"bg-indigo-100 text-indigo-800 border-indigo-300 dark:bg-indigo-900/30 dark:text-indigo-300 dark:border-indigo-700/60"};function De(r){const o=r.replace(/^```json\s*/i,"").replace(/\s*```$/,"");try{return JSON.stringify(JSON.parse(o),null,2)}catch{return o}}function Re(r){return r.session_id?.startsWith("sati-evaluation-")===!0||r.tool_name?.toLowerCase().includes("sati")===!0}const Ie=({message:r})=>{const[o,s]=a.useState(!1),x=Re(r),u=x?r.tool_name==="sati_evaluation_output"?"Sati · memory update":"Sati · analysis":r.tool_name??"tool result";return e.jsxs("details",{open:o,onToggle:n=>s(n.target.open),className:"w-full",children:[e.jsxs("summary",{className:"list-none cursor-pointer select-none flex items-center gap-2 text-xs text-gray-400 dark:text-matrix-secondary/40 hover:text-gray-500 dark:hover:text-matrix-secondary/60 transition-colors py-0.5",children:[e.jsx("div",{className:"flex-1 h-px bg-gray-200 dark:bg-matrix-primary/20"}),e.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap px-2",children:[e.jsx("span",{children:x?"🧠":"🔧"}),e.jsx("span",{children:u}),e.jsx(W,{size:11,className:`transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx("div",{className:"flex-1 h-px bg-gray-200 dark:bg-matrix-primary/20"})]}),o&&e.jsx("pre",{className:"mt-2 px-3 py-2.5 whitespace-pre-wrap break-all text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 border border-gray-300 dark:border-matrix-primary/60 rounded-lg bg-gray-50 dark:bg-zinc-900 max-h-48 overflow-y-auto",children:De(r.content)})]})},Te={table:({children:r})=>e.jsx("div",{className:"my-2 overflow-x-auto rounded-lg border border-gray-200 dark:border-matrix-primary/60",children:e.jsx("table",{className:"min-w-full text-xs border-collapse",children:r})}),thead:({children:r})=>e.jsx("thead",{className:"bg-gray-100 dark:bg-zinc-900 text-gray-600 dark:text-matrix-secondary/70",children:r}),tbody:({children:r})=>e.jsx("tbody",{className:"divide-y divide-gray-100 dark:divide-matrix-primary/20",children:r}),tr:({children:r})=>e.jsx("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/60 transition-colors",children:r}),th:({children:r})=>e.jsx("th",{className:"px-3 py-2 text-left font-semibold whitespace-nowrap border-b border-gray-200 dark:border-matrix-primary/40",children:r}),td:({children:r})=>e.jsx("td",{className:"px-3 py-2 text-gray-700 dark:text-matrix-secondary align-top",children:r})},re=F.memo(({messages:r,isLoading:o,messagesEndRef:s})=>{const x=a.useMemo(()=>fe(r),[r]);return e.jsxs(e.Fragment,{children:[x.map(u=>{const{message:n,toolGroups:p}=u;if(n.type==="tool")return e.jsx("div",{className:"px-2 py-0.5",children:e.jsx(Ie,{message:n})},u.index);const b=n.type==="human",m=n.source==="webhook"||n.source==="chronos",g=b&&!m;return e.jsxs("div",{className:`flex items-end gap-2.5 ${g?"justify-end":"justify-start"}`,children:[!g&&e.jsx("div",{className:"w-7 h-7 rounded-full flex-shrink-0 flex items-center justify-center bg-azure-primary/10 text-azure-primary dark:bg-matrix-primary/20 dark:text-matrix-highlight mb-0.5",children:m&&n.source==="webhook"?e.jsx(ue,{size:14}):m&&n.source==="chronos"?e.jsx(pe,{size:14}):e.jsx(B,{size:14})}),e.jsxs("div",{className:`
4
+ `,children:[e.jsx("div",{className:"flex-1 min-w-0",children:A?e.jsx("div",{onClick:w=>w.stopPropagation(),children:e.jsx("input",{ref:v,type:"text",value:y,onChange:w=>C(w.target.value),onKeyDown:D,className:"w-full text-sm px-1.5 py-0.5 bg-white dark:bg-black border border-azure-primary dark:border-matrix-highlight rounded-lg focus:outline-none dark:text-matrix-highlight"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-medium truncate leading-snug",children:l.title||"Untitled Session"}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-matrix-secondary/50 mt-0.5",children:Ne(l.last_message_at??l.started_at)})]})}),e.jsx("div",{className:`flex items-center gap-0.5 shrink-0 transition-opacity ${k||A?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:w=>w.stopPropagation(),children:A?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:I,className:"p-1.5 rounded-lg text-emerald-600 hover:bg-emerald-50 dark:text-emerald-400 dark:hover:bg-emerald-900/20 transition-colors",title:"Save",children:e.jsx(ne,{size:13})}),e.jsx("button",{onClick:M,className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",title:"Cancel",children:e.jsx(X,{size:13})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:w=>z(w,l),className:"p-1.5 rounded-lg text-gray-400 hover:text-blue-500 hover:bg-blue-50 dark:text-matrix-secondary/50 dark:hover:text-blue-400 dark:hover:bg-blue-900/20 transition-colors",title:"Rename",children:e.jsx(ie,{size:13})}),e.jsx("button",{onClick:()=>g(`/sessions/${l.id}/audit`),className:"p-1.5 rounded-lg text-gray-400 hover:text-violet-500 hover:bg-violet-50 dark:text-matrix-secondary/50 dark:hover:text-violet-400 dark:hover:bg-violet-900/20 transition-colors",title:"Audit",children:e.jsx(oe,{size:13})}),e.jsx("button",{onClick:()=>u(l.id),className:"p-1.5 rounded-lg text-gray-400 hover:text-amber-500 hover:bg-amber-50 dark:text-matrix-secondary/50 dark:hover:text-amber-400 dark:hover:bg-amber-900/20 transition-colors",title:"Archive",children:e.jsx(le,{size:13})}),e.jsx("button",{onClick:()=>n(l.id),className:"p-1.5 rounded-lg text-gray-400 hover:text-red-500 hover:bg-red-50 dark:text-matrix-secondary/50 dark:hover:text-red-400 dark:hover:bg-red-900/20 transition-colors",title:"Delete",children:e.jsx(de,{size:13})})]})})]},l.id)})]})]}):e.jsxs("div",{className:"w-14 bg-white dark:bg-black border-r border-gray-300 dark:border-matrix-primary flex flex-col items-center py-3 gap-3 shrink-0 transition-colors duration-300",children:[e.jsx("button",{onClick:m,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-matrix-primary/20 text-gray-400 dark:text-matrix-secondary/60 transition-colors",title:"Expand sidebar",children:e.jsx(ae,{size:18})}),e.jsx("div",{className:"w-8 h-px bg-gray-200 dark:bg-matrix-primary/20"}),e.jsx("button",{onClick:x,className:"p-2.5 bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black rounded-xl hover:bg-azure-secondary dark:hover:bg-matrix-secondary shadow-sm transition-colors",title:"New chat",children:e.jsx(U,{size:18})})]})};function K(r){if(r==null)return"";if(typeof r=="string")try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}try{return JSON.stringify(r,null,2)}catch{return String(r)}}const Ce=F.memo(({group:r})=>{const[o,s]=a.useState(!1),x=r.result!==null,u=r.result?.content??"",n=u.startsWith("Error")||u.startsWith("❌");return e.jsxs("div",{className:"rounded-lg border border-gray-300 dark:border-matrix-primary/70 bg-white dark:bg-black overflow-hidden text-sm mb-1",children:[e.jsxs("button",{onClick:()=>s(!o),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-50 dark:hover:bg-zinc-900/60 transition-colors",children:[e.jsx(ce,{size:12,className:"text-amber-500 dark:text-amber-400/80 flex-shrink-0"}),e.jsx("span",{className:"flex-1 font-mono text-xs text-gray-600 dark:text-matrix-secondary/80 truncate",children:r.call.name}),x?n?e.jsx(Q,{size:12,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(Y,{size:12,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(Z,{size:12,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx(W,{size:12,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx(H,{initial:!1,children:o&&e.jsx(V.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15,ease:"easeInOut"},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-2.5 pt-1 border-t border-gray-100 dark:border-matrix-primary/20 space-y-2",children:[Object.keys(r.call.args??{}).length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"args"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-gray-50 dark:bg-zinc-900 rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-36 overflow-y-auto",children:K(r.call.args)})]}),x&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"result"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-gray-50 dark:bg-zinc-900 rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-44 overflow-y-auto",children:K(u)})]})]})})})]})});function J(r){return r?.task??r?.prompt??""}function ze(r){if(typeof r!="string")return String(r);try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}}const Me=F.memo(({group:r})=>{const[o,s]=a.useState(!1),{getByToolName:x}=ee(),u=x(r.call.name),n={label:u.label,emoji:u.emoji,colorClass:u.colorClass,bgClass:u.bgClass},p=r.result!==null,b=r.result?.content??"",m=b.startsWith("❌")||b.toLowerCase().startsWith("error"),g=J(r.call.args).slice(0,100),c=r.call.args?.smith??null;return e.jsxs("div",{className:`rounded-lg border border-gray-300 dark:border-matrix-primary/70 overflow-hidden text-sm mb-1 ${n.bgClass}`,children:[e.jsxs("button",{onClick:()=>s(!o),className:"w-full flex items-center gap-2.5 px-3 py-2 text-left hover:brightness-95 dark:hover:brightness-110 transition-all",children:[e.jsx("span",{className:"text-base flex-shrink-0 leading-none",children:n.emoji}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:`text-xs font-semibold ${n.colorClass}`,children:[n.label,c?` · ${c}`:""]}),g&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-matrix-secondary/60 truncate mt-0.5",children:g})]}),p?m?e.jsx(Q,{size:14,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(Y,{size:14,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(Z,{size:14,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx(W,{size:13,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx(H,{initial:!1,children:o&&e.jsx(V.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.18,ease:"easeInOut"},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-2.5 pt-1 border-t border-gray-200 dark:border-matrix-primary/20 space-y-2",children:[J(r.call.args)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"task"}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-matrix-secondary/80 bg-white dark:bg-black rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 whitespace-pre-wrap",children:J(r.call.args)})]}),p&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/40 uppercase tracking-wider mb-1",children:"result"}),e.jsx("pre",{className:"text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 whitespace-pre-wrap break-all bg-white dark:bg-black rounded-md p-2 border border-gray-100 dark:border-matrix-primary/20 max-h-56 overflow-y-auto",children:ze(b)})]})]})})})]})});function Ee(r){return r==null||r===0?null:r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function q(r){return r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}const Ae=F.memo(({message:r})=>{const o=r.usage_metadata,s=o?.input_tokens??o?.prompt_tokens??0,x=o?.output_tokens??o?.completion_tokens??0,u=s>0||x>0,n=Ee(r.duration_ms),p=r.model,b=r.sati_memories_count??null;if(!u&&!n&&!p&&b==null)return null;const m=p?(p.includes(":")?p.split(":").pop():p)?.split("-").slice(0,4).join("-")??p:null;return e.jsxs("div",{className:"mt-2 pt-1.5 border-t border-gray-100 dark:border-matrix-primary/20 flex flex-wrap items-center gap-x-3 gap-y-0.5",children:[m&&e.jsx("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40 truncate max-w-[180px]",title:p??"",children:m}),u&&e.jsxs("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:["↑",q(s)," ↓",q(x)]}),n&&e.jsx("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:n}),b!=null&&b>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] font-mono text-purple-400 dark:text-purple-400/70",children:[e.jsx(xe,{size:10}),b]})]})}),G={amber:"bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-900/30 dark:text-amber-300 dark:border-amber-700/60",purple:"bg-purple-100 text-purple-800 border-purple-300 dark:bg-purple-900/30 dark:text-purple-300 dark:border-purple-700/60",violet:"bg-violet-100 text-violet-800 border-violet-300 dark:bg-violet-900/30 dark:text-violet-300 dark:border-violet-700/60",teal:"bg-teal-100 text-teal-800 border-teal-300 dark:bg-teal-900/30 dark:text-teal-300 dark:border-teal-700/60",gray:"bg-zinc-100 text-zinc-700 border-zinc-300 dark:bg-zinc-800 dark:text-zinc-300 dark:border-zinc-600",indigo:"bg-indigo-100 text-indigo-800 border-indigo-300 dark:bg-indigo-900/30 dark:text-indigo-300 dark:border-indigo-700/60"};function De(r){const o=r.replace(/^```json\s*/i,"").replace(/\s*```$/,"");try{return JSON.stringify(JSON.parse(o),null,2)}catch{return o}}function Re(r){return r.session_id?.startsWith("sati-evaluation-")===!0||r.tool_name?.toLowerCase().includes("sati")===!0}const Ie=({message:r})=>{const[o,s]=a.useState(!1),x=Re(r),u=x?r.tool_name==="sati_evaluation_output"?"Sati · memory update":"Sati · analysis":r.tool_name??"tool result";return e.jsxs("details",{open:o,onToggle:n=>s(n.target.open),className:"w-full",children:[e.jsxs("summary",{className:"list-none cursor-pointer select-none flex items-center gap-2 text-xs text-gray-400 dark:text-matrix-secondary/40 hover:text-gray-500 dark:hover:text-matrix-secondary/60 transition-colors py-0.5",children:[e.jsx("div",{className:"flex-1 h-px bg-gray-200 dark:bg-matrix-primary/20"}),e.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap px-2",children:[e.jsx("span",{children:x?"🧠":"🔧"}),e.jsx("span",{children:u}),e.jsx(W,{size:11,className:`transition-transform duration-200 ${o?"rotate-180":""}`})]}),e.jsx("div",{className:"flex-1 h-px bg-gray-200 dark:bg-matrix-primary/20"})]}),o&&e.jsx("pre",{className:"mt-2 px-3 py-2.5 whitespace-pre-wrap break-all text-xs font-mono text-gray-600 dark:text-matrix-secondary/80 border border-gray-300 dark:border-matrix-primary/60 rounded-lg bg-gray-50 dark:bg-zinc-900 max-h-48 overflow-y-auto",children:De(r.content)})]})},Te={table:({children:r})=>e.jsx("div",{className:"my-2 overflow-x-auto rounded-lg border border-gray-200 dark:border-matrix-primary/60",children:e.jsx("table",{className:"min-w-full text-xs border-collapse",children:r})}),thead:({children:r})=>e.jsx("thead",{className:"bg-gray-100 dark:bg-zinc-900 text-gray-600 dark:text-matrix-secondary/70",children:r}),tbody:({children:r})=>e.jsx("tbody",{className:"divide-y divide-gray-100 dark:divide-matrix-primary/20",children:r}),tr:({children:r})=>e.jsx("tr",{className:"hover:bg-gray-50 dark:hover:bg-zinc-900/60 transition-colors",children:r}),th:({children:r})=>e.jsx("th",{className:"px-3 py-2 text-left font-semibold whitespace-nowrap border-b border-gray-200 dark:border-matrix-primary/40",children:r}),td:({children:r})=>e.jsx("td",{className:"px-3 py-2 text-gray-700 dark:text-matrix-secondary align-top",children:r})},re=F.memo(({messages:r,isLoading:o,messagesEndRef:s})=>{const x=a.useMemo(()=>fe(r),[r]);return e.jsxs(e.Fragment,{children:[x.map(u=>{const{message:n,toolGroups:p}=u;if(n.type==="tool")return e.jsx("div",{className:"px-2 py-0.5",children:e.jsx(Ie,{message:n})},u.index);const b=n.type==="human",m=n.source==="webhook"||n.source==="chronos",g=b&&!m;return e.jsxs("div",{className:`flex items-end gap-2.5 ${g?"justify-end":"justify-start"}`,children:[!g&&e.jsx("div",{className:"w-7 h-7 rounded-full flex-shrink-0 flex items-center justify-center bg-azure-primary/10 text-azure-primary dark:bg-matrix-primary/20 dark:text-matrix-highlight mb-0.5",children:m&&n.source==="webhook"?e.jsx(ue,{size:14}):m&&n.source==="chronos"?e.jsx(pe,{size:14}):e.jsx(B,{size:14})}),e.jsxs("div",{className:`
5
5
  max-w-[85%] md:max-w-[72%] min-w-0
6
6
  ${g?"bg-azure-primary text-white dark:text-white/80 dark:bg-matrix-primary rounded-2xl rounded-br-sm px-4 py-2.5":"bg-gray-50 dark:bg-zinc-900 border border-gray-300 dark:border-matrix-primary/60 text-gray-800 dark:text-matrix-secondary rounded-2xl rounded-bl-sm px-4 py-3"}
7
7
  `,children:[m&&e.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold uppercase tracking-wider border bg-amber-50 text-amber-700 border-amber-300 dark:bg-amber-900/30 dark:text-amber-300 dark:border-amber-700/60",children:n.source==="webhook"?"Webhook":"Chronos"})}),b&&e.jsxs(e.Fragment,{children:[n.audio_duration_seconds!=null&&e.jsxs("div",{className:"flex items-center gap-1 mb-1.5 text-white/70 dark:text-white/50",children:[e.jsx(ge,{size:11}),e.jsxs("span",{className:"text-[10px] font-mono tracking-wide",children:["voice · ",n.audio_duration_seconds,"s"]})]}),e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap break-words",children:n.content})]}),n.type==="ai"&&e.jsxs(e.Fragment,{children:[p&&p.length>0&&e.jsx("div",{className:"mb-2.5 space-y-1",children:p.map(c=>ke(c.call.name)?e.jsx(Me,{group:c},c.call.id):e.jsx(Ce,{group:c},c.call.id))}),n.content&&e.jsx("div",{className:`
@@ -22,7 +22,7 @@ import{j as e,A as H,m as X}from"./vendor-motion-C3CZ8ZlO.js";import{c as te,r a
22
22
  `,children:e.jsx(je,{remarkPlugins:[ve],components:Te,children:n.content})}),e.jsx(Ae,{message:n})]})]}),g&&e.jsx("div",{className:"w-7 h-7 rounded-full flex-shrink-0 flex items-center justify-center bg-gray-200 dark:bg-matrix-primary/30 text-gray-500 dark:text-matrix-secondary mb-0.5",children:e.jsx(be,{size:14})})]},u.index)}),o&&e.jsxs("div",{className:"flex items-end gap-2.5 justify-start",children:[e.jsx("div",{className:"w-7 h-7 rounded-full flex-shrink-0 flex items-center justify-center bg-azure-primary/10 text-azure-primary dark:bg-matrix-primary/20 dark:text-matrix-highlight mb-0.5",children:e.jsx(B,{size:14})}),e.jsxs("div",{className:"bg-gray-50 dark:bg-zinc-900 border border-gray-300 dark:border-matrix-primary/60 rounded-2xl rounded-bl-sm px-4 py-3 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-azure-primary dark:bg-matrix-highlight animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-azure-primary dark:bg-matrix-highlight animate-bounce",style:{animationDelay:"160ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-azure-primary dark:bg-matrix-highlight animate-bounce",style:{animationDelay:"320ms"}})]})]}),e.jsx("div",{ref:s})]})});re.displayName="MessageList";const Oe=({messages:r,onSendMessage:o,isLoading:s,activeSessionId:x,activeSession:u,onToggleSidebar:n,onUserTyping:p,agents:b})=>{const[m,g]=a.useState(""),[c,S]=a.useState([]),[y,C]=a.useState(null),[v,z]=a.useState(0),[I,M]=a.useState([]),D=b??[],l=a.useRef(null),k=a.useRef(null),A=a.useRef(r.length),w=a.useRef(s);a.useEffect(()=>{(r.length!==A.current||w.current&&!s)&&(l.current?.scrollIntoView({behavior:"smooth"}),A.current=r.length,w.current=s)},[r,s]),a.useLayoutEffect(()=>{const t=k.current;if(!t)return;requestAnimationFrame(()=>{t&&(t.style.height="auto",t.style.height=Math.min(t.scrollHeight,160)+"px")})},[m]),a.useEffect(()=>{ye.get("/smiths").then(t=>M(t.smiths.map(d=>({name:d.name,emoji:"🕶️",description:"Remote Smith agent",color:"gray"})))).catch(()=>{})},[]);const O=a.useMemo(()=>D.filter(t=>t.delegateToolName!=="").map(t=>({name:t.auditAgent,emoji:t.emoji,description:t.description,color:t.color})),[D]),_=a.useMemo(()=>[...O,...I.filter(t=>!O.some(d=>d.name===t.name))],[O,I]),E=a.useMemo(()=>y?_.filter(t=>t.name.toLowerCase().startsWith(y.query.toLowerCase())):[],[y,_]),$=a.useCallback(t=>{if(!y)return;const d=m.slice(0,y.startIdx),N=m.slice(y.startIdx+1+y.query.length),L=(d+N).replace(/ +/g," ").trim();g(L),S(T=>T.includes(t)?T:[...T,t]),C(null),z(0),setTimeout(()=>k.current?.focus(),0)},[y,m]),P=a.useCallback(t=>{S(d=>d.filter(N=>N!==t))},[]),i=a.useCallback(t=>{const d=t.target.value;g(d),p&&p();const N=t.target.selectionStart??d.length,T=d.slice(0,N).match(/@(\w*)$/);T?(C({query:T[1],startIdx:N-T[0].length}),z(0)):C(null)},[]),h=a.useCallback(()=>{if(!(m.trim()||c.length>0)||s)return;const d=[...c.map(N=>`@${N}`),m.trim()].filter(Boolean);o(d.join(" ")),g(""),S([]),C(null),k.current&&(k.current.style.height="auto")},[m,c,s,o]),j=a.useCallback(t=>{if(y&&E.length>0){if(t.key==="ArrowDown"){t.preventDefault(),z(d=>(d+1)%E.length);return}if(t.key==="ArrowUp"){t.preventDefault(),z(d=>(d-1+E.length)%E.length);return}if(t.key==="Tab"||t.key==="Enter"){t.preventDefault(),$(E[v].name);return}if(t.key==="Escape"){t.preventDefault(),C(null);return}}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),h())},[y,E,v,$,h]),f=t=>_.find(d=>d.name===t)??{name:t,emoji:"🤖",description:"",color:"gray"};return e.jsxs("div",{className:"flex-1 flex flex-col h-full bg-white dark:bg-black overflow-hidden transition-colors duration-300",children:[n&&e.jsxs("div",{className:"md:hidden flex items-center gap-3 px-4 py-3 shrink-0 bg-white dark:bg-black border-b border-gray-300 dark:border-matrix-primary",children:[e.jsx("button",{onClick:n,className:"p-2 -ml-1 rounded-lg hover:bg-gray-100 dark:hover:bg-matrix-primary/20 text-gray-500 dark:text-matrix-secondary transition-colors","aria-label":"Open sessions",children:e.jsx(me,{size:20})}),e.jsx("span",{className:"text-sm font-semibold text-gray-800 dark:text-matrix-highlight truncate flex-1",children:u?.title??(x?"Chat":"Morpheus")})]}),x?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 px-4 py-5 space-y-4",children:e.jsx(re,{messages:r,isLoading:s,messagesEndRef:l})}),e.jsx("div",{className:"shrink-0 px-4 pt-3 pb-4 bg-white dark:bg-black border-t border-gray-300 dark:border-matrix-primary",children:e.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[y&&E.length>0&&e.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-2 z-50 bg-white dark:bg-zinc-900 border border-gray-300 dark:border-matrix-primary rounded-xl shadow-xl overflow-hidden",children:[e.jsx("div",{className:"px-3 py-1.5 border-b border-gray-100 dark:border-matrix-primary/40 flex items-center gap-1.5",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400 dark:text-matrix-secondary/50",children:"Agents"})}),e.jsx("ul",{className:"max-h-52 overflow-y-auto py-1",children:E.map((t,d)=>e.jsx("li",{children:e.jsxs("button",{type:"button",onMouseDown:N=>{N.preventDefault(),$(t.name)},onMouseEnter:()=>z(d),className:`
23
23
  w-full flex items-center gap-3 px-3 py-2 text-left transition-colors
24
24
  ${d===v?"bg-azure-primary/10 dark:bg-matrix-primary/20":"hover:bg-gray-50 dark:hover:bg-matrix-primary/10"}
25
- `,children:[e.jsx("span",{className:"text-base leading-none",children:t.emoji}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"block text-sm font-medium text-gray-800 dark:text-matrix-highlight",children:["@",t.name]}),e.jsx("span",{className:"block text-xs text-gray-400 dark:text-matrix-secondary/50 truncate",children:t.description})]}),d===v&&e.jsx("kbd",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-gray-100 dark:bg-black text-gray-500 dark:text-matrix-secondary/60 font-mono border border-gray-200 dark:border-matrix-primary/40",children:"Tab"})]})},t.name))})]}),c.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:c.map(t=>{const d=f(t),N=G[d.color]??G.gray;return e.jsxs("span",{className:`inline-flex items-center gap-1 pl-2 pr-1 py-0.5 rounded-full text-xs font-medium border ${N}`,children:[e.jsx("span",{className:"leading-none",children:d.emoji}),e.jsxs("span",{children:["@",t]}),e.jsx("button",{type:"button",onClick:()=>P(t),className:"ml-0.5 rounded-full p-0.5 hover:bg-black/10 dark:hover:bg-white/10 transition-colors","aria-label":`Remove @${t}`,children:e.jsx(Q,{size:10})})]},t)})}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),h()},className:"flex items-end gap-2",children:[e.jsx("textarea",{ref:k,value:m,onChange:i,onKeyDown:j,placeholder:"Message Morpheus… (type @ to mention an agent)",rows:1,disabled:s,className:`
25
+ `,children:[e.jsx("span",{className:"text-base leading-none",children:t.emoji}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"block text-sm font-medium text-gray-800 dark:text-matrix-highlight",children:["@",t.name]}),e.jsx("span",{className:"block text-xs text-gray-400 dark:text-matrix-secondary/50 truncate",children:t.description})]}),d===v&&e.jsx("kbd",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-gray-100 dark:bg-black text-gray-500 dark:text-matrix-secondary/60 font-mono border border-gray-200 dark:border-matrix-primary/40",children:"Tab"})]})},t.name))})]}),c.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:c.map(t=>{const d=f(t),N=G[d.color]??G.gray;return e.jsxs("span",{className:`inline-flex items-center gap-1 pl-2 pr-1 py-0.5 rounded-full text-xs font-medium border ${N}`,children:[e.jsx("span",{className:"leading-none",children:d.emoji}),e.jsxs("span",{children:["@",t]}),e.jsx("button",{type:"button",onClick:()=>P(t),className:"ml-0.5 rounded-full p-0.5 hover:bg-black/10 dark:hover:bg-white/10 transition-colors","aria-label":`Remove @${t}`,children:e.jsx(X,{size:10})})]},t)})}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),h()},className:"flex items-end gap-2",children:[e.jsx("textarea",{ref:k,value:m,onChange:i,onKeyDown:j,placeholder:"Message Morpheus… (type @ to mention an agent)",rows:1,disabled:s,className:`
26
26
  flex-1 resize-none max-h-40 overflow-y-auto
27
27
  bg-gray-100 dark:bg-zinc-900
28
28
  border border-gray-300 dark:border-matrix-primary/60