morpheus-cli 0.8.6 → 0.8.8

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 (74) hide show
  1. package/dist/channels/telegram.js +43 -0
  2. package/dist/http/api.js +49 -13
  3. package/dist/http/routers/chronos.js +12 -1
  4. package/dist/http/webhooks-router.js +11 -3
  5. package/dist/runtime/ISubagent.js +1 -0
  6. package/dist/runtime/apoc.js +49 -39
  7. package/dist/runtime/audit/repository.js +193 -6
  8. package/dist/runtime/chronos/repository.js +35 -0
  9. package/dist/runtime/keymaker.js +6 -30
  10. package/dist/runtime/memory/sati/repository.js +37 -0
  11. package/dist/runtime/memory/sqlite.js +16 -3
  12. package/dist/runtime/neo.js +78 -34
  13. package/dist/runtime/oracle.js +31 -6
  14. package/dist/runtime/skills/tool.js +25 -0
  15. package/dist/runtime/smiths/delegator.js +21 -0
  16. package/dist/runtime/subagent-utils.js +89 -0
  17. package/dist/runtime/tasks/repository.js +51 -0
  18. package/dist/runtime/tasks/worker.js +12 -2
  19. package/dist/runtime/telephonist.js +17 -9
  20. package/dist/runtime/tools/delegation-utils.js +120 -0
  21. package/dist/runtime/tools/index.js +0 -2
  22. package/dist/runtime/trinity.js +50 -34
  23. package/dist/runtime/webhooks/repository.js +31 -0
  24. package/dist/types/pagination.js +1 -0
  25. package/dist/ui/assets/AuditDashboard-5sA8Sd8S.js +1 -0
  26. package/dist/ui/assets/Chat-CjxeAQmd.js +41 -0
  27. package/dist/ui/assets/Chronos-BAjeLobF.js +1 -0
  28. package/dist/ui/assets/{ConfirmationModal-Bx-GtD9B.js → ConfirmationModal-fvgnOWTY.js} +1 -1
  29. package/dist/ui/assets/{Dashboard-DDyN_X-J.js → Dashboard-Ca5mSefz.js} +1 -1
  30. package/dist/ui/assets/{DeleteConfirmationModal-DIXbckY8.js → DeleteConfirmationModal-A8EmnHoa.js} +1 -1
  31. package/dist/ui/assets/{Logs-dzPLW45U.js → Logs-CYu7se7R.js} +1 -1
  32. package/dist/ui/assets/MCPManager-DsDA_ZVT.js +1 -0
  33. package/dist/ui/assets/ModelPricing-DnSm_Nh-.js +1 -0
  34. package/dist/ui/assets/Notifications-CiljQzvM.js +1 -0
  35. package/dist/ui/assets/Pagination-JsiwxVNQ.js +1 -0
  36. package/dist/ui/assets/SatiMemories-rnO2b0LG.js +1 -0
  37. package/dist/ui/assets/SessionAudit-Dfvhge3Z.js +9 -0
  38. package/dist/ui/assets/{Settings-DNDe62-H.js → Settings-OQlHAJoy.js} +1 -1
  39. package/dist/ui/assets/Skills-Crsybug0.js +7 -0
  40. package/dist/ui/assets/Smiths-wm90jRDT.js +1 -0
  41. package/dist/ui/assets/Tasks-C5FMu_Yu.js +1 -0
  42. package/dist/ui/assets/TrinityDatabases-BzYfecKI.js +1 -0
  43. package/dist/ui/assets/{UsageStats-doBLB7Lc.js → UsageStats-CBo2vW2n.js} +1 -1
  44. package/dist/ui/assets/{WebhookManager-D3A5pdjC.js → WebhookManager-0tDFkfHd.js} +1 -1
  45. package/dist/ui/assets/audit-B-F8XPLi.js +1 -0
  46. package/dist/ui/assets/chronos-BvMxfBQH.js +1 -0
  47. package/dist/ui/assets/{config-DX3Xb0XE.js → config-DteVgNGR.js} +1 -1
  48. package/dist/ui/assets/index-Cwqr-n0Y.js +10 -0
  49. package/dist/ui/assets/index-DcfyUdLI.css +1 -0
  50. package/dist/ui/assets/{mcp-DfhJYN14.js → mcp-DxzodOdH.js} +1 -1
  51. package/dist/ui/assets/{skills-BPjq0qV7.js → skills--hAyQnmG.js} +1 -1
  52. package/dist/ui/assets/{stats-DHCRNkJp.js → stats-Cibaisqd.js} +1 -1
  53. package/dist/ui/assets/vendor-icons-BVuQI-6R.js +1 -0
  54. package/dist/ui/index.html +3 -3
  55. package/dist/ui/sw.js +1 -1
  56. package/package.json +2 -1
  57. package/dist/runtime/tools/apoc-tool.js +0 -157
  58. package/dist/runtime/tools/neo-tool.js +0 -172
  59. package/dist/runtime/tools/trinity-tool.js +0 -157
  60. package/dist/ui/assets/Chat-CO15OnaY.js +0 -38
  61. package/dist/ui/assets/Chronos-CUZDQLh2.js +0 -1
  62. package/dist/ui/assets/MCPManager-CRHWR4S7.js +0 -1
  63. package/dist/ui/assets/ModelPricing-TRBesy0r.js +0 -1
  64. package/dist/ui/assets/Notifications-DMke7Dr7.js +0 -1
  65. package/dist/ui/assets/SatiMemories-CaLrgdZV.js +0 -1
  66. package/dist/ui/assets/SessionAudit-DedGO5XK.js +0 -9
  67. package/dist/ui/assets/Skills-KUhW7UXP.js +0 -7
  68. package/dist/ui/assets/Smiths-Btoqw4Ex.js +0 -1
  69. package/dist/ui/assets/Tasks-cwA25Hq2.js +0 -1
  70. package/dist/ui/assets/TrinityDatabases-CQhettEJ.js +0 -1
  71. package/dist/ui/assets/chronos-DlDM2UBT.js +0 -1
  72. package/dist/ui/assets/index-CQIUjucB.js +0 -10
  73. package/dist/ui/assets/index-DAh3q_hR.css +0 -1
  74. package/dist/ui/assets/vendor-icons-DLvvGkeN.js +0 -1
@@ -65,7 +65,12 @@ export class TaskWorker {
65
65
  switch (task.agent) {
66
66
  case 'apoc': {
67
67
  const apoc = Apoc.getInstance();
68
- result = await apoc.execute(task.input, task.context ?? undefined, task.session_id);
68
+ result = await apoc.execute(task.input, task.context ?? undefined, task.session_id, {
69
+ origin_channel: task.origin_channel,
70
+ session_id: task.session_id,
71
+ origin_message_id: task.origin_message_id ?? undefined,
72
+ origin_user_id: task.origin_user_id ?? undefined,
73
+ });
69
74
  break;
70
75
  }
71
76
  case 'neo': {
@@ -80,7 +85,12 @@ export class TaskWorker {
80
85
  }
81
86
  case 'trinit': {
82
87
  const trinity = Trinity.getInstance();
83
- result = await trinity.execute(task.input, task.context ?? undefined, task.session_id);
88
+ result = await trinity.execute(task.input, task.context ?? undefined, task.session_id, {
89
+ origin_channel: task.origin_channel,
90
+ session_id: task.session_id,
91
+ origin_message_id: task.origin_message_id ?? undefined,
92
+ origin_user_id: task.origin_user_id ?? undefined,
93
+ });
84
94
  break;
85
95
  }
86
96
  case 'keymaker': {
@@ -2,16 +2,24 @@ import { GoogleGenAI } from '@google/genai';
2
2
  import OpenAI from 'openai';
3
3
  import { OpenRouter } from '@openrouter/sdk';
4
4
  import fs from 'fs';
5
+ import { parseFile } from 'music-metadata';
5
6
  /**
6
- * Estimates audio duration in seconds based on file size and a typical bitrate.
7
- * Uses 32 kbps (4000 bytes/sec) as a conservative baseline for compressed audio (OGG, MP3, etc.).
8
- * This is an approximation — actual duration depends on encoding settings.
7
+ * Returns the actual audio duration in seconds by parsing the file header.
8
+ * Falls back to a size-based estimate (~32 kbps) if parsing fails.
9
9
  */
10
- function estimateAudioDurationSeconds(filePath) {
10
+ async function getAudioDurationSeconds(filePath) {
11
+ try {
12
+ const metadata = await parseFile(filePath);
13
+ const duration = metadata.format.duration;
14
+ if (duration != null && duration > 0)
15
+ return Math.round(duration);
16
+ }
17
+ catch {
18
+ // fall through to estimate
19
+ }
11
20
  try {
12
21
  const stats = fs.statSync(filePath);
13
- const bytesPerSecond = 4000; // ~32 kbps
14
- return Math.round(stats.size / bytesPerSecond);
22
+ return Math.round(stats.size / 4000); // ~32 kbps fallback
15
23
  }
16
24
  catch {
17
25
  return 0;
@@ -57,7 +65,7 @@ class GeminiTelephonist {
57
65
  input_token_details: {
58
66
  cache_read: usage?.cachedContentTokenCount ?? 0
59
67
  },
60
- audio_duration_seconds: estimateAudioDurationSeconds(filePath)
68
+ audio_duration_seconds: await getAudioDurationSeconds(filePath)
61
69
  };
62
70
  return { text, usage: usageMetadata };
63
71
  }
@@ -91,7 +99,7 @@ class WhisperTelephonist {
91
99
  input_tokens: 0,
92
100
  output_tokens: 0,
93
101
  total_tokens: 0,
94
- audio_duration_seconds: estimateAudioDurationSeconds(filePath)
102
+ audio_duration_seconds: await getAudioDurationSeconds(filePath)
95
103
  };
96
104
  return { text, usage: usageMetadata };
97
105
  }
@@ -148,7 +156,7 @@ class OpenRouterTelephonist {
148
156
  input_tokens: usage?.prompt_tokens ?? 0,
149
157
  output_tokens: usage?.completion_tokens ?? 0,
150
158
  total_tokens: usage?.total_tokens ?? 0,
151
- audio_duration_seconds: estimateAudioDurationSeconds(filePath)
159
+ audio_duration_seconds: await getAudioDurationSeconds(filePath)
152
160
  };
153
161
  return { text, usage: usageMetadata };
154
162
  }
@@ -0,0 +1,120 @@
1
+ import { tool } from "@langchain/core/tools";
2
+ import { z } from "zod";
3
+ import { TaskRepository } from "../tasks/repository.js";
4
+ import { TaskRequestContext } from "../tasks/context.js";
5
+ import { compositeDelegationError, isLikelyCompositeDelegationTask } from "./delegation-guard.js";
6
+ import { DisplayManager } from "../display.js";
7
+ import { ChannelRegistry } from "../../channels/registry.js";
8
+ import { AuditRepository } from "../audit/repository.js";
9
+ /**
10
+ * Factory that builds a delegation StructuredTool for Apoc/Neo/Trinity.
11
+ * Handles: composite guard, sync branch (notify→execute→audit→increment),
12
+ * async branch (dedup→canEnqueue→createTask→setAck).
13
+ */
14
+ export function buildDelegationTool(opts) {
15
+ const { name, agentKey, agentLabel, auditAgent, isSync, notifyText, executeSync, } = opts;
16
+ const toolInstance = tool(async ({ task, context }) => {
17
+ const display = DisplayManager.getInstance();
18
+ const source = `${agentLabel}DelegateTool`;
19
+ try {
20
+ if (isLikelyCompositeDelegationTask(task)) {
21
+ display.log(`${agentLabel} delegation rejected (non-atomic task): ${task.slice(0, 140)}`, {
22
+ source,
23
+ level: "warning",
24
+ });
25
+ return compositeDelegationError();
26
+ }
27
+ // ── Sync mode: execute inline and return result directly ──
28
+ if (isSync()) {
29
+ display.log(`${agentLabel} executing synchronously: ${task.slice(0, 80)}...`, {
30
+ source,
31
+ level: "info",
32
+ });
33
+ const ctx = TaskRequestContext.get();
34
+ const sessionId = ctx?.session_id ?? "default";
35
+ if (ctx?.origin_channel && ctx.origin_user_id && ctx.origin_channel !== 'api' && ctx.origin_channel !== 'ui') {
36
+ ChannelRegistry.sendToUser(ctx.origin_channel, ctx.origin_user_id, notifyText)
37
+ .catch(() => { });
38
+ }
39
+ try {
40
+ const result = await executeSync(task, context, sessionId, ctx);
41
+ TaskRequestContext.incrementSyncDelegation();
42
+ display.log(`${agentLabel} sync execution completed.`, { source, level: "info" });
43
+ if (result.usage) {
44
+ AuditRepository.getInstance().insert({
45
+ session_id: sessionId,
46
+ event_type: 'llm_call',
47
+ agent: auditAgent,
48
+ provider: result.usage.provider,
49
+ model: result.usage.model,
50
+ input_tokens: result.usage.inputTokens,
51
+ output_tokens: result.usage.outputTokens,
52
+ duration_ms: result.usage.durationMs,
53
+ status: 'success',
54
+ metadata: { step_count: result.usage.stepCount, mode: 'sync' },
55
+ });
56
+ }
57
+ return result.output;
58
+ }
59
+ catch (syncErr) {
60
+ TaskRequestContext.incrementSyncDelegation();
61
+ display.log(`${agentLabel} sync execution failed: ${syncErr.message}`, { source, level: "error" });
62
+ return `❌ ${agentLabel} error: ${syncErr.message}`;
63
+ }
64
+ }
65
+ // ── Async mode (default): create background task ──
66
+ const existingAck = TaskRequestContext.findDuplicateDelegation(agentKey, task);
67
+ if (existingAck) {
68
+ display.log(`${agentLabel} delegation deduplicated. Reusing task ${existingAck.task_id}.`, {
69
+ source,
70
+ level: "info",
71
+ });
72
+ return `Task ${existingAck.task_id} already queued for ${existingAck.agent} execution.`;
73
+ }
74
+ if (!TaskRequestContext.canEnqueueDelegation()) {
75
+ display.log(`${agentLabel} delegation blocked by per-turn limit.`, { source, level: "warning" });
76
+ return "Delegation limit reached for this user turn. Split the request or wait for current tasks.";
77
+ }
78
+ const ctx = TaskRequestContext.get();
79
+ const repository = TaskRepository.getInstance();
80
+ const created = repository.createTask({
81
+ agent: agentKey,
82
+ input: task,
83
+ context: context ?? null,
84
+ origin_channel: ctx?.origin_channel ?? "api",
85
+ session_id: ctx?.session_id ?? "default",
86
+ origin_message_id: ctx?.origin_message_id ?? null,
87
+ origin_user_id: ctx?.origin_user_id ?? null,
88
+ max_attempts: 3,
89
+ });
90
+ TaskRequestContext.setDelegationAck({ task_id: created.id, agent: agentKey, task });
91
+ display.log(`${agentLabel} task created: ${created.id}`, {
92
+ source,
93
+ level: "info",
94
+ meta: {
95
+ agent: created.agent,
96
+ origin_channel: created.origin_channel,
97
+ session_id: created.session_id,
98
+ input: created.input,
99
+ },
100
+ });
101
+ return `Task ${created.id} queued for ${agentLabel} execution.`;
102
+ }
103
+ catch (err) {
104
+ display.log(`${source} error: ${err.message}`, { source, level: "error" });
105
+ return `${agentLabel} task enqueue failed: ${err.message}`;
106
+ }
107
+ }, {
108
+ name,
109
+ description: typeof opts.description === 'string' ? opts.description : opts.description(),
110
+ schema: z.object({
111
+ task: z.string().describe(`Clear task description **in the user's language**`),
112
+ context: z.string().optional().describe(`Optional context from the conversation **in the user's language**`),
113
+ }),
114
+ });
115
+ // If description is dynamic, expose an updater method on the tool instance
116
+ if (typeof opts.description === 'function') {
117
+ toolInstance._descriptionFn = opts.description;
118
+ }
119
+ return toolInstance;
120
+ }
@@ -1,7 +1,5 @@
1
1
  // Export all tools from the tools module
2
2
  export * from './morpheus-tools.js';
3
- export * from './apoc-tool.js';
4
- export * from './neo-tool.js';
5
3
  export * from './smith-tool.js';
6
4
  export * from './chronos-tools.js';
7
5
  export * from './time-verify-tools.js';
@@ -5,10 +5,32 @@ import { ConfigManager } from "../config/manager.js";
5
5
  import { ProviderFactory } from "./providers/factory.js";
6
6
  import { ProviderError } from "./errors.js";
7
7
  import { DisplayManager } from "./display.js";
8
- import { SQLiteChatMessageHistory } from "./memory/sqlite.js";
9
8
  import { DatabaseRegistry } from "./memory/trinity-db.js";
10
9
  import { testConnection, introspectSchema, executeQuery } from "./trinity-connector.js";
11
- import { updateTrinityDelegateToolDescription } from "./tools/trinity-tool.js";
10
+ import { extractRawUsage, persistAgentMessage, buildAgentResult, emitToolAuditEvents } from "./subagent-utils.js";
11
+ import { buildDelegationTool } from "./tools/delegation-utils.js";
12
+ const TRINITY_BASE_DESCRIPTION = `Delegate a database task to Trinity, the specialized database subagent, asynchronously.
13
+
14
+ This tool enqueues a background task and returns an acknowledgement with task id.
15
+ Trinity interprets natural language database requests, generates the appropriate query, and returns results.
16
+
17
+ Use this tool when the user asks for ANY of the following:
18
+ - Querying data from a registered database (SELECT, find, aggregate)
19
+ - Checking database status or schema
20
+ - Running reports or analytics against a database
21
+ - Listing tables, collections, or fields
22
+ - Counting records or summarizing data`;
23
+ function buildDatabaseCatalog(databases) {
24
+ if (databases.length === 0) {
25
+ return '\n\nNo databases currently registered. Register databases via /api/trinity/databases.';
26
+ }
27
+ const lines = databases.map((db) => {
28
+ const schema = db.schema_json ? JSON.parse(db.schema_json) : null;
29
+ const tables = schema?.tables?.map((t) => t.name).join(', ') || 'schema not loaded';
30
+ return `- [${db.id}] ${db.name} (${db.type}): ${tables}`;
31
+ });
32
+ return `\n\nRegistered databases:\n${lines.join('\n')}`;
33
+ }
12
34
  /**
13
35
  * Trinity is a subagent of Oracle specialized in database operations.
14
36
  * It receives delegated tasks from Oracle, interprets them in natural language,
@@ -17,6 +39,7 @@ import { updateTrinityDelegateToolDescription } from "./tools/trinity-tool.js";
17
39
  export class Trinity {
18
40
  static instance = null;
19
41
  static currentSessionId = undefined;
42
+ static _delegateTool = null;
20
43
  agent;
21
44
  config;
22
45
  display = DisplayManager.getInstance();
@@ -34,11 +57,15 @@ export class Trinity {
34
57
  }
35
58
  static resetInstance() {
36
59
  Trinity.instance = null;
60
+ Trinity._delegateTool = null;
37
61
  }
38
62
  static async refreshDelegateCatalog() {
39
63
  const registry = DatabaseRegistry.getInstance();
40
64
  const databases = registry.listDatabases();
41
- updateTrinityDelegateToolDescription(databases);
65
+ if (Trinity._delegateTool) {
66
+ const full = `${TRINITY_BASE_DESCRIPTION}${buildDatabaseCatalog(databases)}`;
67
+ Trinity._delegateTool.description = full;
68
+ }
42
69
  }
43
70
  buildTrinityTools() {
44
71
  const registry = DatabaseRegistry.getInstance();
@@ -169,7 +196,7 @@ export class Trinity {
169
196
  throw new ProviderError(trinityConfig.provider, err, 'Trinity subagent initialization failed');
170
197
  }
171
198
  }
172
- async execute(task, context, sessionId) {
199
+ async execute(task, context, sessionId, taskContext) {
173
200
  if (!this.agent) {
174
201
  await this.initialize();
175
202
  }
@@ -217,44 +244,33 @@ ${context ? `CONTEXT FROM ORACLE:\n${context}` : ''}
217
244
  const content = typeof lastMessage.content === 'string'
218
245
  ? lastMessage.content
219
246
  : JSON.stringify(lastMessage.content);
220
- const rawUsage = lastMessage.usage_metadata
221
- ?? lastMessage.response_metadata?.usage
222
- ?? lastMessage.response_metadata?.tokenUsage
223
- ?? lastMessage.usage;
224
- const inputTokens = rawUsage?.input_tokens ?? 0;
225
- const outputTokens = rawUsage?.output_tokens ?? 0;
247
+ const rawUsage = extractRawUsage(lastMessage);
226
248
  const stepCount = response.messages.filter((m) => m instanceof AIMessage).length;
227
249
  const targetSession = sessionId ?? Trinity.currentSessionId ?? 'trinity';
228
- const history = new SQLiteChatMessageHistory({ sessionId: targetSession });
229
- try {
230
- const persisted = new AIMessage(content);
231
- if (rawUsage)
232
- persisted.usage_metadata = rawUsage;
233
- persisted.provider_metadata = { provider: trinityConfig.provider, model: trinityConfig.model };
234
- persisted.agent_metadata = { agent: 'trinity' };
235
- persisted.duration_ms = durationMs;
236
- await history.addMessage(persisted);
237
- }
238
- finally {
239
- history.close();
240
- }
250
+ await persistAgentMessage('trinity', content, trinityConfig, targetSession, rawUsage, durationMs);
251
+ emitToolAuditEvents(response.messages.slice(2), targetSession, 'trinity');
241
252
  this.display.log('Trinity task completed.', { source: 'Trinity' });
242
- return {
243
- output: content,
244
- usage: {
245
- provider: trinityConfig.provider,
246
- model: trinityConfig.model,
247
- inputTokens,
248
- outputTokens,
249
- durationMs,
250
- stepCount,
251
- },
252
- };
253
+ return buildAgentResult(content, trinityConfig, rawUsage, durationMs, stepCount);
253
254
  }
254
255
  catch (err) {
255
256
  throw new ProviderError(trinityConfig.provider, err, 'Trinity task execution failed');
256
257
  }
257
258
  }
259
+ createDelegateTool() {
260
+ if (!Trinity._delegateTool) {
261
+ Trinity._delegateTool = buildDelegationTool({
262
+ name: 'trinity_delegate',
263
+ description: TRINITY_BASE_DESCRIPTION,
264
+ agentKey: 'trinit',
265
+ agentLabel: 'Trinity',
266
+ auditAgent: 'trinity',
267
+ isSync: () => ConfigManager.getInstance().get().trinity?.execution_mode === 'sync',
268
+ notifyText: '👩‍💻 Trinity is executing your request...',
269
+ executeSync: (task, context, sessionId) => Trinity.getInstance().execute(task, context, sessionId),
270
+ });
271
+ }
272
+ return Trinity._delegateTool;
273
+ }
258
274
  async reload() {
259
275
  this.config = ConfigManager.getInstance().get();
260
276
  this.agent = undefined;
@@ -164,6 +164,37 @@ export class WebhookRepository {
164
164
  const rows = this.db.prepare(query).all(...params);
165
165
  return rows.map(this.deserializeNotification);
166
166
  }
167
+ buildNotificationWhere(filters) {
168
+ const params = [];
169
+ let where = 'WHERE 1=1';
170
+ if (filters?.webhookId) {
171
+ where += ' AND webhook_id = ?';
172
+ params.push(filters.webhookId);
173
+ }
174
+ if (filters?.unreadOnly) {
175
+ where += ' AND read = 0';
176
+ }
177
+ if (filters?.status) {
178
+ where += ' AND status = ?';
179
+ params.push(filters.status);
180
+ }
181
+ return { where, params };
182
+ }
183
+ countNotifications(filters) {
184
+ const { where, params } = this.buildNotificationWhere(filters);
185
+ const row = this.db.prepare(`SELECT COUNT(*) as cnt FROM webhook_notifications ${where}`).get(...params);
186
+ return row.cnt;
187
+ }
188
+ listNotificationsPaginated(filters) {
189
+ const page = Math.max(1, filters?.page ?? 1);
190
+ const per_page = Math.min(100, Math.max(1, filters?.per_page ?? 20));
191
+ const offset = (page - 1) * per_page;
192
+ const total = this.countNotifications(filters);
193
+ const total_pages = Math.ceil(total / per_page);
194
+ const { where, params } = this.buildNotificationWhere(filters);
195
+ const rows = this.db.prepare(`SELECT * FROM webhook_notifications ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...params, per_page, offset);
196
+ return { data: rows.map(this.deserializeNotification), total, page, per_page, total_pages };
197
+ }
167
198
  getNotificationById(id) {
168
199
  const row = this.db.prepare('SELECT * FROM webhook_notifications WHERE id = ?').get(id);
169
200
  return row ? this.deserializeNotification(row) : null;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{j as e,m as n}from"./vendor-motion-C3CZ8ZlO.js";import{L as O,r as B}from"./vendor-react-DikRIOlj.js";import{a as R}from"./audit-B-F8XPLi.js";import{O as C,av as D,j as L,i as F,ar as v,E as k,m as S,A as _,h as w,aw as I,e as U,I as A,ax as W,J as $,p as G,ah as V}from"./vendor-icons-BVuQI-6R.js";import"./vendor-utils-D4NnWbOU.js";import"./index-Cwqr-n0Y.js";function u(a){return a===0?"$0.00":a<1e-4?"<$0.0001":a<.01?`$${a.toFixed(4)}`:`$${a.toFixed(2)}`}function m(a){return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}k`:String(a)}function j(a){if(a<1e3)return`${a}ms`;if(a<6e4)return`${(a/1e3).toFixed(1)}s`;const l=Math.floor(a/6e4),i=Math.floor(a%6e4/1e3);return`${l}m ${i}s`}function H(a){return a?new Date(a).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function z(a,l){return l?`${Math.round(a/l*100)}%`:"0%"}function J({data:a}){const[l,i]=B.useState(null);if(!a.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(...a.map(r=>r.eventCount),1);return e.jsx("div",{className:"flex items-end gap-0.5 h-24 w-full relative",children:a.map((r,c)=>{const y=Math.max(4,Math.round(r.eventCount/s*88)),g=l===c;return e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end group",onMouseEnter:()=>i(c),onMouseLeave:()=>i(null),children:[g&&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:[r.date,": ",r.eventCount," events · ",u(r.estimatedCostUsd)]}),e.jsx("div",{style:{height:y},className:`w-full rounded-t transition-colors ${g?"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"}`})]},r.date)})})}function h({icon:a,label:l,value:i,sub:s,color:r="blue"}){const c={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 ${c[r]}`,children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:a}),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:l}),e.jsx("p",{className:"text-xl font-bold font-mono leading-tight",children:i}),s&&e.jsx("div",{className:"text-[11px] opacity-60 mt-0.5 leading-snug",children:s})]})]})}function x({title:a,icon:l,children:i}){return e.jsxs("div",{className:"rounded-lg border border-gray-200 dark:border-matrix-primary overflow-hidden",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:l}),e.jsx("h2",{className:"text-sm font-semibold text-gray-700 dark:text-matrix-secondary uppercase tracking-wider",children:a})]}),e.jsx("div",{className:"p-4",children:i})]})}const P={oracle:"🔮",apoc:"🧑‍🔬",neo:"🥷",trinity:"👩‍💻",smith:"🤖",keymaker:"🗝️",chronos:"⏰",sati:"🧠",telephonist:"📞",unknown:"?"},T={oracle:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300",apoc:"bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",neo:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300",trinity:"bg-teal-100 text-teal-700 dark:bg-teal-900/40 dark:text-teal-300",smith:"bg-gray-200 text-gray-700 dark:bg-gray-700/60 dark:text-gray-300",keymaker:"bg-pink-100 text-pink-700 dark:bg-pink-900/40 dark:text-pink-300",chronos:"bg-orange-100 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300",sati:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300",telephonist:"bg-rose-100 text-rose-700 dark:bg-rose-900/40 dark:text-rose-300",unknown:"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-secondary/60"};function M({agent:a}){const l=T[a]??T.unknown;return e.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] font-semibold px-1.5 py-0.5 rounded ${l}`,children:[P[a]??"?"," ",a.toUpperCase()]})}function Z({status:a}){const l={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 ${l[a]??l.unknown}`,children:a})}const q={llm_call:e.jsx(v,{size:13}),tool_call:e.jsx(k,{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(S,{size:13}),telephonist:e.jsx($,{size:13}),skill_executed:e.jsx(A,{size:13}),chronos_job:e.jsx(w,{size:13}),task_created:e.jsx(V,{size:13}),task_completed:e.jsx(G,{size:13})},K={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",telephonist:"text-rose-500 dark:text-rose-400",skill_executed:"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:a}){return a==="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(k,{size:13,className:"flex-shrink-0 text-amber-500 dark:text-amber-400"})}const X={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",telephonist:"bg-rose-400 dark:bg-rose-500",skill_executed:"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"},Y={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.04}}},o={hidden:{opacity:0,y:12},show:{opacity:1,y:0}},ie=()=>{const{data:a,isLoading:l,mutate:i}=R();if(l)return e.jsxs("div",{className:"flex items-center justify-center h-64 gap-3 text-gray-400 dark:text-matrix-secondary",children:[e.jsx(C,{size:20,className:"animate-spin"}),e.jsx("span",{className:"text-sm font-mono",children:"Loading audit data…"})]});if(!a)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(D,{size:24}),e.jsx("span",{className:"text-sm",children:"Failed to load audit data."})]});const{sessions:s,totals:r,byAgent:c,byModel:y,topTools:g,recentSessions:N,dailyActivity:p}=a,f=[["llm_call",r.llmCallCount],["tool_call",r.toolCallCount],["mcp_tool",r.mcpToolCount],["memory_recovery",r.memoryRecoveryCount],["telephonist",r.telephonistCount],["skill_executed",r.skillCount],["chronos_job",r.chronosJobCount],["task_created",r.taskCreatedCount],["task_completed",r.taskCompletedCount]].filter(([,t])=>t>0).sort((t,d)=>d[1]-t[1]),E=Math.max(...f.map(([,t])=>t),1);return e.jsxs(n.div,{variants:Y,initial:"hidden",animate:"show",className:"space-y-6",children:[e.jsxs(n.div,{variants:o,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 · ",r.totalEventCount.toLocaleString()," events total"]})]})]}),e.jsxs("button",{onClick:()=>i(),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(C,{size:14})," Refresh"]})]}),e.jsxs(n.div,{variants:o,className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(h,{icon:e.jsx(F,{size:16}),label:"Total Cost",value:u(r.estimatedCostUsd),color:"green"}),e.jsx(h,{icon:e.jsx(v,{size:16}),label:"LLM Calls",value:r.llmCallCount.toLocaleString(),color:"blue"}),e.jsx(h,{icon:e.jsx(k,{size:16}),label:"Tool Calls",value:(r.toolCallCount+r.mcpToolCount).toLocaleString(),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[r.toolCallCount," native"]}),e.jsx("br",{}),e.jsxs("span",{children:[r.mcpToolCount," MCP"]})]}),color:"amber"}),e.jsx(h,{icon:e.jsx(S,{size:16}),label:"Memory Hits",value:r.memoryRecoveryCount.toLocaleString(),color:"teal"}),e.jsx(h,{icon:e.jsx(_,{size:16}),label:"Total Tokens",value:m(r.totalInputTokens+r.totalOutputTokens),sub:e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["↑",m(r.totalInputTokens)," in"]}),e.jsx("br",{}),e.jsxs("span",{children:["↓",m(r.totalOutputTokens)," out"]})]}),color:"purple"}),e.jsx(h,{icon:e.jsx(w,{size:16}),label:"Total Time",value:j(r.totalDurationMs),color:"rose"})]}),e.jsxs(n.div,{variants:o,className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(x,{title:"Sessions",icon:e.jsx(I,{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:d,cls:b})=>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 ${b}`,children:d})]},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(U,{size:14}),children:[e.jsx(J,{data:p}),p.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:p[0]?.date}),e.jsx("span",{className:"flex-1 text-right",children:p[p.length-1]?.date})]})]})]}),e.jsx(n.div,{variants:o,children:e.jsx(x,{title:"Events by Type",icon:e.jsx(_,{size:14}),children:e.jsx("div",{className:"space-y-2",children:f.map(([t,d])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-5 flex justify-center ${K[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 ${X[t]??"bg-gray-400"}`,style:{width:z(d,E)}})}),e.jsx("span",{className:"text-xs font-mono text-gray-500 dark:text-matrix-secondary w-16 text-right",children:d.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-matrix-secondary/50 w-10 text-right",children:z(d,r.totalEventCount)})]},t))})})}),e.jsxs(n.div,{variants:o,className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(x,{title:"By Agent",icon:e.jsx(A,{size:14}),children:c.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:c.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:j(t.totalDurationMs)}),e.jsx("td",{className:"py-1.5 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:u(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:u(t.estimatedCostUsd)})]},`${t.provider}/${t.model}`))})]})})})]}),g.length>0&&e.jsx(n.div,{variants:o,children:e.jsx(x,{title:"Top Tools",icon:e.jsx(k,{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:g.map((t,d)=>{const b=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:b>.1?"text-red-500 dark:text-red-400":b>0?"text-amber-500 dark:text-amber-400":"text-gray-400 dark:text-matrix-secondary/50",children:t.count>0?`${Math.round(b*100)}%`:"—"})})]},d)})})]})})})}),e.jsx(n.div,{variants:o,children:e.jsx(x,{title:"Recent Sessions with Audit",icon:e.jsx(L,{size:14}),children:N.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:N.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:H(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:j(t.totalDurationMs)}),e.jsx("td",{className:"py-2 text-right font-semibold text-gray-700 dark:text-matrix-secondary",children:u(t.estimatedCostUsd)}),e.jsx("td",{className:"py-2 text-right",children:e.jsx(O,{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(W,{size:11})})})]},t.session_id))})]})})})}),r.telephonistCount>0&&e.jsx(n.div,{variants:o,children:e.jsx(x,{title:"Audio / Telephonist",icon:e.jsx($,{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:r.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:r.totalAudioSeconds<60?`${r.totalAudioSeconds.toFixed(1)}s`:`${(r.totalAudioSeconds/60).toFixed(1)}m`})]})]})})})]})};export{ie as AuditDashboard};
@@ -0,0 +1,41 @@
1
+ import{j as e,A as B,m as L}from"./vendor-motion-C3CZ8ZlO.js";import{c as U,r as l}from"./vendor-react-DikRIOlj.js";import{s as H,t as F,u as X,v as Q,X as W,w as V,x as Y,y as Z,z as ee,E as re,q as G,F as K,r as q,G as $,m as te,M as ae,I as T,J as se,U as ie,K as ne}from"./vendor-icons-BVuQI-6R.js";import{h as oe,g as le,i as de,c as A}from"./index-Cwqr-n0Y.js";import{M as ce,r as xe}from"./vendor-markdown-BN_Np5Ta.js";import{C as me}from"./ConfirmationModal-fvgnOWTY.js";import"./vendor-utils-D4NnWbOU.js";function he(r){const n=Date.now()-r;return n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:new Date(r).toLocaleDateString()}const pe=({sessions:r,activeSessionId:n,onSelectSession:i,onCreateSession:d,onArchiveSession:p,onDeleteSession:x,onRenameSession:c,isOpen:u,toggleSidebar:m})=>{const v=U(),[g,b]=l.useState(null),[w,k]=l.useState(""),z=l.useRef(null);l.useEffect(()=>{g&&z.current&&z.current.focus()},[g]);const I=(o,S)=>{o.stopPropagation(),b(S.id),k(S.title||"Untitled Session")},D=o=>{o?.stopPropagation(),g&&w.trim()&&(c(g,w.trim()),b(null))},N=o=>{o?.stopPropagation(),b(null)},_=o=>{o.key==="Enter"?D():o.key==="Escape"&&N()};return u?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(X,{size:16})})]}),e.jsx("div",{className:"px-3 py-2.5 shrink-0",children:e.jsxs("button",{onClick:d,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(F,{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(o=>{const S=n===o.id,E=g===o.id;return e.jsxs("div",{onClick:()=>!E&&i(o.id),className:`
2
+ group relative flex items-center gap-2 px-3 py-2.5 rounded-xl cursor-pointer transition-all
3
+ ${S?"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:E?e.jsx("div",{onClick:a=>a.stopPropagation(),children:e.jsx("input",{ref:z,type:"text",value:w,onChange:a=>k(a.target.value),onKeyDown:_,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:o.title||"Untitled Session"}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-matrix-secondary/50 mt-0.5",children:he(o.started_at)})]})}),e.jsx("div",{className:`flex items-center gap-0.5 shrink-0 transition-opacity ${S||E?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:a=>a.stopPropagation(),children:E?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:D,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(Q,{size:13})}),e.jsx("button",{onClick:N,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(W,{size:13})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a=>I(a,o),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(V,{size:13})}),e.jsx("button",{onClick:()=>v(`/sessions/${o.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(Y,{size:13})}),e.jsx("button",{onClick:()=>p(o.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(Z,{size:13})}),e.jsx("button",{onClick:()=>x(o.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(ee,{size:13})})]})})]},o.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(H,{size:18})}),e.jsx("div",{className:"w-8 h-px bg-gray-200 dark:bg-matrix-primary/20"}),e.jsx("button",{onClick:d,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(F,{size:18})})]})};function P(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 ge=({group:r})=>{const[n,i]=l.useState(!1),d=r.result!==null,p=r.result?.content??"",x=p.startsWith("Error")||p.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:()=>i(!n),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(re,{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}),d?x?e.jsx(G,{size:12,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(K,{size:12,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(q,{size:12,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx($,{size:12,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${n?"rotate-180":""}`})]}),e.jsx(B,{initial:!1,children:n&&e.jsx(L.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:P(r.call.args)})]}),d&&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:P(p)})]})]})})})]})},ue={apoc_delegate:{label:"Apoc",emoji:"🧑‍🔬",colorClass:"text-amber-600 dark:text-amber-400",bgClass:"bg-amber-50 dark:bg-amber-900/10"},neo_delegate:{label:"Neo",emoji:"🥷",colorClass:"text-violet-600 dark:text-violet-400",bgClass:"bg-violet-50 dark:bg-violet-900/10"},trinity_delegate:{label:"Trinity",emoji:"👩‍💻",colorClass:"text-teal-600 dark:text-teal-400",bgClass:"bg-teal-50 dark:bg-teal-900/10"},smith_delegate:{label:"Smith",emoji:"🕶️",colorClass:"text-gray-500 dark:text-gray-400",bgClass:"bg-gray-50 dark:bg-zinc-900"}};function O(r){return r?.task??r?.prompt??""}function be(r){if(typeof r!="string")return String(r);try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}}const ye=({group:r})=>{const[n,i]=l.useState(!1),d=ue[r.call.name]??{label:r.call.name,emoji:"🤖",colorClass:"text-gray-500",bgClass:"bg-gray-50 dark:bg-zinc-900"},p=r.result!==null,x=r.result?.content??"",c=x.startsWith("❌")||x.toLowerCase().startsWith("error"),u=O(r.call.args).slice(0,100),m=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 ${d.bgClass}`,children:[e.jsxs("button",{onClick:()=>i(!n),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:d.emoji}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:`text-xs font-semibold ${d.colorClass}`,children:[d.label,m?` · ${m}`:""]}),u&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-matrix-secondary/60 truncate mt-0.5",children:u})]}),p?c?e.jsx(G,{size:14,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(K,{size:14,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):e.jsx(q,{size:14,className:"text-gray-400 animate-spin flex-shrink-0"}),e.jsx($,{size:13,className:`text-gray-400 dark:text-matrix-secondary/40 flex-shrink-0 transition-transform duration-200 ${n?"rotate-180":""}`})]}),e.jsx(B,{initial:!1,children:n&&e.jsx(L.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:[O(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:O(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:be(x)})]})]})})})]})};function fe(r){return r==null||r===0?null:r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function R(r){return r>=1e3?`${(r/1e3).toFixed(1)}k`:String(r)}const ke=({message:r})=>{const n=r.usage_metadata,i=n?.input_tokens??n?.prompt_tokens??0,d=n?.output_tokens??n?.completion_tokens??0,p=i>0||d>0,x=fe(r.duration_ms),c=r.model,u=r.sati_memories_count??null;if(!p&&!x&&!c&&u==null)return null;const m=c?(c.includes(":")?c.split(":").pop():c)?.split("-").slice(0,4).join("-")??c: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:c??"",children:m}),p&&e.jsxs("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:["↑",R(i)," ↓",R(d)]}),x&&e.jsx("span",{className:"text-[11px] font-mono text-gray-400 dark:text-matrix-secondary/40",children:x}),u!=null&&u>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(te,{size:10}),u]})]})},je=[{name:"apoc",emoji:"🧑‍🔬",description:"Filesystem, shell & git",color:"amber"},{name:"keymaker",emoji:"🗝️",description:"Quick inline tasks",color:"purple"},{name:"neo",emoji:"🥷",description:"MCP tool orchestration",color:"violet"},{name:"trinity",emoji:"👩‍💻",description:"Database specialist",color:"teal"}],J={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"};function ve(r){try{return JSON.stringify(JSON.parse(r),null,2)}catch{return r}}function we(r){return r.session_id?.startsWith("sati-evaluation-")===!0||r.tool_name?.toLowerCase().includes("sati")===!0}const Ne=({message:r})=>{const[n,i]=l.useState(!1),d=we(r),p=d?r.tool_name==="sati_evaluation_output"?"Sati · memory update":"Sati · analysis":r.tool_name??"tool result";return e.jsxs("details",{open:n,onToggle:x=>i(x.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:d?"🧠":"🔧"}),e.jsx("span",{children:p}),e.jsx($,{size:11,className:`transition-transform duration-200 ${n?"rotate-180":""}`})]}),e.jsx("div",{className:"flex-1 h-px bg-gray-200 dark:bg-matrix-primary/20"})]}),n&&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:ve(r.content)})]})},Se={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})},Ce=({messages:r,onSendMessage:n,isLoading:i,activeSessionId:d,activeSession:p,onToggleSidebar:x})=>{const[c,u]=l.useState(""),[m,v]=l.useState([]),[g,b]=l.useState(null),[w,k]=l.useState(0),[z,I]=l.useState([]),D=l.useRef(null),N=l.useRef(null);l.useEffect(()=>{D.current?.scrollIntoView({behavior:"smooth"})},[r,i]),l.useEffect(()=>{const t=N.current;t&&(t.style.height="auto",t.style.height=t.scrollHeight+"px")},[c]),l.useEffect(()=>{oe.get("/smiths").then(t=>I(t.smiths.map(s=>({name:s.name,emoji:"🕶️",description:"Remote Smith agent",color:"gray"})))).catch(()=>{})},[]);const _=[...je,...z],o=g?_.filter(t=>t.name.toLowerCase().startsWith(g.query.toLowerCase())):[],S=t=>{if(!g)return;const s=c.slice(0,g.startIdx),f=c.slice(g.startIdx+1+g.query.length),M=(s+f).replace(/ +/g," ").trim();u(M),v(j=>j.includes(t)?j:[...j,t]),b(null),k(0),setTimeout(()=>N.current?.focus(),0)},E=t=>{v(s=>s.filter(f=>f!==t))},a=t=>{const s=t.target.value;u(s);const f=t.target.selectionStart??s.length,j=s.slice(0,f).match(/@(\w*)$/);j?(b({query:j[1],startIdx:f-j[0].length}),k(0)):b(null)},h=()=>{if(!(c.trim()||m.length>0)||i)return;const s=[...m.map(f=>`@${f}`),c.trim()].filter(Boolean);n(s.join(" ")),u(""),v([]),b(null),N.current&&(N.current.style.height="auto")},y=t=>{if(g&&o.length>0){if(t.key==="ArrowDown"){t.preventDefault(),k(s=>(s+1)%o.length);return}if(t.key==="ArrowUp"){t.preventDefault(),k(s=>(s-1+o.length)%o.length);return}if(t.key==="Tab"||t.key==="Enter"){t.preventDefault(),S(o[w].name);return}if(t.key==="Escape"){t.preventDefault(),b(null);return}}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),h())},C=t=>_.find(s=>s.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:[x&&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:x,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(ae,{size:20})}),e.jsx("span",{className:"text-sm font-semibold text-gray-800 dark:text-matrix-highlight truncate flex-1",children:p?.title??(d?"Chat":"Morpheus")})]}),d?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0 px-4 py-5 space-y-4",children:[le(r).map(t=>{const{message:s,toolGroups:f}=t;if(s.type==="tool")return e.jsx("div",{className:"px-2 py-0.5",children:e.jsx(Ne,{message:s})},t.index);const M=s.type==="human";return e.jsxs("div",{className:`flex items-end gap-2.5 ${M?"justify-end":"justify-start"}`,children:[!M&&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(T,{size:14})}),e.jsxs("div",{className:`
5
+ max-w-[85%] md:max-w-[72%] min-w-0
6
+ ${M?"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
+ `,children:[M&&e.jsxs(e.Fragment,{children:[s.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(se,{size:11}),e.jsxs("span",{className:"text-[10px] font-mono tracking-wide",children:["voice · ",s.audio_duration_seconds,"s"]})]}),e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap break-words",children:s.content})]}),s.type==="ai"&&e.jsxs(e.Fragment,{children:[f&&f.length>0&&e.jsx("div",{className:"mb-2.5 space-y-1",children:f.map(j=>de(j.call.name)?e.jsx(ye,{group:j},j.call.id):e.jsx(ge,{group:j},j.call.id))}),s.content&&e.jsx("div",{className:`
8
+ prose prose-sm dark:prose-invert max-w-none
9
+ prose-p:my-1.5 prose-p:leading-relaxed
10
+ prose-headings:my-2 prose-headings:font-semibold
11
+ prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5
12
+ prose-pre:my-2 prose-pre:rounded-lg prose-pre:text-xs
13
+ prose-code:text-[0.8em] prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:font-mono
14
+ prose-table:my-0 prose-thead:border-0 prose-tbody:border-0
15
+ prose-tr:border-0 prose-th:p-0 prose-td:p-0
16
+ dark:prose-p:text-matrix-secondary
17
+ dark:prose-headings:text-matrix-highlight
18
+ dark:prose-strong:text-matrix-highlight
19
+ dark:prose-li:text-matrix-secondary
20
+ dark:prose-code:text-matrix-highlight dark:prose-code:bg-black/60
21
+ dark:prose-pre:bg-black dark:prose-pre:border dark:prose-pre:border-matrix-primary/30
22
+ `,children:e.jsx(ce,{remarkPlugins:[xe],components:Se,children:s.content})}),e.jsx(ke,{message:s})]})]}),M&&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(ie,{size:14})})]},t.index)}),i&&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(T,{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:D})]}),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:[g&&o.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:o.map((t,s)=>e.jsx("li",{children:e.jsxs("button",{type:"button",onMouseDown:f=>{f.preventDefault(),S(t.name)},onMouseEnter:()=>k(s),className:`
23
+ w-full flex items-center gap-3 px-3 py-2 text-left transition-colors
24
+ ${s===w?"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})]}),s===w&&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))})]}),m.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:m.map(t=>{const s=C(t),f=J[s.color]??J.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 ${f}`,children:[e.jsx("span",{className:"leading-none",children:s.emoji}),e.jsxs("span",{children:["@",t]}),e.jsx("button",{type:"button",onClick:()=>E(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(W,{size:10})})]},t)})}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),h()},className:"flex items-end gap-2",children:[e.jsx("textarea",{ref:N,value:c,onChange:a,onKeyDown:y,placeholder:"Message Morpheus… (type @ to mention an agent)",rows:1,disabled:i,className:`
26
+ flex-1 resize-none max-h-40 overflow-y-auto
27
+ bg-gray-100 dark:bg-zinc-900
28
+ border border-gray-300 dark:border-matrix-primary/60
29
+ rounded-xl px-4 py-3
30
+ text-sm leading-relaxed
31
+ text-gray-800 dark:text-matrix-secondary
32
+ placeholder-gray-400 dark:placeholder-matrix-secondary/40
33
+ focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-transparent
34
+ disabled:opacity-50
35
+ transition-all duration-200
36
+ `}),e.jsx("button",{type:"submit",disabled:!c.trim()&&m.length===0||i,className:"flex-shrink-0 p-3 rounded-xl bg-azure-primary text-white dark:bg-matrix-secondary dark:text-black hover:bg-azure-secondary dark:hover:bg-matrix-highlight disabled:opacity-40 disabled:cursor-not-allowed transition-colors shadow-sm",children:e.jsx(ne,{size:18})})]}),e.jsx("p",{className:"mt-1.5 text-center text-[11px] text-gray-300 dark:text-matrix-secondary/25 select-none",children:"Enter to send · Shift+Enter for newline · @ to mention an agent"})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-azure-primary/10 dark:bg-matrix-primary/10 flex items-center justify-center",children:e.jsx(T,{size:30,className:"text-azure-primary/60 dark:text-matrix-highlight/50"})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-base font-semibold text-gray-700 dark:text-matrix-highlight",children:"Morpheus is ready"}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-matrix-secondary/60 max-w-[240px] leading-relaxed",children:"Select a session from the sidebar or start a new chat."})]})]})]})},Te=()=>{const[r,n]=l.useState([]),[i,d]=l.useState(null),[p,x]=l.useState([]),[c,u]=l.useState(!1),[m,v]=l.useState(()=>typeof window<"u"?window.innerWidth>=768:!0),g=l.useRef(!1);l.useEffect(()=>{g.current=c},[c]),l.useEffect(()=>{if(!i)return;const a=setInterval(async()=>{if(!g.current)try{const y=(await A.getMessages(i)).filter(C=>C.type!=="system");x(C=>{if(y.length!==C.length)return y;const t=y.at(-1)?.created_at??0,s=C.at(-1)?.created_at??0;return t>s?y:C})}catch{}},3e3);return()=>clearInterval(a)},[i]);const[b,w]=l.useState({isOpen:!1,title:"",description:"",onConfirm:()=>{}}),k=async()=>{try{const a=await A.getSessions();return n(a),a}catch(a){return console.error("Failed to load sessions:",a),[]}};l.useEffect(()=>{k().then(a=>{if(!a.length)return;const h=sessionStorage.getItem("morpheus.chat.uiSessionId"),y=h&&a.find(C=>C.id===h)?h:a[0].id;d(y)})},[]),l.useEffect(()=>{i?(z(i),sessionStorage.setItem("morpheus.chat.uiSessionId",i)):x([])},[i]);const z=async a=>{try{const h=await A.getMessages(a);x(h.filter(y=>y.type!=="system"))}catch(h){console.error("Failed to load messages:",h)}},I=async()=>{try{const a=await A.createSession();await k(),d(a.id),window.innerWidth<768&&v(!1)}catch(a){console.error("Failed to create session:",a)}},D=a=>{d(a),window.innerWidth<768&&v(!1)},N=async a=>{if(!i)return;const h={type:"human",content:a};x(y=>[...y,h]),u(!0);try{await A.sendMessage(i,a),await z(i),await k()}catch(y){console.error("Failed to send message:",y)}finally{u(!1)}},_=a=>{w({isOpen:!0,title:"Archive Session",description:"Are you sure you want to archive this session? It will be moved to the archives.",confirmJson:"Archive",onConfirm:async()=>{try{await A.archiveSession(a),i===a&&d(null),await k()}catch(h){console.error("Failed to archive session:",h)}}})},o=a=>{w({isOpen:!0,title:"Delete Session",description:"Are you sure you want to DELETE this session? This action cannot be undone.",confirmJson:"Delete",variant:"destructive",onConfirm:async()=>{try{await A.deleteSession(a),i===a&&d(null),await k()}catch(h){console.error("Failed to delete session:",h)}}})},S=async(a,h)=>{try{await A.renameSession(a,h),await k()}catch(y){console.error("Failed to rename session:",y)}},E=r.find(a=>a.id===i)??null;return e.jsxs("div",{className:"flex h-full w-full overflow-hidden bg-white dark:bg-black relative",children:[m&&e.jsx("div",{className:"fixed inset-0 bg-black/40 z-20 md:hidden",onClick:()=>v(!1)}),e.jsx("div",{className:`
37
+ fixed top-16 bottom-0 left-0 z-40 flex
38
+ md:relative md:inset-auto md:z-auto md:translate-x-0
39
+ transition-transform duration-300 ease-out
40
+ ${m?"translate-x-0":"-translate-x-full"}
41
+ `,children:e.jsx(pe,{sessions:r,activeSessionId:i,onSelectSession:D,onCreateSession:I,onArchiveSession:_,onDeleteSession:o,onRenameSession:S,isOpen:m,toggleSidebar:()=>v(!m)})}),e.jsx("div",{className:"flex-1 flex flex-col h-full overflow-hidden min-w-0",children:e.jsx(Ce,{messages:p,onSendMessage:N,isLoading:c,activeSessionId:i,activeSession:E,onToggleSidebar:()=>v(!m)})}),e.jsx(me,{isOpen:b.isOpen,onClose:()=>w(a=>({...a,isOpen:!1})),onConfirm:b.onConfirm,title:b.title,description:b.description,confirmJson:b.confirmJson,variant:b.variant})]})};export{Te as ChatPage};
@@ -0,0 +1 @@
1
+ import{j as e}from"./vendor-motion-C3CZ8ZlO.js";import{r as n}from"./vendor-react-DikRIOlj.js";import{a as L,b as I,c as y,u as O}from"./chronos-BvMxfBQH.js";import{D as R}from"./DeleteConfirmationModal-A8EmnHoa.js";import{P as J}from"./Pagination-JsiwxVNQ.js";import{ad as M,ae as U,af as B,ag as H,ah as W,z as $,h as T,X as q,a5 as F}from"./vendor-icons-BVuQI-6R.js";import{m as z}from"./vendor-utils-D4NnWbOU.js";import{T as C,S}from"./SelectInput-KVLsnfra.js";import"./index-Cwqr-n0Y.js";const Y={running:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",success:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",failed:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",timeout:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"};function X({jobId:s}){const{data:i,isLoading:m}=L(s,50);return m?e.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary animate-pulse",children:"Loading history…"}):!i||i.length===0?e.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary italic",children:"No executions yet."}):e.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary dark:bg-zinc-900 overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary",children:[e.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Triggered At"}),e.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Completed At"}),e.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Status"}),e.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Error"})]})}),e.jsx("tbody",{children:i.map(r=>e.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0",children:[e.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:new Date(r.triggered_at).toLocaleString()}),e.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:r.completed_at?new Date(r.completed_at).toLocaleString():"—"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${Y[r.status]}`,children:r.status})}),e.jsx("td",{className:"px-3 py-2 dark:text-red-400 max-w-xs truncate",children:r.error??"—"})]},r.id))})]})})}function Z({enabled:s}){return e.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-bold uppercase ${s?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-tertiary"}`,children:s?"Enabled":"Disabled"})}function _(s,i){return s.length>i?`${s.slice(0,i)}…`:s}function E(s){return s?new Date(s).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function K({onEdit:s}){const[i,m]=n.useState(1),[r,u]=n.useState(20),{data:o,isLoading:c}=I({page:i,per_page:r}),d=o?.data??[],[h,l]=n.useState(null),[x,g]=n.useState(null),[p,b]=n.useState(null),f=t=>{u(t),m(1)},k=async t=>{g(t.id);try{t.enabled?await y.disableJob(t.id):await y.enableJob(t.id),await z(N=>typeof N=="string"&&N.startsWith("/chronos"))}finally{g(null)}},v=async()=>{if(p){g(p.id);try{await y.deleteJob(p.id),await z(t=>typeof t=="string"&&t.startsWith("/chronos"))}finally{g(null),b(null)}}};return c?e.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary animate-pulse",children:"Loading jobs…"}):!c&&d.length===0&&i===1?e.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary",children:["No Chronos jobs yet. Click ",e.jsx("strong",{className:"dark:text-matrix-highlight",children:"New Job"})," to get started."]}):e.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary overflow-hidden",children:[e.jsxs("table",{className:"w-full text-sm font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900",children:[e.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Prompt"}),e.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden md:table-cell",children:"Schedule"}),e.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Next Run"}),e.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Last Run"}),e.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium text-right",children:"Actions"})]})}),e.jsx("tbody",{children:d.map(t=>e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0 hover:bg-azure-hover dark:hover:bg-matrix-primary/10 transition-colors",children:[e.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary max-w-xs",children:[e.jsx("span",{title:t.prompt,children:_(t.prompt,50)}),e.jsx("div",{className:"text-xs text-azure-text-muted dark:text-matrix-tertiary",children:t.created_by})]}),e.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden md:table-cell text-xs",children:[e.jsx("div",{className:"capitalize",children:t.schedule_type}),e.jsx("div",{className:"text-azure-text-muted dark:text-matrix-tertiary truncate max-w-[140px]",title:t.schedule_expression,children:t.schedule_expression})]}),e.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:E(t.next_run_at)}),e.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:E(t.last_run_at)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(Z,{enabled:t.enabled})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{title:h===t.id?"Hide history":"View history",onClick:()=>l(h===t.id?null:t.id),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:h===t.id?e.jsx(M,{className:"w-4 h-4"}):e.jsx(U,{className:"w-4 h-4"})}),e.jsx("button",{title:"Edit",onClick:()=>s(t),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx("button",{title:t.enabled?"Disable":"Enable",onClick:()=>k(t),disabled:x===t.id,className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors disabled:opacity-40",children:t.enabled?e.jsx(H,{className:"w-4 h-4"}):e.jsx(W,{className:"w-4 h-4"})}),e.jsx("button",{title:"Delete",onClick:()=>b(t),disabled:x===t.id,className:"p-1.5 rounded text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-40",children:e.jsx($,{className:"w-4 h-4"})})]})})]},t.id),h===t.id&&e.jsx("tr",{className:"bg-azure-surface dark:bg-zinc-900/50",children:e.jsxs("td",{colSpan:6,className:"px-4 py-3",children:[e.jsx("div",{className:"text-xs font-bold dark:text-matrix-highlight mb-2",children:"Execution History"}),e.jsx(X,{jobId:t.id})]})},`${t.id}-history`)]}))})]}),o&&o.total_pages>1&&e.jsx(J,{page:i,totalPages:o.total_pages,perPage:r,total:o.total,onPageChange:m,onPerPageChange:f}),e.jsx(R,{isOpen:!!p,onClose:()=>b(null),onConfirm:v,title:"Delete Chronos Job",message:p?`Delete job "${_(p.prompt,60)}"? This action cannot be undone.`:""})]})}function V({scheduleExpression:s,scheduleType:i,timezone:m}){const[r,u]=n.useState(null),[o,c]=n.useState(null),d=n.useRef(null);if(n.useEffect(()=>{if(!s.trim()){u(null),c(null);return}return d.current&&clearTimeout(d.current),d.current=setTimeout(async()=>{try{const l=await y.preview(s,i,m);u(l),c(null)}catch(l){c(l.message??"Invalid expression"),u(null)}},500),()=>{d.current&&clearTimeout(d.current)}},[s,i,m]),!s.trim())return null;const h=(l,x)=>{try{return new Date(l).toLocaleString("pt-BR",{timeZone:x,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return new Date(l).toLocaleString()}};return e.jsx("div",{className:"mt-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900 p-3 text-sm",children:o?e.jsxs("p",{className:"text-red-500 dark:text-red-400 flex items-center gap-1.5",children:[e.jsx("span",{children:"⚠"})," ",o]}):r?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-azure-text-secondary dark:text-matrix-secondary",children:[e.jsx(T,{className:"w-3.5 h-3.5 text-azure-primary dark:text-matrix-highlight shrink-0"}),e.jsx("span",{className:"font-medium dark:text-matrix-highlight",children:"Next run:"}),e.jsx("span",{children:h(r.next_run_at,m||"UTC")})]}),r.human_readable&&e.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary/70 pl-5",children:r.human_readable}),r.next_occurrences.length>0&&e.jsx("div",{className:"pl-5 space-y-0.5",children:r.next_occurrences.map((l,x)=>e.jsxs("p",{className:"text-azure-text-muted dark:text-matrix-tertiary text-xs",children:["#",x+2,": ",l]},x))})]}):e.jsx("p",{className:"text-azure-text-muted dark:text-matrix-tertiary italic",children:"Parsing…"})})}const G=["UTC","America/Sao_Paulo","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Mexico_City","America/Buenos_Aires","America/Bogota","America/Lima","America/Santiago","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Lisbon","Europe/Moscow","Europe/Istanbul","Asia/Dubai","Asia/Kolkata","Asia/Bangkok","Asia/Singapore","Asia/Tokyo","Asia/Shanghai","Asia/Seoul","Asia/Jakarta","Australia/Sydney","Australia/Melbourne","Pacific/Auckland","Africa/Cairo","Africa/Johannesburg","Africa/Lagos"],Q=[{value:"telegram",label:"Telegram"},{value:"discord",label:"Discord"}],ee=[{value:"once",label:"Once"},{value:"cron",label:"Recurring (Cron)"},{value:"interval",label:"Recurring (Interval)"}],te={once:'e.g. "in 30 minutes", "tomorrow at 9am", "2026-03-01T09:00:00"',cron:'e.g. "0 9 * * 1-5" (weekdays at 9am)',interval:'e.g. "every 30 minutes", "every sunday at 9am", "every weekday"'};function re({isOpen:s,onClose:i,onCreated:m,editJob:r}){const u=!!r,{data:o}=O(),[c,d]=n.useState(""),[h,l]=n.useState("once"),[x,g]=n.useState(""),[p,b]=n.useState("UTC"),[f,k]=n.useState([]),[v,t]=n.useState(null),[N,w]=n.useState(!1),A=a=>{k(j=>j.includes(a)?j.filter(D=>D!==a):[...j,a])};n.useEffect(()=>{r?(d(r.prompt),l(r.schedule_type),g(r.schedule_expression),b(r.timezone),k(r.notify_channels??[])):(d(""),l("once"),g(""),b(o?.timezone??"UTC"),k([])),t(null)},[r,s,o?.timezone]);const P=async()=>{if(t(null),!c.trim()){t("Prompt is required");return}if(!x.trim()){t("Schedule expression is required");return}w(!0);try{if(u&&r){const a={prompt:c,schedule_expression:x,timezone:p,notify_channels:f};await y.updateJob(r.id,a)}else{const a={prompt:c,schedule_type:h,schedule_expression:x,timezone:p,notify_channels:f};await y.createJob(a)}await z(a=>typeof a=="string"&&a.startsWith("/chronos")),m(),i()}catch(a){t(a.message??"Failed to save job")}finally{w(!1)}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:i}),e.jsxs("div",{className:"relative z-10 w-full max-w-lg mx-4 rounded-lg border border-azure-border dark:border-matrix-primary bg-white dark:bg-black shadow-xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-azure-border dark:border-matrix-primary",children:[e.jsx("h2",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight font-mono",children:u?"Edit Chronos Job":"New Chronos Job"}),e.jsx("button",{onClick:i,className:"p-1 rounded text-azure-text-muted dark:text-matrix-tertiary hover:text-azure-text-primary dark:hover:text-matrix-highlight transition-colors",children:e.jsx(q,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(C,{label:"Prompt",value:c,onChange:a=>d(a.target.value),placeholder:"What should the Oracle do when this job triggers?"}),!u&&e.jsx(S,{label:"Schedule Type",value:h,onChange:a=>l(a.target.value),options:ee}),e.jsxs("div",{children:[e.jsx(C,{label:"Schedule Expression",value:x,onChange:a=>g(a.target.value),placeholder:te[h]}),e.jsx(V,{scheduleExpression:x,scheduleType:h,timezone:p})]}),e.jsx(S,{label:"Timezone",value:p,onChange:a=>b(a.target.value),options:G.map(a=>({value:a,label:a}))}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:["Notify Channels ",e.jsx("span",{className:"text-xs font-normal opacity-60",children:"(empty = all active channels)"})]}),e.jsx("div",{className:"flex gap-4",children:Q.map(({value:a,label:j})=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f.includes(a),onChange:()=>A(a),className:"rounded border-azure-border dark:border-matrix-primary accent-azure-primary dark:accent-matrix-highlight"}),e.jsx("span",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary capitalize",children:j})]},a))})]}),v&&e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:v})]}),e.jsxs("div",{className:"flex justify-end gap-3 p-4 border-t border-azure-border dark:border-matrix-primary",children:[e.jsx("button",{onClick:i,className:"px-4 py-2 rounded text-sm border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors font-mono",children:"Cancel"}),e.jsx("button",{onClick:P,disabled:N,className:"px-4 py-2 rounded text-sm bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight font-bold hover:opacity-90 disabled:opacity-50 transition-opacity font-mono",children:N?"Saving…":u?"Update":"Create"})]})]})]}):null}function me(){const[s,i]=n.useState(!1),[m,r]=n.useState(null),u=d=>{r(d),i(!0)},o=()=>{i(!1),r(null)},c=()=>{z(d=>typeof d=="string"&&d.startsWith("/chronos"))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-azure-primary/10 dark:bg-matrix-highlight/10 border border-azure-primary/20 dark:border-matrix-highlight/30 flex items-center justify-center",children:e.jsx(T,{className:"w-5 h-5 text-azure-primary dark:text-matrix-highlight"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-azure-text dark:text-matrix-highlight",children:"Chronos"}),e.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-tertiary mt-0.5",children:"Temporal Intent Engine — schedule prompts for the Oracle."})]})]}),e.jsxs("button",{onClick:()=>{r(null),i(!0)},className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[e.jsx(F,{className:"w-4 h-4"}),"New Job"]})]}),e.jsx(K,{onEdit:u}),e.jsx(re,{isOpen:s,onClose:o,onCreated:c,editJob:m})]})}export{me as ChronosPage};
@@ -1 +1 @@
1
- import{j as r}from"./vendor-motion-C3CZ8ZlO.js";import{D as o,d as x,e as n,j as c,k as g,B as t}from"./index-CQIUjucB.js";function p({isOpen:i,onClose:a,onConfirm:s,title:d,description:l,confirmJson:m="Confirm",variant:e="default"}){return r.jsx(o,{open:i,onOpenChange:a,children:r.jsxs(x,{className:"sm:max-w-md bg-azure-surface dark:bg-black border-azure-border dark:border-matrix-primary",children:[r.jsx(n,{children:r.jsx(c,{className:"text-azure-primary dark:text-matrix-highlight flex items-center gap-2",children:d})}),r.jsx("div",{className:"py-4",children:r.jsx("p",{className:"text-azure-text-secondary dark:text-matrix-secondary",children:l})}),r.jsxs(g,{className:"flex flex-col sm:flex-row gap-3 sm:justify-end",children:[r.jsx(t,{variant:"outline",onClick:a,className:"dark:border-matrix-primary dark:text-matrix-secondary dark:hover:bg-matrix-primary/20",children:"Cancel"}),r.jsx(t,{variant:e,onClick:()=>{s(),a()},className:e==="destructive"?"dark:bg-red-900/50 dark:text-red-200 dark:hover:bg-red-800/60":"dark:bg-matrix-primary dark:text-black dark:hover:bg-matrix-highlight",children:m})]})]})})}export{p as C};
1
+ import{j as r}from"./vendor-motion-C3CZ8ZlO.js";import{D as o,d as x,e as n,j as c,k as g,B as t}from"./index-Cwqr-n0Y.js";function p({isOpen:i,onClose:a,onConfirm:s,title:d,description:l,confirmJson:m="Confirm",variant:e="default"}){return r.jsx(o,{open:i,onOpenChange:a,children:r.jsxs(x,{className:"sm:max-w-md bg-azure-surface dark:bg-black border-azure-border dark:border-matrix-primary",children:[r.jsx(n,{children:r.jsx(c,{className:"text-azure-primary dark:text-matrix-highlight flex items-center gap-2",children:d})}),r.jsx("div",{className:"py-4",children:r.jsx("p",{className:"text-azure-text-secondary dark:text-matrix-secondary",children:l})}),r.jsxs(g,{className:"flex flex-col sm:flex-row gap-3 sm:justify-end",children:[r.jsx(t,{variant:"outline",onClick:a,className:"dark:border-matrix-primary dark:text-matrix-secondary dark:hover:bg-matrix-primary/20",children:"Cancel"}),r.jsx(t,{variant:e,onClick:()=>{s(),a()},className:e==="destructive"?"dark:bg-red-900/50 dark:text-red-200 dark:hover:bg-red-800/60":"dark:bg-matrix-primary dark:text-black dark:hover:bg-matrix-highlight",children:m})]})]})})}export{p as C};