sync: migrate ai-operator to Gitea (2026-08-10)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package region
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"ai-operator/internal/dialogue/state"
|
||||
)
|
||||
|
||||
func ShouldApplyRegionResolution(ctx SelectionContext, result ResolutionResult) RegionDecision {
|
||||
d := RegionDecision{RegionCode: result.RegionCode, Candidates: result.Candidates, ReasonCode: result.ReasonCode}
|
||||
if ctx.CurrentState == state.StateEnded || ctx.CurrentState == state.StateClosing || ctx.CurrentState == state.StateHandoff {
|
||||
d.ReasonCode = "call_ended"
|
||||
d.MessageKey = "closing.started"
|
||||
return d
|
||||
}
|
||||
if result.Intent == IntentUnsupported || result.ReasonCode == "disabled_region" {
|
||||
d.ReasonCode = result.ReasonCode
|
||||
d.MessageKey = "region.unsupported"
|
||||
return d
|
||||
}
|
||||
if result.NeedsClarification || result.Intent == IntentAmbiguous {
|
||||
d.NeedsClarification = true
|
||||
d.MessageKey = nonEmpty(result.ClarificationMessageKey, "region.ask_clarify")
|
||||
return d
|
||||
}
|
||||
if result.RegionCode == "" || result.Region == nil {
|
||||
d.MessageKey = "region.not_understood"
|
||||
return d
|
||||
}
|
||||
switch ctx.CurrentState {
|
||||
case state.StateLanguageSelection:
|
||||
d.ReasonCode = "language_required"
|
||||
d.MessageKey = "language.ask"
|
||||
return d
|
||||
case state.StateRegionSelection:
|
||||
if result.Confidence >= MediumConfidence && result.Region.Enabled {
|
||||
d.Apply = true
|
||||
d.MessageKey = "region.selected"
|
||||
}
|
||||
return d
|
||||
case state.StateReadyToHelp, state.StateQuestionAnswering:
|
||||
if ctx.CurrentRegionCode == "" && result.Confidence >= MediumConfidence && result.Region.Enabled {
|
||||
d.Apply = true
|
||||
d.MessageKey = "region.selected"
|
||||
return d
|
||||
}
|
||||
if ctx.AllowChange && result.Intent == IntentRegionChange && result.Confidence >= HighConfidence && result.Region.Enabled {
|
||||
d.Apply = true
|
||||
d.MessageKey = "region.changed"
|
||||
return d
|
||||
}
|
||||
d.ReasonCode = "state_not_ready"
|
||||
d.MessageKey = "ready.to_help"
|
||||
return d
|
||||
default:
|
||||
d.ReasonCode = "state_not_ready"
|
||||
d.MessageKey = "region.ask"
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
func IsExplicitChangeRequest(input string) bool {
|
||||
n := Normalize(input)
|
||||
phrases := []string{
|
||||
"сменить регион", "поменять регион", "изменить регион", "другой регион", "я из другого региона", "мой регион", "регион ", "я в ", "я из ", "выберите регион", "укажите регион",
|
||||
"аймақты ауыстыру", "өңірді өзгерту", "басқа өңір", "менің өңірім", "өңірім", "аймағым", "мен астанадамын", "мен алматыдамын", "облысынанмын",
|
||||
"change region", "switch region", "my region is", "i am in", "i am from",
|
||||
}
|
||||
for _, p := range phrases {
|
||||
if strings.Contains(n, Normalize(p)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func nonEmpty(v, fallback string) string {
|
||||
if v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user