@sleep2agi/commhub-server 0.4.2 → 0.4.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +14 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "CommHub MCP Server — AI Agent communication hub with SSE push, MCP protocol, and REST API",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -49,7 +49,10 @@ const CORS_ORIGINS = process.env.COMMHUB_CORS_ORIGINS
49
49
 
50
50
  function corsHeaders(req: Request): Record<string, string> {
51
51
  const origin = req.headers.get("Origin") || "";
52
- const allowed = CORS_ORIGINS.includes(origin) ? origin : "";
52
+ const allowed = CORS_ORIGINS.includes(origin)
53
+ || origin === "https://agent-network.vansin.me"
54
+ || origin === "https://agent-network-dashboard.vercel.app"
55
+ ? origin : "";
53
56
  return {
54
57
  "Access-Control-Allow-Origin": allowed,
55
58
  "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
@@ -249,6 +252,16 @@ Bun.serve({
249
252
  }
250
253
  }
251
254
 
255
+ // ── REST: recent messages (for Dashboard communication graph) ──
256
+ if (url.pathname === "/api/messages") {
257
+ const limit = Number(url.searchParams.get("limit")) || 100;
258
+ const since = url.searchParams.get("since") ?? new Date(Date.now() - 3600000).toISOString().replace("T", " ").slice(0, 19);
259
+ const rows = db.query(
260
+ "SELECT id, session_name as to_alias, from_session as from_alias, type, priority, content, created_at FROM inbox WHERE created_at >= ?1 ORDER BY created_at DESC LIMIT ?2"
261
+ ).all(since, limit);
262
+ return withCors(req, Response.json({ ok: true, messages: rows }));
263
+ }
264
+
252
265
  // ── REST: recent completions ──
253
266
  if (url.pathname === "/api/completions") {
254
267
  const since = url.searchParams.get("since") ?? new Date(Date.now() - 86400000).toISOString();