Files
ds2api/internal/sse/line.go
CJACK b82bc1311a fix: use parent_message_id and fresh PoW headers for empty-output retry and continue
Previously retry/continue requests reused the initial PoW header and
lacked parent_message_id, causing them to land as disconnected root
messages in the DeepSeek session instead of proper follow-up turns.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-27 21:31:51 +08:00

67 lines
1.9 KiB
Go

package sse
import (
"fmt"
)
// LineResult is the normalized parse result for one DeepSeek SSE line.
type LineResult struct {
Parsed bool
Stop bool
ContentFilter bool
ErrorMessage string
Parts []ContentPart
ToolDetectionThinkingParts []ContentPart
NextType string
ResponseMessageID int
}
// ParseDeepSeekContentLine centralizes one-line DeepSeek SSE parsing for both
// streaming and non-streaming handlers.
func ParseDeepSeekContentLine(raw []byte, thinkingEnabled bool, currentType string) LineResult {
chunk, done, parsed := ParseDeepSeekSSELine(raw)
if !parsed {
return LineResult{NextType: currentType}
}
if done {
return LineResult{Parsed: true, Stop: true, NextType: currentType}
}
if errObj, hasErr := chunk["error"]; hasErr {
return LineResult{
Parsed: true,
Stop: true,
ErrorMessage: fmt.Sprintf("%v", errObj),
NextType: currentType,
}
}
if code, _ := chunk["code"].(string); code == "content_filter" {
return LineResult{
Parsed: true,
Stop: true,
ContentFilter: true,
NextType: currentType,
}
}
if hasContentFilterStatus(chunk) {
return LineResult{
Parsed: true,
Stop: true,
ContentFilter: true,
NextType: currentType,
}
}
parts, detectionThinkingParts, finished, nextType := ParseSSEChunkForContentDetailed(chunk, thinkingEnabled, currentType)
parts = filterLeakedContentFilterParts(parts)
detectionThinkingParts = filterLeakedContentFilterParts(detectionThinkingParts)
var respMsgID int
observeResponseMessageID(chunk, &respMsgID)
return LineResult{
Parsed: true,
Stop: finished,
Parts: parts,
ToolDetectionThinkingParts: detectionThinkingParts,
NextType: nextType,
ResponseMessageID: respMsgID,
}
}