feat: increase SSE scanner buffer to 4MB for Anthropic tool calls, add stream error handling, prune unused Go dependencies, and add setup instructions.

This commit is contained in:
2026-05-13 15:09:27 +03:00
parent 7447cb3a56
commit 28eb7e849b
9 changed files with 114 additions and 175 deletions
+17 -2
View File
@@ -306,6 +306,11 @@ func handleStreaming(
c.Response().SetBodyStreamWriter(func(w *bufio.Writer) {
scanner := bufio.NewScanner(resp.Body)
const maxScanTokenSize = 4 * 1024 * 1024 // 4 MB — Claude Code tool calls produce large chunks
buf := make([]byte, maxScanTokenSize)
scanner.Buffer(buf, maxScanTokenSize)
for scanner.Scan() {
line := scanner.Text()
if !strings.HasPrefix(line, "data: ") {
@@ -314,10 +319,20 @@ func handleStreaming(
chunk := []byte(strings.TrimPrefix(line, "data: "))
event := transformer.TransformChunk(chunk)
if event != "" {
w.WriteString(event)
w.Flush()
if _, err := w.WriteString(event); err != nil {
logger.Warn("[ANTHROPIC] Stream write error [IP: %s]: %v", c.IP(), err)
return
}
if err := w.Flush(); err != nil {
logger.Warn("[ANTHROPIC] Stream flush error [IP: %s]: %v", c.IP(), err)
return
}
}
}
if err := scanner.Err(); err != nil {
logger.Warn("[ANTHROPIC] Stream scan error [IP: %s]: %v", c.IP(), err)
return
}
// Ensure final events are sent
final := transformer.TransformChunk([]byte("[DONE]"))
if final != "" {