fix: sync latest telesrv fixes

This commit is contained in:
A 2026-07-04 01:14:47 +08:00
parent b7269b135f
commit b1f74185f0
11 changed files with 203 additions and 72 deletions

View file

@ -2,16 +2,29 @@ package ai
import "telesrv/internal/domain"
const (
defaultToneEmojiFormal int64 = 4963195715414131468
defaultToneEmojiShort int64 = 5089558399201313570
defaultToneEmojiTribal int64 = 4906965037207257780
defaultToneEmojiCorp int64 = 5103015433682813448
defaultToneEmojiZen int64 = 5129871924314243582
defaultToneEmojiBiblical int64 = 5006296094481580688
defaultToneEmojiViking int64 = 5102866720440189629
)
func DefaultTones() []domain.AIComposeTone {
return []domain.AIComposeTone{
defaultTone("neutral", "Polish", "Make the draft clearer, smoother, and chat-ready while keeping the original intent. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("formal", "Formal", "Rewrite in a more professional, polished, and polite tone. Avoid casual wording and contractions. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("friendly", "Friendly", "Rewrite in a warmer, conversational tone with natural phrasing. Light contractions are acceptable. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("concise", "Concise", "Rewrite the draft to be shorter and easier to scan while keeping the key meaning. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("formal", "Formal", defaultToneEmojiFormal, "Rewrite in a more professional, polished, and polite tone. Avoid casual wording and contractions. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("short", "Short", defaultToneEmojiShort, "Rewrite the draft to be shorter and easier to scan while keeping the key meaning. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("tribal", "Tribal", defaultToneEmojiTribal, "Rewrite in a primal, chant-like style with short punchy phrasing and playful energy. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("corp", "Corp", defaultToneEmojiCorp, "Rewrite in a business-corporate style with clear, action-oriented wording. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("zen", "Zen", defaultToneEmojiZen, "Rewrite in a calm, mindful, minimal style with gentle phrasing. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("biblical", "Biblical", defaultToneEmojiBiblical, "Rewrite in a solemn, archaic, scripture-like style while preserving the original meaning. Avoid returning the exact original text when a safe wording improvement is possible."),
defaultTone("viking", "Viking", defaultToneEmojiViking, "Rewrite in a bold, saga-like style with confident phrasing. Avoid returning the exact original text when a safe wording improvement is possible."),
}
}
func defaultTone(slug, title, prompt string) domain.AIComposeTone {
func defaultTone(slug, title string, emojiID int64, prompt string) domain.AIComposeTone {
ex := domain.AIComposeToneExample{
From: domain.AIComposeText{Text: "Can you send me the file when you have time?"},
To: domain.AIComposeText{Text: "Could you send me the file when you have a moment?"},
@ -20,6 +33,7 @@ func defaultTone(slug, title, prompt string) domain.AIComposeTone {
Default: true,
Slug: slug,
Title: title,
EmojiID: emojiID,
Prompt: prompt,
ExampleEnglish: &ex,
}

View file

@ -33,7 +33,7 @@ func localTransform(text string, req domain.AIComposeRequest, tone domain.AIComp
return ensureSentencePunctuation(text)
case "friendly":
return ensureSentencePunctuation(text)
case "concise":
case "short", "concise":
return trimVerboseLead(text)
default:
return ensureSentencePunctuation(text)

View file

@ -91,6 +91,40 @@ func TestDefaultTonePromptsDiscourageEcho(t *testing.T) {
}
}
func TestDefaultTonesMatchOfficialDirectory(t *testing.T) {
want := []struct {
slug string
title string
emojiID int64
}{
{"formal", "Formal", defaultToneEmojiFormal},
{"short", "Short", defaultToneEmojiShort},
{"tribal", "Tribal", defaultToneEmojiTribal},
{"corp", "Corp", defaultToneEmojiCorp},
{"zen", "Zen", defaultToneEmojiZen},
{"biblical", "Biblical", defaultToneEmojiBiblical},
{"viking", "Viking", defaultToneEmojiViking},
}
got := DefaultTones()
if len(got) != len(want) {
t.Fatalf("DefaultTones len = %d, want %d", len(got), len(want))
}
for i, tone := range got {
if tone.Slug != want[i].slug || tone.Title != want[i].title {
t.Fatalf("DefaultTones[%d] = %s/%s, want %s/%s", i, tone.Slug, tone.Title, want[i].slug, want[i].title)
}
if !tone.Default {
t.Fatalf("DefaultTones[%d].Default = false, want true", i)
}
if tone.EmojiID != want[i].emojiID {
t.Fatalf("DefaultTones[%d].EmojiID = %d, want %d", i, tone.EmojiID, want[i].emojiID)
}
if tone.ExampleEnglish == nil {
t.Fatalf("DefaultTones[%d].ExampleEnglish = nil", i)
}
}
}
func TestComposeCallsProviderWithInstruction(t *testing.T) {
provider := &fakeProvider{text: "Please send the file when you have a moment."}
svc := NewService(memory.NewAIComposeStore(), WithProvider(provider))