dashboard.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Letta Scheduling 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: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  11. background: #f8f9fa;
  12. color: #1a1a1a;
  13. padding: 24px;
  14. line-height: 1.6;
  15. }
  16. .container { max-width: 1100px; margin: 0 auto; }
  17. /* Header */
  18. .header {
  19. display: flex;
  20. justify-content: space-between;
  21. align-items: center;
  22. margin-bottom: 24px;
  23. flex-wrap: wrap;
  24. gap: 16px;
  25. }
  26. .header h1 {
  27. font-size: 24px;
  28. font-weight: 600;
  29. }
  30. .header-links {
  31. display: flex;
  32. gap: 16px;
  33. }
  34. .header-links a {
  35. color: #666;
  36. text-decoration: none;
  37. font-size: 14px;
  38. }
  39. .header-links a:hover {
  40. color: #1a1a1a;
  41. }
  42. /* Migration Banner */
  43. .migration-banner {
  44. background: #fff3cd;
  45. border: 2px solid #ffc107;
  46. border-radius: 8px;
  47. padding: 16px;
  48. margin-bottom: 24px;
  49. }
  50. .migration-banner h3 {
  51. font-size: 16px;
  52. font-weight: 600;
  53. margin-bottom: 8px;
  54. color: #856404;
  55. }
  56. .migration-banner p {
  57. font-size: 14px;
  58. color: #856404;
  59. margin-bottom: 8px;
  60. }
  61. .migration-banner a {
  62. color: #856404;
  63. font-weight: 600;
  64. }
  65. h2 {
  66. font-size: 16px;
  67. font-weight: 600;
  68. margin: 24px 0 12px 0;
  69. color: #1a1a1a;
  70. }
  71. /* API Key Section */
  72. .card {
  73. background: white;
  74. border: 1px solid #e0e0e0;
  75. border-radius: 8px;
  76. padding: 20px;
  77. margin-bottom: 20px;
  78. }
  79. .card-title {
  80. font-size: 14px;
  81. font-weight: 600;
  82. margin-bottom: 12px;
  83. color: #666;
  84. }
  85. #api-key-section input {
  86. width: 100%;
  87. padding: 10px 12px;
  88. border: 1px solid #e0e0e0;
  89. border-radius: 6px;
  90. font-size: 14px;
  91. margin-bottom: 12px;
  92. }
  93. #api-key-section input:focus {
  94. outline: none;
  95. border-color: #1a1a1a;
  96. }
  97. .btn-group {
  98. display: flex;
  99. gap: 8px;
  100. }
  101. /* Buttons */
  102. button, .btn {
  103. background: #1a1a1a;
  104. color: white;
  105. border: none;
  106. padding: 8px 16px;
  107. border-radius: 6px;
  108. cursor: pointer;
  109. font-size: 14px;
  110. font-weight: 500;
  111. }
  112. button:hover { background: #333; }
  113. button.secondary {
  114. background: white;
  115. color: #1a1a1a;
  116. border: 1px solid #e0e0e0;
  117. }
  118. button.secondary:hover {
  119. background: #f5f5f5;
  120. }
  121. button.danger {
  122. background: white;
  123. color: #dc2626;
  124. border: 1px solid #fecaca;
  125. }
  126. button.danger:hover {
  127. background: #fef2f2;
  128. }
  129. button.sm {
  130. padding: 6px 12px;
  131. font-size: 13px;
  132. }
  133. /* Tabs */
  134. .tabs {
  135. display: flex;
  136. gap: 4px;
  137. border-bottom: 1px solid #e0e0e0;
  138. margin-bottom: 20px;
  139. }
  140. .tab {
  141. padding: 10px 20px;
  142. background: transparent;
  143. color: #666;
  144. border: none;
  145. border-bottom: 2px solid transparent;
  146. cursor: pointer;
  147. font-weight: 500;
  148. font-size: 14px;
  149. border-radius: 0;
  150. margin-bottom: -1px;
  151. }
  152. .tab:hover {
  153. color: #1a1a1a;
  154. background: transparent;
  155. }
  156. .tab.active {
  157. color: #1a1a1a;
  158. border-bottom-color: #1a1a1a;
  159. background: transparent;
  160. }
  161. /* Content */
  162. .content {
  163. display: none;
  164. }
  165. .content.active { display: block; }
  166. /* Tables */
  167. .table-container {
  168. background: white;
  169. border: 1px solid #e0e0e0;
  170. border-radius: 8px;
  171. overflow: hidden;
  172. margin-bottom: 16px;
  173. }
  174. table {
  175. width: 100%;
  176. border-collapse: collapse;
  177. }
  178. th, td {
  179. padding: 12px 16px;
  180. text-align: left;
  181. border-bottom: 1px solid #e0e0e0;
  182. }
  183. th {
  184. background: #f8f9fa;
  185. font-weight: 600;
  186. font-size: 13px;
  187. color: #666;
  188. }
  189. tr:last-child td { border-bottom: none; }
  190. tr:hover td { background: #fafafa; }
  191. td { font-size: 14px; }
  192. /* Forms */
  193. .form-group {
  194. margin-bottom: 16px;
  195. }
  196. label {
  197. display: block;
  198. margin-bottom: 6px;
  199. font-weight: 500;
  200. font-size: 14px;
  201. }
  202. input[type="text"], input[type="datetime-local"], textarea, select {
  203. width: 100%;
  204. padding: 10px 12px;
  205. border: 1px solid #e0e0e0;
  206. border-radius: 6px;
  207. font-size: 14px;
  208. font-family: inherit;
  209. }
  210. input:focus, textarea:focus, select:focus {
  211. outline: none;
  212. border-color: #1a1a1a;
  213. }
  214. textarea { min-height: 100px; resize: vertical; }
  215. .help-text { color: #666; font-size: 13px; margin-top: 4px; }
  216. /* Status badges */
  217. .badge {
  218. display: inline-flex;
  219. align-items: center;
  220. padding: 4px 10px;
  221. border-radius: 4px;
  222. font-size: 12px;
  223. font-weight: 500;
  224. }
  225. .badge.success {
  226. background: #dcfce7;
  227. color: #166534;
  228. }
  229. .badge.failed {
  230. background: #fef2f2;
  231. color: #dc2626;
  232. }
  233. .hidden { display: none; }
  234. .error { color: #dc2626; margin-top: 8px; font-size: 14px; }
  235. .empty {
  236. text-align: center;
  237. padding: 40px;
  238. color: #666;
  239. }
  240. /* Status indicator */
  241. .status-msg {
  242. display: flex;
  243. align-items: center;
  244. gap: 8px;
  245. padding: 8px 0;
  246. font-size: 14px;
  247. }
  248. .status-msg.success { color: #166534; }
  249. .status-msg.error { color: #dc2626; }
  250. /* Loading spinner */
  251. .loading {
  252. text-align: center;
  253. padding: 40px;
  254. color: #666;
  255. }
  256. .spinner {
  257. display: inline-block;
  258. width: 32px;
  259. height: 32px;
  260. border: 3px solid #e0e0e0;
  261. border-top-color: #1a1a1a;
  262. border-radius: 50%;
  263. animation: spin 0.8s linear infinite;
  264. margin-bottom: 8px;
  265. }
  266. @keyframes spin {
  267. to { transform: rotate(360deg); }
  268. }
  269. .mono {
  270. font-family: 'SF Mono', Consolas, monospace;
  271. font-size: 13px;
  272. }
  273. @media (max-width: 768px) {
  274. body { padding: 16px; }
  275. th, td { padding: 10px 12px; }
  276. .header { flex-direction: column; align-items: flex-start; }
  277. }
  278. </style>
  279. </head>
  280. <body>
  281. <div class="container">
  282. <div class="header">
  283. <h1>Letta Scheduling Dashboard</h1>
  284. <div class="header-links">
  285. <a href="/">Home</a>
  286. <a href="https://docs.letta.com/guides/agents/scheduling/" target="_blank">Letta Docs</a>
  287. <a href="https://github.com/cpfiffer/letta-switchboard">GitHub</a>
  288. </div>
  289. </div>
  290. <!-- Migration Notice -->
  291. <div class="migration-banner">
  292. <h3>✨ Now powered by Letta's native scheduling!</h3>
  293. <p>
  294. This dashboard now calls Letta's API directly. The old Switchboard backend has been deprecated.
  295. Read the <a href="https://docs.letta.com/guides/agents/scheduling/" target="_blank">full scheduling docs →</a>
  296. </p>
  297. </div>
  298. <!-- API Key Input -->
  299. <div id="api-key-section" class="card">
  300. <div class="card-title">Authentication</div>
  301. <input type="password" id="api-key-input" placeholder="Enter your Letta API key (sk-let-...)">
  302. <div class="btn-group">
  303. <button onclick="saveApiKey()">Connect</button>
  304. <button onclick="clearApiKey()" class="secondary">Disconnect</button>
  305. </div>
  306. <div id="api-key-status"></div>
  307. </div>
  308. <div id="main-content" class="hidden">
  309. <!-- Tabs -->
  310. <div class="tabs">
  311. <button class="tab active" onclick="showTab('schedules')">Schedules</button>
  312. <button class="tab" onclick="showTab('create')">Create New</button>
  313. <button class="tab" onclick="showTab('results')">Results</button>
  314. </div>
  315. <!-- Schedules Tab -->
  316. <div id="schedules-tab" class="content active">
  317. <h2>One-Time Schedules</h2>
  318. <div class="table-container">
  319. <table id="onetime-table">
  320. <thead>
  321. <tr>
  322. <th>ID</th>
  323. <th>Agent ID</th>
  324. <th>Execute At</th>
  325. <th>Message</th>
  326. <th></th>
  327. </tr>
  328. </thead>
  329. <tbody></tbody>
  330. </table>
  331. </div>
  332. <h2>Recurring Schedules</h2>
  333. <div class="table-container">
  334. <table id="recurring-table">
  335. <thead>
  336. <tr>
  337. <th>ID</th>
  338. <th>Agent ID</th>
  339. <th>Cron</th>
  340. <th>Timezone</th>
  341. <th>Message</th>
  342. <th>Last Run</th>
  343. <th></th>
  344. </tr>
  345. </thead>
  346. <tbody></tbody>
  347. </table>
  348. </div>
  349. <button onclick="loadSchedules()" class="secondary">Refresh</button>
  350. </div>
  351. <!-- Create Tab -->
  352. <div id="create-tab" class="content">
  353. <div class="card">
  354. <h2 style="margin-top: 0;">Create Schedule</h2>
  355. <div class="form-group">
  356. <label>Schedule Type</label>
  357. <select id="schedule-type" onchange="toggleScheduleType()">
  358. <option value="onetime">One-Time</option>
  359. <option value="recurring">Recurring</option>
  360. </select>
  361. </div>
  362. <div class="form-group">
  363. <label for="agent-id">Agent ID</label>
  364. <input type="text" id="agent-id" placeholder="agent-xxx">
  365. </div>
  366. <div class="form-group">
  367. <label for="message">Message</label>
  368. <textarea id="message" placeholder="Your message to the agent"></textarea>
  369. </div>
  370. <div id="onetime-fields">
  371. <div class="form-group">
  372. <label for="execute-at">Execute At</label>
  373. <input type="datetime-local" id="execute-at">
  374. </div>
  375. <div class="form-group">
  376. <label for="timezone">Timezone</label>
  377. <select id="timezone">
  378. <option value="local" selected>Local Browser Time</option>
  379. <option value="UTC">UTC</option>
  380. <option value="America/New_York">Eastern (US)</option>
  381. <option value="America/Chicago">Central (US)</option>
  382. <option value="America/Denver">Mountain (US)</option>
  383. <option value="America/Los_Angeles">Pacific (US)</option>
  384. <option value="Europe/London">London</option>
  385. <option value="Europe/Paris">Paris</option>
  386. <option value="Asia/Tokyo">Tokyo</option>
  387. </select>
  388. <div class="help-text">Time will be converted to UTC for storage</div>
  389. </div>
  390. </div>
  391. <div id="recurring-fields" class="hidden">
  392. <div class="form-group">
  393. <label for="cron">Cron Expression</label>
  394. <input type="text" id="cron" placeholder="0 9 * * 1-5">
  395. <div class="help-text">Examples: "0 9 * * *" (daily at 9am), "*/5 * * * *" (every 5 min)</div>
  396. </div>
  397. <div class="form-group">
  398. <label for="recurring-timezone">Timezone</label>
  399. <select id="recurring-timezone">
  400. <option value="UTC" selected>UTC</option>
  401. <option value="America/New_York">Eastern (US)</option>
  402. <option value="America/Chicago">Central (US)</option>
  403. <option value="America/Denver">Mountain (US)</option>
  404. <option value="America/Los_Angeles">Pacific (US)</option>
  405. <option value="Europe/London">London</option>
  406. <option value="Europe/Paris">Paris</option>
  407. <option value="Asia/Tokyo">Tokyo</option>
  408. </select>
  409. <div class="help-text">Cron expression will be evaluated in this timezone</div>
  410. </div>
  411. </div>
  412. <button onclick="createSchedule()">Create Schedule</button>
  413. <div id="create-error" class="error"></div>
  414. </div>
  415. </div>
  416. <!-- Results Tab -->
  417. <div id="results-tab" class="content">
  418. <h2>Execution Results</h2>
  419. <div class="table-container">
  420. <table id="results-table">
  421. <thead>
  422. <tr>
  423. <th>Schedule ID</th>
  424. <th>Type</th>
  425. <th>Status</th>
  426. <th>Agent ID</th>
  427. <th>Message</th>
  428. <th>Run ID / Error</th>
  429. <th>Executed At</th>
  430. </tr>
  431. </thead>
  432. <tbody></tbody>
  433. </table>
  434. </div>
  435. <button onclick="loadResults()" class="secondary">Refresh</button>
  436. </div>
  437. </div>
  438. </div>
  439. <script>
  440. const LETTA_API = 'https://api.letta.com/v1';
  441. let API_KEY = sessionStorage.getItem('letta_api_key') || '';
  442. let DEFAULT_AGENT_ID = sessionStorage.getItem('default_agent_id') || '';
  443. // Initialize
  444. if (API_KEY) {
  445. document.getElementById('api-key-input').value = API_KEY;
  446. document.getElementById('main-content').classList.remove('hidden');
  447. if (DEFAULT_AGENT_ID) {
  448. document.getElementById('agent-id').value = DEFAULT_AGENT_ID;
  449. loadSchedules();
  450. }
  451. }
  452. // Helper: Convert ISO timestamp to Unix milliseconds
  453. function toUnixMs(isoString) {
  454. return new Date(isoString).getTime();
  455. }
  456. // Helper: Convert Unix milliseconds to readable date
  457. function fromUnixMs(ms) {
  458. return new Date(ms).toLocaleString();
  459. }
  460. function saveApiKey() {
  461. API_KEY = document.getElementById('api-key-input').value.trim();
  462. if (!API_KEY) {
  463. showStatus('api-key-status', 'API key is required', 'error');
  464. return;
  465. }
  466. sessionStorage.setItem('letta_api_key', API_KEY);
  467. document.getElementById('main-content').classList.remove('hidden');
  468. showStatus('api-key-status', 'Connected successfully', 'success');
  469. // Only auto-load if we have a saved agent ID
  470. if (DEFAULT_AGENT_ID) {
  471. loadSchedules();
  472. }
  473. }
  474. function clearApiKey() {
  475. sessionStorage.removeItem('letta_api_key');
  476. API_KEY = '';
  477. document.getElementById('api-key-input').value = '';
  478. document.getElementById('main-content').classList.add('hidden');
  479. showStatus('api-key-status', 'Disconnected', 'error');
  480. }
  481. function showStatus(elementId, message, type) {
  482. const el = document.getElementById(elementId);
  483. el.innerHTML = `<div class="status-msg ${type}">${message}</div>`;
  484. }
  485. function showTab(tab) {
  486. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  487. document.querySelectorAll('.content').forEach(c => c.classList.remove('active'));
  488. event.target.classList.add('active');
  489. document.getElementById(`${tab}-tab`).classList.add('active');
  490. }
  491. function toggleScheduleType() {
  492. const type = document.getElementById('schedule-type').value;
  493. document.getElementById('onetime-fields').classList.toggle('hidden', type !== 'onetime');
  494. document.getElementById('recurring-fields').classList.toggle('hidden', type !== 'recurring');
  495. }
  496. async function loadSchedules() {
  497. const agentId = document.getElementById('agent-id').value.trim();
  498. if (!agentId) {
  499. const onetimeBody = document.querySelector('#onetime-table tbody');
  500. const recurringBody = document.querySelector('#recurring-table tbody');
  501. onetimeBody.innerHTML = '<tr><td colspan="5" class="empty">Enter an Agent ID and click Refresh to view schedules</td></tr>';
  502. recurringBody.innerHTML = '<tr><td colspan="7" class="empty">Enter an Agent ID and click Refresh to view schedules</td></tr>';
  503. return;
  504. }
  505. // Save for next time
  506. sessionStorage.setItem('default_agent_id', agentId);
  507. DEFAULT_AGENT_ID = agentId;
  508. const onetimeBody = document.querySelector('#onetime-table tbody');
  509. const recurringBody = document.querySelector('#recurring-table tbody');
  510. onetimeBody.innerHTML = '<tr><td colspan="5" class="loading"><div class="spinner"></div><p>Loading...</p></td></tr>';
  511. recurringBody.innerHTML = '<tr><td colspan="7" class="loading"><div class="spinner"></div><p>Loading...</p></td></tr>';
  512. try {
  513. // Letta API returns all schedules (one-time and recurring) in a single call
  514. const response = await fetch(`${LETTA_API}/agents/${agentId}/schedule`, {
  515. headers: { 'Authorization': `Bearer ${API_KEY}` }
  516. });
  517. if (!response.ok) {
  518. throw new Error(`Failed to load schedules: ${response.statusText}`);
  519. }
  520. const data = await response.json();
  521. const schedules = data.scheduled_messages || [];
  522. // Split into one-time and recurring
  523. const onetime = schedules.filter(s => s.schedule.type === 'one-time');
  524. const recurring = schedules.filter(s => s.schedule.type === 'recurring');
  525. onetimeBody.innerHTML = onetime.length ? onetime.map(s => `
  526. <tr>
  527. <td class="mono">${s.id.substring(0, 8)}...</td>
  528. <td class="mono">${s.agent_id}</td>
  529. <td>${fromUnixMs(s.next_scheduled_at)}</td>
  530. <td>${truncate(s.messages[0]?.content || '', 50)}</td>
  531. <td><button class="danger sm" onclick="deleteSchedule('${s.id}')">Delete</button></td>
  532. </tr>
  533. `).join('') : '<tr><td colspan="5" class="empty">No one-time schedules</td></tr>';
  534. recurringBody.innerHTML = recurring.length ? recurring.map(s => `
  535. <tr>
  536. <td class="mono">${s.id.substring(0, 8)}...</td>
  537. <td class="mono">${s.agent_id}</td>
  538. <td class="mono">${s.schedule.cron_expression}</td>
  539. <td>UTC</td>
  540. <td>${truncate(s.messages[0]?.content || '', 50)}</td>
  541. <td>${s.next_scheduled_at ? fromUnixMs(s.next_scheduled_at) : 'Never'}</td>
  542. <td><button class="danger sm" onclick="deleteSchedule('${s.id}')">Delete</button></td>
  543. </tr>
  544. `).join('') : '<tr><td colspan="7" class="empty">No recurring schedules</td></tr>';
  545. } catch (error) {
  546. onetimeBody.innerHTML = `<tr><td colspan="5" class="empty">Error: ${error.message}</td></tr>`;
  547. recurringBody.innerHTML = `<tr><td colspan="7" class="empty">Error: ${error.message}</td></tr>`;
  548. }
  549. }
  550. async function loadResults() {
  551. const resultsBody = document.querySelector('#results-table tbody');
  552. resultsBody.innerHTML = '<tr><td colspan="7" class="empty">Results tracking not available yet. Check Letta Cloud dashboard for execution history.</td></tr>';
  553. // NOTE: Letta's scheduling API doesn't expose execution history yet
  554. // Users should check the Letta Cloud dashboard or use the runs API
  555. }
  556. async function createSchedule() {
  557. const type = document.getElementById('schedule-type').value;
  558. const agentId = document.getElementById('agent-id').value.trim();
  559. const message = document.getElementById('message').value.trim();
  560. const errorDiv = document.getElementById('create-error');
  561. errorDiv.textContent = '';
  562. if (!agentId || !message) {
  563. errorDiv.textContent = 'Please fill in all required fields';
  564. return;
  565. }
  566. // Save agent ID for convenience
  567. sessionStorage.setItem('default_agent_id', agentId);
  568. DEFAULT_AGENT_ID = agentId;
  569. try {
  570. // Build Letta API format
  571. const payload = {
  572. messages: [{
  573. role: 'user',
  574. content: message
  575. }]
  576. };
  577. if (type === 'onetime') {
  578. const executeAt = document.getElementById('execute-at').value;
  579. const timezone = document.getElementById('timezone').value;
  580. if (!executeAt) {
  581. errorDiv.textContent = 'Please specify execution time';
  582. return;
  583. }
  584. let executeDate;
  585. if (timezone === 'local') {
  586. executeDate = new Date(executeAt);
  587. } else if (timezone === 'UTC') {
  588. executeDate = new Date(executeAt + 'Z');
  589. } else {
  590. executeDate = new Date(executeAt);
  591. }
  592. // Convert to Unix milliseconds for Letta API
  593. payload.schedule = {
  594. type: 'one-time',
  595. scheduled_at: executeDate.getTime()
  596. };
  597. } else {
  598. const cron = document.getElementById('cron').value.trim();
  599. if (!cron) {
  600. errorDiv.textContent = 'Please specify cron expression';
  601. return;
  602. }
  603. // Letta uses 5-field cron (no seconds)
  604. payload.schedule = {
  605. type: 'recurring',
  606. cron_expression: cron
  607. };
  608. }
  609. const response = await fetch(`${LETTA_API}/agents/${agentId}/schedule`, {
  610. method: 'POST',
  611. headers: {
  612. 'Authorization': `Bearer ${API_KEY}`,
  613. 'Content-Type': 'application/json'
  614. },
  615. body: JSON.stringify(payload)
  616. });
  617. if (!response.ok) {
  618. const error = await response.json();
  619. throw new Error(error.detail || error.message || 'Failed to create schedule');
  620. }
  621. // Clear form
  622. document.getElementById('message').value = '';
  623. document.getElementById('execute-at').value = '';
  624. document.getElementById('cron').value = '';
  625. document.getElementById('recurring-timezone').value = 'UTC';
  626. // Switch to schedules tab
  627. showTab('schedules');
  628. document.querySelector('.tab').click();
  629. loadSchedules();
  630. } catch (error) {
  631. errorDiv.textContent = error.message;
  632. }
  633. }
  634. async function deleteSchedule(id) {
  635. if (!confirm('Delete this schedule?')) return;
  636. const agentId = document.getElementById('agent-id').value.trim();
  637. if (!agentId) {
  638. alert('Agent ID is required');
  639. return;
  640. }
  641. try {
  642. const response = await fetch(`${LETTA_API}/agents/${agentId}/schedule/${id}`, {
  643. method: 'DELETE',
  644. headers: { 'Authorization': `Bearer ${API_KEY}` }
  645. });
  646. if (!response.ok) {
  647. const error = await response.json();
  648. throw new Error(error.detail || error.message || 'Failed to delete');
  649. }
  650. loadSchedules();
  651. } catch (error) {
  652. alert('Error: ' + error.message);
  653. }
  654. }
  655. function truncate(str, len) {
  656. return str.length > len ? str.substring(0, len) + '...' : str;
  657. }
  658. </script>
  659. </body>
  660. </html>