feat(dingtalk): add reasoning mode and support evidence
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
type memoryRepo struct {
|
||||
admins map[string]bool
|
||||
prefs map[string]string
|
||||
rounds map[string]int
|
||||
hints map[string]bool
|
||||
bindings map[string]ResourceBinding
|
||||
candidate BootstrapCandidate
|
||||
sessions map[string]SettingSession
|
||||
@@ -18,7 +20,7 @@ type memoryRepo struct {
|
||||
}
|
||||
|
||||
func newMemoryRepo() *memoryRepo {
|
||||
return &memoryRepo{admins: map[string]bool{}, prefs: map[string]string{}, bindings: map[string]ResourceBinding{}, sessions: map[string]SettingSession{}}
|
||||
return &memoryRepo{admins: map[string]bool{}, prefs: map[string]string{}, rounds: map[string]int{}, hints: map[string]bool{}, bindings: map[string]ResourceBinding{}, sessions: map[string]SettingSession{}}
|
||||
}
|
||||
func (r *memoryRepo) IsAdministrator(_ context.Context, tenant, staff string) (bool, error) {
|
||||
return r.admins[tenant+"/"+staff], nil
|
||||
@@ -27,6 +29,14 @@ func (r *memoryRepo) SetPreference(_ context.Context, tenant, channel, staff, lo
|
||||
r.prefs[tenant+"/"+staff] = locale
|
||||
return nil
|
||||
}
|
||||
func (r *memoryRepo) SetReasoningMaxRounds(_ context.Context, tenant, channel, staff string, rounds int, _ time.Time) error {
|
||||
r.rounds[tenant+"/"+channel+"/"+staff] = rounds
|
||||
return nil
|
||||
}
|
||||
func (r *memoryRepo) SetReasoningHintEnabled(_ context.Context, tenant, channel, staff string, enabled bool, _ time.Time) error {
|
||||
r.hints[tenant+"/"+channel+"/"+staff] = enabled
|
||||
return nil
|
||||
}
|
||||
func (r *memoryRepo) SaveBinding(_ context.Context, b ResourceBinding) error {
|
||||
if r.saveErr != nil {
|
||||
return r.saveErr
|
||||
@@ -69,6 +79,43 @@ func TestControllerLanguageForOrdinaryUser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerReasoningRoundsForOrdinaryUser(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "u", Text: "/setting rounds 15", ConversationType: "direct"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.rounds["t/dingtalk/u"] != 15 || !strings.Contains(out, "15轮") {
|
||||
t.Fatalf("rounds=%v out=%q", r.rounds, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerRejectsOutOfRangeReasoningRounds(t *testing.T) {
|
||||
for _, value := range []string{"0", "51", "abc"} {
|
||||
r := newMemoryRepo()
|
||||
out, err := NewController(r).Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "u", Text: "/setting rounds " + value, ConversationType: "direct"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(r.rounds) != 0 || !strings.Contains(out, "1-50") {
|
||||
t.Fatalf("value=%q rounds=%v out=%q", value, r.rounds, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerReasoningHintForOrdinaryUser(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "u", Text: "/setting hint off", ConversationType: "direct"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.hints["t/dingtalk/u"] || !strings.Contains(out, "已关闭") {
|
||||
t.Fatalf("hints=%v out=%q", r.hints, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerSettingMenuExplainsLanguageWithoutAdminActionsToOrdinaryUser(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
|
||||
Reference in New Issue
Block a user