Skip to content

Commit ecb63d9

Browse files
committed
Add keepalive
1 parent 0713f48 commit ecb63d9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

apps/sim/app/api/copilot/chat/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export async function POST(req: NextRequest) {
335335
goRoute: '/api/copilot',
336336
autoExecuteTools: true,
337337
interactive: true,
338-
promptForToolApproval: true,
338+
promptForToolApproval: false,
339339
onComplete: async (result: OrchestratorResult) => {
340340
if (!actualChatId) return
341341

@@ -415,7 +415,7 @@ export async function POST(req: NextRequest) {
415415
goRoute: '/api/copilot',
416416
autoExecuteTools: true,
417417
interactive: true,
418-
promptForToolApproval: true,
418+
promptForToolApproval: false,
419419
})
420420

421421
const responseData = {

apps/sim/lib/copilot/chat-streaming.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
218218
})
219219
}
220220

221+
const keepaliveInterval = setInterval(() => {
222+
if (clientDisconnected) return
223+
try {
224+
controller.enqueue(encoder.encode(': keepalive\n\n'))
225+
} catch {
226+
clientDisconnected = true
227+
}
228+
}, 15_000)
229+
221230
try {
222231
await orchestrateCopilotStream(requestPayload, {
223232
...orchestrateOptions,
@@ -256,6 +265,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
256265
},
257266
})
258267
} finally {
268+
clearInterval(keepaliveInterval)
259269
activeStreams.delete(streamId)
260270
if (chatId) {
261271
resolvePendingChatStream(chatId, streamId)

0 commit comments

Comments
 (0)