Fix stream compatibility and vision model exposure

This commit is contained in:
MiY
2026-04-29 20:23:13 +08:00
parent d7e071b24a
commit 241334c658
42 changed files with 603 additions and 157 deletions

View File

@@ -15,6 +15,7 @@ import (
"ds2api/internal/devcapture"
adminshared "ds2api/internal/httpapi/admin/shared"
"ds2api/internal/rawsample"
"ds2api/internal/util"
)
type captureChain struct {
@@ -479,10 +480,13 @@ func previewCaptureChainResponse(chain captureChain) string {
func previewText(text string, limit int) string {
text = strings.TrimSpace(text)
if limit <= 0 || len(text) <= limit {
if limit <= 0 {
return text
}
return text[:limit] + "..."
if truncated, ok := util.TruncateRunes(text, limit); ok {
return truncated + "..."
}
return text
}
func captureChainHasTruncatedResponse(chain captureChain) bool {

View File

@@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"testing"
"unicode/utf8"
"ds2api/internal/devcapture"
)
@@ -231,6 +232,16 @@ func TestCombineCaptureBodiesPreservesOrderAndSeparators(t *testing.T) {
}
}
func TestPreviewTextPreservesUTF8MB4Characters(t *testing.T) {
preview := previewText(strings.Repeat("😀", 281), 280)
if !utf8.ValidString(preview) {
t.Fatalf("expected valid utf-8 preview, got %q", preview)
}
if preview != strings.Repeat("😀", 280)+"..." {
t.Fatalf("unexpected preview: %q", preview)
}
}
func TestQueryRawSampleCapturesGroupsBySessionAndMatchesQuestion(t *testing.T) {
devcapture.Global().Clear()
defer devcapture.Global().Clear()