41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package callflow
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"git.ipao.vip/rogee/go-sip/internal/ai"
|
|
)
|
|
|
|
// ApprovedPipeline is one call's immutable Agent execution. It shares the
|
|
// media sequencing with other modes without importing legacy AI snapshots.
|
|
type ApprovedPipeline interface {
|
|
Open(context.Context) ([]byte, error)
|
|
RunTurn(context.Context, []byte) (ai.TurnResult, error)
|
|
}
|
|
|
|
func ExecuteApproved(ctx context.Context, session MediaSession, mode ai.Mode, pipeline ApprovedPipeline, capture CaptureConfig) (Result, error) {
|
|
if pipeline == nil {
|
|
return Result{}, errors.New("approved AI pipeline is required")
|
|
}
|
|
if capture.CallDuration > 0 {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, capture.CallDuration)
|
|
defer cancel()
|
|
}
|
|
return executeFlow(ctx, session, mode, pipeline.Open, pipeline.RunTurn, capture)
|
|
}
|
|
|
|
// ApprovedCapture hands explicit task conversation limits to the shared media
|
|
// controller. A zero field denotes an absent optional business value.
|
|
func ApprovedCapture(bound ai.CurrentBound) CaptureConfig {
|
|
return CaptureConfig{
|
|
FirstSpeechTimeout: bound.Conversation.SilenceTimeout,
|
|
CallDuration: bound.Conversation.MaxDuration,
|
|
EndSilence: bound.Conversation.SilenceTimeout,
|
|
VoiceThreshold: 1,
|
|
MaxTurns: bound.Conversation.MaxTurns,
|
|
MaxPendingAudioChunks: bound.Conversation.MaxPendingAudioChunks,
|
|
}
|
|
}
|