refactor: improve code readability and consistency across multiple files

This commit is contained in:
Administrator committed 2026-03-21 17:12:45 +08:00
1 parent 4f646ef2b8
commit 087e8519c5
9 files changed
+133 -74

No files matched your search

+2 -2
View File
@@ -65,7 +65,7 @@ func MeasureContextRunes(messages []providers.Message) int {
totalRunes += utf8.RuneCountInString(tc.Name)
// Arguments: serialize and count
if argsJSON, err := json.Marshal(tc.Arguments); err == nil {
totalRunes += utf8.RuneCountInString(string(argsJSON))
totalRunes += utf8.RuneCount(argsJSON)
} else {
// Fallback estimate if serialization fails
totalRunes += 100
@@ -136,7 +136,7 @@ func TruncateContextSmart(messages []providers.Message, maxRunes int) []provider
for _, tc := range msg.ToolCalls {
msgRunes += utf8.RuneCountInString(tc.Name)
if argsJSON, err := json.Marshal(tc.Arguments); err == nil {
msgRunes += utf8.RuneCountInString(string(argsJSON))
msgRunes += utf8.RuneCount(argsJSON)
} else {
msgRunes += 100
}
+1 -1
View File
@@ -156,7 +156,7 @@ func TestMeasureContextRunes(t *testing.T) {
{
name: "unicode characters",
messages: []providers.Message{
{Role: "user", Content: "你好世界"}, // 4 Chinese characters
{Role: "user", Content: "\u4f60\u597d\u4e16\u754c"}, // 4 Chinese characters
},
want: 4,
},