mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 15:26:55 +08:00
Improve NOFXi agent product handling
This commit is contained in:
11
agent/web.go
11
agent/web.go
@@ -3,6 +3,7 @@ package agent
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
@@ -165,13 +166,23 @@ func (w *WebHandler) HandleChatStream(rw http.ResponseWriter, r *http.Request) {
|
||||
defer cancel()
|
||||
|
||||
resp, err := w.agent.HandleMessageStreamForStoreUser(ctx, storeUserIDFromContext(r.Context()), req.UserID, msg, func(event, data string) {
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
writeSSE(rw, flusher, event, data)
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || ctx.Err() != nil {
|
||||
w.logger.Info("agent stream cancelled", "user_id", req.UserID, "error", err)
|
||||
return
|
||||
}
|
||||
w.logger.Error("agent HandleMessageStream failed", "error", err, "user_id", req.UserID)
|
||||
writeSSE(rw, flusher, "error", "I ran into a problem while handling that message. Please try again.")
|
||||
return
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
// Send final done event with complete response
|
||||
writeSSE(rw, flusher, "done", resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user