Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/sse-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SSE Gateway (functional stream)

## Run

```bash
npm i express
node apps/sse-gateway/server.mjs
Comment on lines +6 to +7

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The run instructions suggest npm i express and running the server directly, but the PR also adds express to the root package.json and an npm run sse:gateway script. To avoid mismatched dependency state and to match the documented workflow, update this README to use npm install (root) and npm run sse:gateway (optionally mentioning PORT=...).

Suggested change
npm i express
node apps/sse-gateway/server.mjs
npm install
npm run sse:gateway
# optional: PORT=5000 npm run sse:gateway

Copilot uses AI. Check for mistakes.
```

## Test

```bash
curl -N "http://localhost:5000/sse?q=email"
```

You should receive:
- `status` event
- `result` event
- periodic keep-alive comments (`: keep-alive`)
62 changes: 62 additions & 0 deletions apps/sse-gateway/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import express from "express";

const app = express();
const PORT = Number(process.env.PORT) || 5000;

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const PORT = Number(process.env.PORT) || 5000; treats PORT=0 as falsy and will incorrectly fall back to 5000. Prefer checking for undefined/empty instead of using ||, so an explicit 0 (or other valid numeric values) is honored.

Suggested change
const PORT = Number(process.env.PORT) || 5000;
const rawPort = process.env.PORT;
const PORT =
rawPort === undefined || rawPort === ""
? 5000
: Number.isNaN(Number(rawPort))
? 5000
: Number(rawPort);

Copilot uses AI. Check for mistakes.

app.get("/", (_req, res) => {
res.json({ ok: true, service: "sse-gateway" });
});

function detectIntent(q = "") {
const s = String(q).toLowerCase();

if (s.includes("email")) return ["email", ["Gmail"]];
if (s.includes("docs")) return ["docs", ["Google Docs"]];
if (s.includes("storage")) return ["storage", ["Google Drive"]];
if (s.includes("dev")) return ["dev", ["Replit", "Vercel"]];
if (s.includes("payment")) return ["payment", ["PayPal"]];
if (s.includes("ai")) return ["ai", ["Hugging Face"]];

return ["general", ["General"]];
}

app.get("/sse", (req, res) => {
const q = String(req.query.q || "");
const [intent, tools] = detectIntent(q);

res.setHeader("Content-Type", "text/event-stream; charset=utf-8");
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Connection", "keep-alive");

if (typeof res.flushHeaders === "function") {
res.flushHeaders();
}

res.write("event: status\n");
res.write(`data: ${JSON.stringify({ status: "processing" })}\n\n`);

const resultTimer = setTimeout(() => {
res.write("event: result\n");
res.write(
`data: ${JSON.stringify({
query: q,
intent,
tools,
})}\n\n`,
);
}, 300);

const heartbeat = setInterval(() => {
res.write(": keep-alive\n\n");
}, 15000);

req.on("close", () => {
clearTimeout(resultTimer);
clearInterval(heartbeat);
res.end();
});
});

app.listen(PORT, "0.0.0.0", () => {
console.log(`SSE server running on ${PORT}`);
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"sse:gateway": "node apps/sse-gateway/server.mjs"
},
"repository": {
"type": "git",
Expand All @@ -22,6 +23,7 @@
},
"homepage": "https://github.com/NguyenCuong1989/DAIOF-Framework#readme",
"dependencies": {
"@playwright/test": "^1.56.1"
"@playwright/test": "^1.56.1",
"express": "^4.21.2"
Comment on lines +26 to +27

Copilot AI Apr 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

express was added to dependencies, but package-lock.json was not updated accordingly. This will leave installs non-reproducible and can cause CI failures due to lockfile drift; please regenerate/commit an updated lockfile that includes express (or remove the lockfile change requirement if the repo intentionally doesn't track it).

Suggested change
"@playwright/test": "^1.56.1",
"express": "^4.21.2"
"@playwright/test": "^1.56.1"

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Lockfile out of sync 🐞 Bug ☼ Reliability

express was added to package.json but package-lock.json was not updated, so lockfile-based
installs can fail or omit express, causing apps/sse-gateway/server.mjs to crash at startup with
a missing module error.
Agent Prompt
## Issue description
`package.json` declares `express`, but `package-lock.json` is not updated accordingly. This makes installs non-reproducible and can break lockfile-based installs, and can lead to runtime failure when starting the SSE gateway.

## Issue Context
The new SSE server imports `express`. The repo has an existing `package-lock.json` whose root dependency list does not include `express`.

## Fix Focus Areas
- package-lock.json[1-75]
- package.json[25-28]

## Suggested fix
1. Run `npm install` (or `npm install --package-lock-only`) at the repo root so the lockfile includes `express`.
2. Commit the updated `package-lock.json` (and ensure it adds the `express` package entries).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

}
}
Loading