package rpc import ( "context" "errors" "reflect" "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 missingApprovedAdapter(value any) bool { if value == nil { return true } v := reflect.ValueOf(value) return v.Kind() == reflect.Pointer && v.IsNil() } func RunApprovedCall(ctx context.Context, approved ApprovedExecution, session callflow.MediaSession, hangup func(context.Context) error, pipeline callflow.ApprovedPipeline) (callflow.Result, error) { if missingApprovedAdapter(session) || hangup == nil || missingApprovedAdapter(pipeline) || approved.MaxCallDuration <= 0 { return callflow.Result{}, errors.New("approved Agent media, hangup, pipeline 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") } ctx, cancel := context.WithTimeout(ctx, approved.MaxCallDuration) defer cancel() return callflow.ExecuteApproved(ctx, session, ai.Mode(approved.AI.Mode), pipeline, callflow.ApprovedCapture(approved.AI)) }