Files
go-sip/internal/rpc/approved_runner.go
T

29 lines
1.2 KiB
Go

package rpc
import (
"context"
"errors"
"git.ipao.vip/rogee/go-sip/internal/ai"
"git.ipao.vip/rogee/go-sip/internal/callflow"
)
// RunApprovedCall is the isolated Agent media entry point. Both the
// Dispatcher-signed call limit and the immutable AI conversation limit apply;
// neither missing media nor a missing hangup adapter can silently proceed.
func RunApprovedCall(ctx context.Context, approved ApprovedExecution, session callflow.MediaSession, hangup func(context.Context) error) (callflow.Result, error) {
if session == nil || hangup == nil || approved.MaxCallDuration <= 0 {
return callflow.Result{}, errors.New("approved Agent media, hangup and signed call duration are required")
}
if approved.AI.Mode != string(ai.ModeFullAI) && approved.AI.Mode != string(ai.ModeASROnly) {
return callflow.Result{}, errors.New("approved AI mode is unsupported")
}
call, err := ai.NewCurrentCall(approved.AI, hangup)
if err != nil {
return callflow.Result{}, err
}
ctx, cancel := context.WithTimeout(ctx, approved.MaxCallDuration)
defer cancel()
return callflow.ExecuteApproved(ctx, session, ai.Mode(approved.AI.Mode), call, callflow.ApprovedCapture(approved.AI))
}