sync: migrate ai-operator to Gitea (2026-08-10)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package handoff
|
||||
|
||||
type PolicyContext struct {
|
||||
State string
|
||||
Route string
|
||||
HandoffEnabled bool
|
||||
HandoffMode HandoffMode
|
||||
AllowInTestRouteOnly bool
|
||||
HasTarget bool
|
||||
AlreadyRequested bool
|
||||
}
|
||||
|
||||
type PolicyDecision struct {
|
||||
Allowed bool
|
||||
StubOnly bool
|
||||
ReasonCode string
|
||||
MessageKey string
|
||||
}
|
||||
|
||||
func Authorize(ctx PolicyContext) PolicyDecision {
|
||||
if ctx.State == "ENDED" {
|
||||
return PolicyDecision{Allowed: false, ReasonCode: "call_ended", MessageKey: "handoff.denied"}
|
||||
}
|
||||
if ctx.AlreadyRequested || ctx.State == "HANDOFF" {
|
||||
return PolicyDecision{Allowed: true, StubOnly: true, ReasonCode: "already_requested", MessageKey: "handoff.already_requested"}
|
||||
}
|
||||
if ctx.AllowInTestRouteOnly && ctx.Route != "test" {
|
||||
return PolicyDecision{Allowed: true, StubOnly: true, ReasonCode: "test_route_only", MessageKey: "handoff.stub"}
|
||||
}
|
||||
if !ctx.HandoffEnabled {
|
||||
return PolicyDecision{Allowed: true, StubOnly: true, ReasonCode: "disabled", MessageKey: "handoff.stub"}
|
||||
}
|
||||
switch ctx.HandoffMode {
|
||||
case HandoffModeDisabledStub:
|
||||
return PolicyDecision{Allowed: true, StubOnly: true, ReasonCode: "disabled", MessageKey: "handoff.stub"}
|
||||
case HandoffModeHangupAfterMessage:
|
||||
return PolicyDecision{Allowed: true, ReasonCode: "ok", MessageKey: "handoff.stub"}
|
||||
case HandoffModeARIRedirect, HandoffModeDialplanContinue:
|
||||
if !ctx.HasTarget {
|
||||
return PolicyDecision{Allowed: true, StubOnly: true, ReasonCode: "not_configured", MessageKey: "handoff.not_configured"}
|
||||
}
|
||||
return PolicyDecision{Allowed: true, ReasonCode: "ok", MessageKey: "handoff.transfer_started"}
|
||||
default:
|
||||
return PolicyDecision{Allowed: false, ReasonCode: "unknown_mode", MessageKey: "handoff.denied"}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user