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

34 lines
1.6 KiB
Go

package rpc
import (
"errors"
"strings"
)
var ErrApprovedWorkerRequired = errors.New("approved call worker is required")
// NewApprovedAgentServer binds the control RPC and one-shot originate callback
// to the same task-call registry. The separate legacy hooks are not accepted
// on this current Mock-only entry: otherwise a control could confirm while a
// call started by a different adapter remains active.
func NewApprovedAgentServer(options ServerOptions, worker *ApprovedCallWorker) (*Server, error) {
if worker == nil {
return nil, ErrApprovedWorkerRequired
}
if options.Mode != "mock" || options.StatePath == "" || options.Status == nil || options.Status.AgentId == "" || options.Status.CellId == "" || options.Status.BootId == "" || strings.TrimSpace(options.ApprovedDispatcherID) == "" || options.LoadedSIP == nil {
return nil, errors.New("approved Agent requires explicit Mock mode, durable state, Agent and Dispatcher identity, and observed SIP")
}
if worker.Lifecycle == nil || worker.Calls == nil || worker.Prepare == nil || worker.OnFailure == nil {
return nil, errors.New("approved Agent requires a process lifecycle, task calls, runner and failure reporting")
}
if options.MockApprovedOriginate != nil || options.ApprovedTaskCalls != nil {
return nil, errors.New("approved Agent cannot use competing call or control adapters")
}
// Copy the configuration so later mutation of worker fields cannot cause
// ExecuteApproved and task controls to observe different registries.
frozen := *worker
options.MockApprovedOriginate = frozen.Originate
options.ApprovedTaskCalls = frozen.Calls
return NewServer(options), nil
}