diff --git a/chat.go b/chat.go index 5af7f11..42da363 100644 --- a/chat.go +++ b/chat.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "strings" + "time" "github.com/revrost/go-openrouter" ) @@ -329,6 +330,19 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { debug("handling request") + go func() { + ticker := time.NewTicker(10 * time.Second) + + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + response.WriteChunk(NewChunk(ChunkAlive, nil)) + } + } + }() + for iteration := range raw.Iterations { debug("iteration %d of %d", iteration+1, raw.Iterations) diff --git a/static/js/chat.js b/static/js/chat.js index 3fbfb08..e38dd58 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -8,6 +8,7 @@ 5: "tool", 6: "error", 7: "end", + 8: "alive", }; const $version = document.getElementById("version"), @@ -1094,6 +1095,10 @@ buffer = buffer.slice(5 + length); + if (type === "alive") { + continue; // we are still alive + } + callback({ type: type, data: data, diff --git a/stream.go b/stream.go index 783ed82..674f32d 100644 --- a/stream.go +++ b/stream.go @@ -21,6 +21,7 @@ const ( ChunkTool ChunkType = 5 ChunkError ChunkType = 6 ChunkEnd ChunkType = 7 + ChunkAlive ChunkType = 8 ) type ChunkType uint8