Skip to content

Commit 669b8cc

Browse files
foxy1402Copilot
andcommitted
Fix IDE tool compatibility: send initial SSE chunk immediately
- Send initial empty delta chunk right after SSE headers to establish stream - Prevents IDE tools (Continue, Zed, Cursor) from timing out waiting for first chunk - Applied to both /v1/chat/completions and /v1/completions endpoints - Add IDE user-agent logging for debugging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ca908bc commit 669b8cc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/routes/chat.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ router.get('/', (req, res) => {
3939
router.post('/', (req, res) => {
4040
const { messages, model: requestedModel, stream = false, temperature, max_tokens, tools, tool_choice } = req.body || {};
4141

42+
// Log IDE/client info for debugging
43+
const userAgent = req.headers['user-agent'] || 'unknown';
44+
if (userAgent.includes('Continue') || userAgent.includes('Zed') || userAgent.includes('Cursor')) {
45+
console.log('[IDE Request]', userAgent, 'stream:', stream, 'model:', requestedModel);
46+
}
47+
4248
// Validate messages
4349
if (!messages || !Array.isArray(messages) || messages.length === 0) {
4450
return res.status(400).json({
@@ -67,6 +73,21 @@ router.post('/', (req, res) => {
6773

6874
if (stream) {
6975
setSSEHeaders(res);
76+
77+
// Send initial empty delta immediately to establish SSE stream (required for IDE tools)
78+
const initialChunk = {
79+
id,
80+
object: 'chat.completion.chunk',
81+
created: Math.floor(Date.now() / 1000),
82+
model,
83+
choices: [{
84+
index: 0,
85+
delta: { role: 'assistant', content: '' },
86+
finish_reason: null
87+
}]
88+
};
89+
res.write(`data: ${JSON.stringify(initialChunk)}\n\n`);
90+
7091
let lastFinishReason = 'stop';
7192

7293
const child = runQoderRequest({

src/routes/completions.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ router.post('/', (req, res) => {
3636

3737
if (stream) {
3838
setSSEHeaders(res);
39+
40+
// Send initial empty chunk immediately (required for IDE tools)
41+
const initialChunk = {
42+
id,
43+
object: 'text_completion',
44+
created: Math.floor(Date.now() / 1000),
45+
model,
46+
choices: [{
47+
text: '',
48+
index: 0,
49+
logprobs: null,
50+
finish_reason: null
51+
}]
52+
};
53+
res.write(`data: ${JSON.stringify(initialChunk)}\n\n`);
3954

4055
const child = runQoderRequest({
4156
prompt,

0 commit comments

Comments
 (0)