heyio 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/server.js
CHANGED
|
@@ -11,6 +11,10 @@ import { abortOrchestrator } from "../copilot/orchestrator.js";
|
|
|
11
11
|
import { getActiveTasks, getTask, listRecentTasks } from "../store/tasks.js";
|
|
12
12
|
import { IO_VERSION } from "../paths.js";
|
|
13
13
|
import { requireAuth } from "./auth.js";
|
|
14
|
+
import { listSchedules, getSchedule, deleteSchedule, setScheduleEnabled } from "../store/schedules.js";
|
|
15
|
+
import { listIoSchedules, getIoSchedule, deleteIoSchedule, setIoScheduleEnabled } from "../store/io-schedules.js";
|
|
16
|
+
import { runScheduleNow } from "../copilot/scheduler.js";
|
|
17
|
+
import { runIoScheduleNow } from "../copilot/io-scheduler.js";
|
|
14
18
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
19
|
const WEB_DIST = path.resolve(__dirname, "../../web-dist");
|
|
16
20
|
let messageHandler;
|
|
@@ -29,7 +33,7 @@ export async function startApiServer() {
|
|
|
29
33
|
app.use(express.json());
|
|
30
34
|
app.use((_req, res, next) => {
|
|
31
35
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
32
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
36
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
33
37
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
34
38
|
next();
|
|
35
39
|
});
|
|
@@ -226,6 +230,172 @@ export async function startApiServer() {
|
|
|
226
230
|
res.status(500).json({ error: "Failed to cancel task" });
|
|
227
231
|
}
|
|
228
232
|
});
|
|
233
|
+
// Schedules endpoints
|
|
234
|
+
api.get("/schedules", (_req, res) => {
|
|
235
|
+
try {
|
|
236
|
+
const io = listIoSchedules();
|
|
237
|
+
const squads = listSchedules();
|
|
238
|
+
res.json({ io, squads });
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
console.error("Error listing schedules:", e);
|
|
242
|
+
res.status(500).json({ error: "Failed to list schedules" });
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
// Squad schedule lifecycle
|
|
246
|
+
api.post("/schedules/squads/:id/pause", (req, res) => {
|
|
247
|
+
const id = Number(req.params.id);
|
|
248
|
+
if (Number.isNaN(id)) {
|
|
249
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
const ok = setScheduleEnabled(id, false);
|
|
254
|
+
if (!ok) {
|
|
255
|
+
res.status(404).json({ error: "Squad schedule not found" });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
res.json({ ok: true, schedule: getSchedule(id) });
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
console.error("Error pausing squad schedule:", e);
|
|
262
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
api.post("/schedules/squads/:id/resume", (req, res) => {
|
|
266
|
+
const id = Number(req.params.id);
|
|
267
|
+
if (Number.isNaN(id)) {
|
|
268
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const ok = setScheduleEnabled(id, true);
|
|
273
|
+
if (!ok) {
|
|
274
|
+
res.status(404).json({ error: "Squad schedule not found" });
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
res.json({ ok: true, schedule: getSchedule(id) });
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
console.error("Error resuming squad schedule:", e);
|
|
281
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
api.post("/schedules/squads/:id/run-now", async (req, res) => {
|
|
285
|
+
const id = Number(req.params.id);
|
|
286
|
+
if (Number.isNaN(id)) {
|
|
287
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const result = await runScheduleNow(id);
|
|
292
|
+
if (!result.ok) {
|
|
293
|
+
res.status(404).json({ error: result.error ?? "Squad schedule not found" });
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
res.json({ ok: true });
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
console.error("Error running squad schedule now:", e);
|
|
300
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
api.delete("/schedules/squads/:id", (req, res) => {
|
|
304
|
+
const id = Number(req.params.id);
|
|
305
|
+
if (Number.isNaN(id)) {
|
|
306
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const ok = deleteSchedule(id);
|
|
311
|
+
if (!ok) {
|
|
312
|
+
res.status(404).json({ error: "Squad schedule not found" });
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
res.json({ ok: true });
|
|
316
|
+
}
|
|
317
|
+
catch (e) {
|
|
318
|
+
console.error("Error deleting squad schedule:", e);
|
|
319
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
// IO schedule lifecycle
|
|
323
|
+
api.post("/schedules/io/:id/pause", (req, res) => {
|
|
324
|
+
const id = Number(req.params.id);
|
|
325
|
+
if (Number.isNaN(id)) {
|
|
326
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
const ok = setIoScheduleEnabled(id, false);
|
|
331
|
+
if (!ok) {
|
|
332
|
+
res.status(404).json({ error: "IO schedule not found" });
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
res.json({ ok: true, schedule: getIoSchedule(id) });
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
console.error("Error pausing IO schedule:", e);
|
|
339
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
api.post("/schedules/io/:id/resume", (req, res) => {
|
|
343
|
+
const id = Number(req.params.id);
|
|
344
|
+
if (Number.isNaN(id)) {
|
|
345
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const ok = setIoScheduleEnabled(id, true);
|
|
350
|
+
if (!ok) {
|
|
351
|
+
res.status(404).json({ error: "IO schedule not found" });
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
res.json({ ok: true, schedule: getIoSchedule(id) });
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
console.error("Error resuming IO schedule:", e);
|
|
358
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
api.post("/schedules/io/:id/run-now", async (req, res) => {
|
|
362
|
+
const id = Number(req.params.id);
|
|
363
|
+
if (Number.isNaN(id)) {
|
|
364
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
const ok = await runIoScheduleNow(id);
|
|
369
|
+
if (!ok) {
|
|
370
|
+
res.status(404).json({ error: "IO schedule not found" });
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
res.json({ ok: true });
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
console.error("Error running IO schedule now:", e);
|
|
377
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
api.delete("/schedules/io/:id", (req, res) => {
|
|
381
|
+
const id = Number(req.params.id);
|
|
382
|
+
if (Number.isNaN(id)) {
|
|
383
|
+
res.status(400).json({ error: "Invalid schedule id" });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
const ok = deleteIoSchedule(id);
|
|
388
|
+
if (!ok) {
|
|
389
|
+
res.status(404).json({ error: "IO schedule not found" });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
res.json({ ok: true });
|
|
393
|
+
}
|
|
394
|
+
catch (e) {
|
|
395
|
+
console.error("Error deleting IO schedule:", e);
|
|
396
|
+
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
397
|
+
}
|
|
398
|
+
});
|
|
229
399
|
// Chat endpoints
|
|
230
400
|
api.post("/message", async (req, res) => {
|
|
231
401
|
const { text } = req.body;
|