on main help sign in
fix(sessions): tag removal, handle multibyte
commitc49b4fe243ffd6b9ded5afdc53c9e85e0dff404c authorChristian Rocha <christian@rocha.is> dateSun 28 Dec 2025, 07:04 (1 year ago) parentd2735fd
1 file changed+5−3
internal/agent/agent.go+5−3
internal/agent/agent.go+5−3
@@ -16,6 +16,7 @@ import (
1616 "fmt"
1717 "log/slog"
1818 "os"
19+ "regexp"
1920 "strconv"
2021 "strings"
2122 "sync"
@@ -45,6 +46,9 @@ var titlePrompt []byte
4546//go:embed templates/summary.md
4647var summaryPrompt []byte
4748
49+// Used to remove <think> tags from generated titles.
50+var thinkTagRegex = regexp.MustCompile(`<think>.*?</think>`)
51+
4852type SessionAgentCall struct {
4953 SessionID string
5054 Prompt string
@@ -760,9 +764,7 @@ func (a *sessionAgent) generateTitle(ctx context.Context, sessionID string, prom
760764 title = strings.ReplaceAll(title, "\n", " ")
761765
762766 // Remove thinking tags if present.
763− if idx := strings.Index(title, "</think>"); idx > 0 {
764− title = title[idx+len("</think>"):]
765− }
767+ title = thinkTagRegex.ReplaceAllString(title, "")
766768
767769 title = strings.TrimSpace(title)
768770 if title == "" {