dashboard.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Switchboard Dashboard</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <style>
  8. * { box-sizing: border-box; margin: 0; padding: 0; }
  9. body {
  10. font-family: 'Courier New', 'Consolas', monospace;
  11. background: #f5f5dc;
  12. color: #000;
  13. padding: 20px;
  14. line-height: 1.6;
  15. }
  16. .container { max-width: 1400px; margin: 0 auto; background: white; padding: 40px; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
  17. h1 {
  18. color: #000;
  19. margin-bottom: 10px;
  20. font-size: 18px;
  21. letter-spacing: 3px;
  22. font-weight: bold;
  23. text-transform: uppercase;
  24. }
  25. h2 {
  26. color: #000;
  27. margin: 30px 0 15px;
  28. font-size: 14px;
  29. letter-spacing: 2px;
  30. font-weight: bold;
  31. text-transform: uppercase;
  32. border-bottom: 2px solid #000;
  33. padding-bottom: 5px;
  34. }
  35. /* API Key Section */
  36. #api-key-section {
  37. background: #fafafa;
  38. border: 2px solid #000;
  39. padding: 20px;
  40. margin-bottom: 30px;
  41. }
  42. #api-key-section input {
  43. width: 100%;
  44. padding: 10px;
  45. border: 2px solid #666;
  46. background: white;
  47. color: #000;
  48. font-family: 'Courier New', monospace;
  49. font-size: 14px;
  50. }
  51. #api-key-section input:focus {
  52. outline: none;
  53. border-color: #000;
  54. box-shadow: none;
  55. }
  56. /* Buttons */
  57. button {
  58. background: white;
  59. color: #000;
  60. border: 2px solid #000;
  61. padding: 8px 16px;
  62. cursor: pointer;
  63. font-size: 12px;
  64. font-family: 'Courier New', monospace;
  65. margin-top: 10px;
  66. text-transform: uppercase;
  67. letter-spacing: 1px;
  68. font-weight: bold;
  69. }
  70. button:hover {
  71. background: #000;
  72. color: white;
  73. }
  74. button.danger {
  75. border-color: #000;
  76. color: #000;
  77. }
  78. button.danger:hover {
  79. background: #000;
  80. color: white;
  81. }
  82. /* Tabs */
  83. .tabs {
  84. display: flex;
  85. gap: 2px;
  86. margin-bottom: 0;
  87. border-bottom: 3px solid #000;
  88. }
  89. .tab {
  90. padding: 10px 20px;
  91. background: #e8e8e8;
  92. color: #000;
  93. border: 2px solid #000;
  94. border-bottom: none;
  95. cursor: pointer;
  96. font-weight: bold;
  97. font-family: 'Courier New', monospace;
  98. text-transform: uppercase;
  99. letter-spacing: 1px;
  100. font-size: 12px;
  101. }
  102. .tab:hover { background: #d0d0d0; }
  103. .tab.active {
  104. background: white;
  105. color: #000;
  106. border-bottom: 3px solid white;
  107. margin-bottom: -3px;
  108. }
  109. /* Content */
  110. .content {
  111. background: white;
  112. border: 2px solid #000;
  113. border-top: none;
  114. padding: 20px;
  115. display: none;
  116. }
  117. .content.active { display: block; }
  118. /* Tables */
  119. table {
  120. width: 100%;
  121. border-collapse: collapse;
  122. margin-top: 15px;
  123. border: 2px solid #000;
  124. }
  125. th, td {
  126. padding: 10px 12px;
  127. text-align: left;
  128. border: 1px solid #000;
  129. }
  130. th {
  131. background: #f0f0f0;
  132. font-weight: bold;
  133. color: #000;
  134. text-transform: uppercase;
  135. font-size: 11px;
  136. letter-spacing: 1px;
  137. }
  138. tr:hover { background: #fafafa; }
  139. td { font-size: 13px; }
  140. /* Forms */
  141. .form-group {
  142. margin-bottom: 20px;
  143. }
  144. label {
  145. display: block;
  146. margin-bottom: 8px;
  147. font-weight: bold;
  148. color: #000;
  149. text-transform: uppercase;
  150. font-size: 11px;
  151. letter-spacing: 1px;
  152. }
  153. input[type="text"], input[type="datetime-local"], textarea, select {
  154. width: 100%;
  155. padding: 10px;
  156. border: 2px solid #666;
  157. background: white;
  158. color: #000;
  159. font-family: 'Courier New', monospace;
  160. font-size: 14px;
  161. }
  162. input:focus, textarea:focus, select:focus {
  163. outline: none;
  164. border-color: #000;
  165. box-shadow: none;
  166. }
  167. textarea { min-height: 80px; }
  168. small { color: #666; font-size: 11px; }
  169. /* Status badges */
  170. .badge {
  171. padding: 4px 10px;
  172. border: 2px solid;
  173. font-size: 11px;
  174. font-weight: bold;
  175. font-family: 'Courier New', monospace;
  176. text-transform: uppercase;
  177. letter-spacing: 1px;
  178. }
  179. .badge.success {
  180. border-color: #000;
  181. color: #000;
  182. background: white;
  183. }
  184. .badge.failed {
  185. border-color: #000;
  186. color: white;
  187. background: #000;
  188. }
  189. .hidden { display: none; }
  190. .error { color: #000; margin-top: 10px; font-weight: bold; }
  191. .empty { text-align: center; padding: 40px; color: #666; }
  192. /* Loading spinner */
  193. .loading {
  194. text-align: center;
  195. padding: 40px;
  196. color: #000;
  197. }
  198. .spinner {
  199. display: inline-block;
  200. width: 40px;
  201. height: 40px;
  202. border: 4px solid #e0e0e0;
  203. border-top-color: #000;
  204. border-radius: 50%;
  205. animation: spin 1s linear infinite;
  206. margin-bottom: 10px;
  207. }
  208. @keyframes spin {
  209. to { transform: rotate(360deg); }
  210. }
  211. @keyframes blink {
  212. 0%, 50% { opacity: 1; }
  213. 51%, 100% { opacity: 0.3; }
  214. }
  215. .blink { animation: blink 1s infinite; }
  216. </style>
  217. </head>
  218. <body>
  219. <div class="container">
  220. <h1>LETTA SWITCHBOARD — MESSAGE ROUTING SERVICE</h1>
  221. <div style="border: 2px solid #000; padding: 10px; margin-bottom: 30px; background: #fafafa;">
  222. <div style="font-size: 11px; line-height: 1.8;">
  223. <strong>SYSTEM:</strong> MESSAGE ROUTING TERMINAL<br>
  224. <strong>VERSION:</strong> 1.0.0<br>
  225. <strong>STATUS:</strong> OPERATIONAL<br>
  226. <strong>PROTOCOL:</strong> REST API + SCHEDULED EXECUTION
  227. </div>
  228. </div>
  229. <!-- API Key Input -->
  230. <div id="api-key-section">
  231. <label for="api-key-input">AUTHENTICATION</label>
  232. <input type="password" id="api-key-input" placeholder="sk-let-...">
  233. <button onclick="saveApiKey()">SAVE KEY</button>
  234. <button onclick="clearApiKey()" class="danger">CLEAR KEY</button>
  235. <div id="api-key-status"></div>
  236. </div>
  237. <div id="main-content" class="hidden">
  238. <!-- Tabs -->
  239. <div class="tabs">
  240. <button class="tab active" onclick="showTab('schedules')">SCHEDULES</button>
  241. <button class="tab" onclick="showTab('create')">CREATE NEW</button>
  242. <button class="tab" onclick="showTab('results')">RESULTS</button>
  243. </div>
  244. <!-- Schedules Tab -->
  245. <div id="schedules-tab" class="content active">
  246. <h2>ONE-TIME SCHEDULES</h2>
  247. <table id="onetime-table">
  248. <thead>
  249. <tr>
  250. <th>ID</th>
  251. <th>Agent ID</th>
  252. <th>Execute At</th>
  253. <th>Message</th>
  254. <th>Actions</th>
  255. </tr>
  256. </thead>
  257. <tbody></tbody>
  258. </table>
  259. <h2>RECURRING SCHEDULES</h2>
  260. <table id="recurring-table">
  261. <thead>
  262. <tr>
  263. <th>ID</th>
  264. <th>Agent ID</th>
  265. <th>Cron</th>
  266. <th>Message</th>
  267. <th>Last Run</th>
  268. <th>Actions</th>
  269. </tr>
  270. </thead>
  271. <tbody></tbody>
  272. </table>
  273. <button onclick="loadSchedules()" style="margin-top: 20px;">REFRESH</button>
  274. </div>
  275. <!-- Create Tab -->
  276. <div id="create-tab" class="content">
  277. <h2>CREATE SCHEDULE</h2>
  278. <div class="form-group">
  279. <label>SCHEDULE TYPE</label>
  280. <select id="schedule-type" onchange="toggleScheduleType()">
  281. <option value="onetime">One-Time</option>
  282. <option value="recurring">Recurring</option>
  283. </select>
  284. </div>
  285. <div class="form-group">
  286. <label for="agent-id">AGENT ID</label>
  287. <input type="text" id="agent-id" placeholder="agent-xxx">
  288. </div>
  289. <div class="form-group">
  290. <label for="message">MESSAGE</label>
  291. <textarea id="message" placeholder="Your message to the agent"></textarea>
  292. </div>
  293. <div id="onetime-fields">
  294. <div class="form-group">
  295. <label for="execute-at">EXECUTE AT</label>
  296. <input type="datetime-local" id="execute-at">
  297. </div>
  298. <div class="form-group">
  299. <label for="timezone">TIMEZONE</label>
  300. <select id="timezone">
  301. <option value="local" selected>Local Browser Time</option>
  302. <option value="UTC">UTC</option>
  303. <option value="America/New_York">Eastern (US)</option>
  304. <option value="America/Chicago">Central (US)</option>
  305. <option value="America/Denver">Mountain (US)</option>
  306. <option value="America/Los_Angeles">Pacific (US)</option>
  307. <option value="Europe/London">London</option>
  308. <option value="Europe/Paris">Paris</option>
  309. <option value="Asia/Tokyo">Tokyo</option>
  310. </select>
  311. <small style="display:block;margin-top:5px;color:#6b7280;">Time will be converted to UTC for storage</small>
  312. </div>
  313. </div>
  314. <div id="recurring-fields" class="hidden">
  315. <div class="form-group">
  316. <label for="cron">CRON EXPRESSION</label>
  317. <input type="text" id="cron" placeholder="0 9 * * 1-5">
  318. <small style="display:block;margin-top:5px;color:#6b7280;">Examples: "0 9 * * *" (daily at 9am), "*/5 * * * *" (every 5 min)</small>
  319. </div>
  320. </div>
  321. <button onclick="createSchedule()">CREATE SCHEDULE</button>
  322. <div id="create-error" class="error"></div>
  323. </div>
  324. <!-- Results Tab -->
  325. <div id="results-tab" class="content">
  326. <h2>EXECUTION RESULTS</h2>
  327. <table id="results-table">
  328. <thead>
  329. <tr>
  330. <th>Schedule ID</th>
  331. <th>Type</th>
  332. <th>Status</th>
  333. <th>Agent ID</th>
  334. <th>Message</th>
  335. <th>Run ID / Error</th>
  336. <th>Executed At</th>
  337. </tr>
  338. </thead>
  339. <tbody></tbody>
  340. </table>
  341. <button onclick="loadResults()" style="margin-top: 20px;">REFRESH</button>
  342. </div>
  343. </div>
  344. </div>
  345. <script>
  346. const API_BASE = window.location.origin;
  347. let API_KEY = sessionStorage.getItem('letta_api_key') || '';
  348. // Initialize
  349. if (API_KEY) {
  350. document.getElementById('api-key-input').value = API_KEY;
  351. document.getElementById('main-content').classList.remove('hidden');
  352. loadSchedules();
  353. loadResults();
  354. }
  355. function saveApiKey() {
  356. API_KEY = document.getElementById('api-key-input').value.trim();
  357. if (!API_KEY) {
  358. alert('ERROR: API KEY REQUIRED');
  359. return;
  360. }
  361. sessionStorage.setItem('letta_api_key', API_KEY);
  362. document.getElementById('main-content').classList.remove('hidden');
  363. document.getElementById('api-key-status').innerHTML = '<p style="color:#000;margin-top:10px;font-weight:bold;">✓ API KEY AUTHENTICATED</p>';
  364. loadSchedules();
  365. loadResults();
  366. }
  367. function clearApiKey() {
  368. sessionStorage.removeItem('letta_api_key');
  369. API_KEY = '';
  370. document.getElementById('api-key-input').value = '';
  371. document.getElementById('main-content').classList.add('hidden');
  372. document.getElementById('api-key-status').innerHTML = '<p style="color:#000;margin-top:10px;font-weight:bold;">✗ SESSION TERMINATED</p>';
  373. }
  374. function showTab(tab) {
  375. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  376. document.querySelectorAll('.content').forEach(c => c.classList.remove('active'));
  377. event.target.classList.add('active');
  378. document.getElementById(`${tab}-tab`).classList.add('active');
  379. }
  380. function toggleScheduleType() {
  381. const type = document.getElementById('schedule-type').value;
  382. document.getElementById('onetime-fields').classList.toggle('hidden', type !== 'onetime');
  383. document.getElementById('recurring-fields').classList.toggle('hidden', type !== 'recurring');
  384. }
  385. async function loadSchedules() {
  386. const onetimeBody = document.querySelector('#onetime-table tbody');
  387. const recurringBody = document.querySelector('#recurring-table tbody');
  388. // Show loading spinners
  389. onetimeBody.innerHTML = '<tr><td colspan="5" class="loading"><div class="spinner"></div><p>Loading...</p></td></tr>';
  390. recurringBody.innerHTML = '<tr><td colspan="6" class="loading"><div class="spinner"></div><p>Loading...</p></td></tr>';
  391. try {
  392. const [onetime, recurring] = await Promise.all([
  393. fetch(`${API_BASE}/schedules/one-time`, {
  394. headers: { 'Authorization': `Bearer ${API_KEY}` }
  395. }).then(r => r.json()),
  396. fetch(`${API_BASE}/schedules/recurring`, {
  397. headers: { 'Authorization': `Bearer ${API_KEY}` }
  398. }).then(r => r.json())
  399. ]);
  400. // One-time schedules
  401. onetimeBody.innerHTML = onetime.length ? onetime.map(s => `
  402. <tr>
  403. <td>${s.id.substring(0, 8)}...</td>
  404. <td>${s.agent_id}</td>
  405. <td>${new Date(s.execute_at).toLocaleString()}</td>
  406. <td>${truncate(s.message, 50)}</td>
  407. <td><button class="danger" onclick="deleteSchedule('one-time', '${s.id}')">DEL</button></td>
  408. </tr>
  409. `).join('') : '<tr><td colspan="5" class="empty">No one-time schedules</td></tr>';
  410. // Recurring schedules
  411. const recurringBody = document.querySelector('#recurring-table tbody');
  412. recurringBody.innerHTML = recurring.length ? recurring.map(s => `
  413. <tr>
  414. <td>${s.id.substring(0, 8)}...</td>
  415. <td>${s.agent_id}</td>
  416. <td>${s.cron}</td>
  417. <td>${truncate(s.message, 50)}</td>
  418. <td>${s.last_run ? new Date(s.last_run).toLocaleString() : 'Never'}</td>
  419. <td><button class="danger" onclick="deleteSchedule('recurring', '${s.id}')">DEL</button></td>
  420. </tr>
  421. `).join('') : '<tr><td colspan="6" class="empty">No recurring schedules</td></tr>';
  422. } catch (error) {
  423. alert('ERROR LOADING SCHEDULES: ' + error.message);
  424. }
  425. }
  426. async function loadResults() {
  427. const resultsBody = document.querySelector('#results-table tbody');
  428. // Show loading spinner
  429. resultsBody.innerHTML = '<tr><td colspan="7" class="loading"><div class="spinner"></div><p>Loading...</p></td></tr>';
  430. try {
  431. const results = await fetch(`${API_BASE}/results`, {
  432. headers: { 'Authorization': `Bearer ${API_KEY}` }
  433. }).then(r => r.json());
  434. resultsBody.innerHTML = results.length ? results.map(r => `
  435. <tr>
  436. <td>${r.schedule_id.substring(0, 8)}...</td>
  437. <td>${r.schedule_type}</td>
  438. <td><span class="badge ${r.status}">${r.status}</span></td>
  439. <td>${r.agent_id}</td>
  440. <td>${truncate(r.message, 30)}</td>
  441. <td>${r.run_id || r.error || 'N/A'}</td>
  442. <td>${new Date(r.executed_at).toLocaleString()}</td>
  443. </tr>
  444. `).join('') : '<tr><td colspan="7" class="empty">No execution results</td></tr>';
  445. } catch (error) {
  446. alert('ERROR LOADING RESULTS: ' + error.message);
  447. }
  448. }
  449. async function createSchedule() {
  450. const type = document.getElementById('schedule-type').value;
  451. const agentId = document.getElementById('agent-id').value.trim();
  452. const message = document.getElementById('message').value.trim();
  453. const errorDiv = document.getElementById('create-error');
  454. errorDiv.textContent = '';
  455. if (!agentId || !message) {
  456. errorDiv.textContent = 'Please fill in all fields';
  457. return;
  458. }
  459. try {
  460. const payload = {
  461. agent_id: agentId,
  462. message: message,
  463. role: 'user'
  464. };
  465. if (type === 'onetime') {
  466. const executeAt = document.getElementById('execute-at').value;
  467. const timezone = document.getElementById('timezone').value;
  468. if (!executeAt) {
  469. errorDiv.textContent = 'Please specify execution time';
  470. return;
  471. }
  472. // Convert datetime-local to ISO 8601 with timezone handling
  473. let executeDate;
  474. if (timezone === 'local') {
  475. // Use local browser timezone
  476. executeDate = new Date(executeAt);
  477. } else if (timezone === 'UTC') {
  478. // Treat input as UTC
  479. executeDate = new Date(executeAt + 'Z');
  480. } else {
  481. // For named timezones, we assume the datetime-local is in that timezone
  482. // Convert to UTC by parsing as local and adjusting
  483. executeDate = new Date(executeAt);
  484. // Note: This is a simplification. For accurate timezone conversion,
  485. // we'd need a library, but for now we assume UTC or local
  486. }
  487. payload.execute_at = executeDate.toISOString();
  488. } else {
  489. const cron = document.getElementById('cron').value.trim();
  490. if (!cron) {
  491. errorDiv.textContent = 'Please specify cron expression';
  492. return;
  493. }
  494. payload.cron = cron;
  495. }
  496. const endpoint = type === 'onetime' ? '/schedules/one-time' : '/schedules/recurring';
  497. const response = await fetch(`${API_BASE}${endpoint}`, {
  498. method: 'POST',
  499. headers: {
  500. 'Authorization': `Bearer ${API_KEY}`,
  501. 'Content-Type': 'application/json'
  502. },
  503. body: JSON.stringify(payload)
  504. });
  505. if (!response.ok) {
  506. const error = await response.json();
  507. throw new Error(error.detail || 'Failed to create schedule');
  508. }
  509. alert('SCHEDULE CREATED SUCCESSFULLY');
  510. document.getElementById('agent-id').value = '';
  511. document.getElementById('message').value = '';
  512. document.getElementById('execute-at').value = '';
  513. document.getElementById('cron').value = '';
  514. showTab('schedules');
  515. loadSchedules();
  516. } catch (error) {
  517. errorDiv.textContent = 'Error: ' + error.message;
  518. }
  519. }
  520. async function deleteSchedule(type, id) {
  521. if (!confirm('CONFIRM: Delete this schedule?')) return;
  522. try {
  523. const response = await fetch(`${API_BASE}/schedules/${type}/${id}`, {
  524. method: 'DELETE',
  525. headers: { 'Authorization': `Bearer ${API_KEY}` }
  526. });
  527. if (!response.ok) throw new Error('Failed to delete');
  528. alert('SCHEDULE DELETED');
  529. loadSchedules();
  530. } catch (error) {
  531. alert('ERROR DELETING SCHEDULE: ' + error.message);
  532. }
  533. }
  534. function truncate(str, len) {
  535. return str.length > len ? str.substring(0, len) + '...' : str;
  536. }
  537. </script>
  538. </body>
  539. </html>