@@ -15,22 +15,41 @@ import (
1515type AgentClient struct {
1616 agentClient livekit.CloudAgent
1717 authBase
18+ httpClient * http.Client
19+ twirpOpts []twirp.ClientOption
1820}
1921
20- func NewAgentClient (url string , apiKey string , apiSecret string , opts ... twirp. ClientOption ) (* AgentClient , error ) {
22+ func NewAgentClient (url string , apiKey string , apiSecret string , opts ... AgentClientOption ) (* AgentClient , error ) {
2123 serverUrl := os .Getenv ("LK_AGENTS_URL" )
2224 if serverUrl == "" {
2325 url = signalling .ToHttpURL (url )
2426 pattern := `^https?://[^.]+\.`
2527 re := regexp .MustCompile (pattern )
2628 serverUrl = re .ReplaceAllString (url , "https://agents." )
2729 }
30+ c := & AgentClient {
31+ authBase : authBase {apiKey , apiSecret },
32+ httpClient : & http.Client {},
33+ }
34+ for _ , opt := range opts {
35+ opt (c )
36+ }
37+ c .agentClient = livekit .NewCloudAgentProtobufClient (serverUrl , c .httpClient , c .twirpOpts ... )
38+ return c , nil
39+ }
40+
41+ type AgentClientOption func (* AgentClient )
2842
29- client := livekit .NewCloudAgentProtobufClient (serverUrl , & http.Client {}, opts ... )
30- return & AgentClient {
31- agentClient : client ,
32- authBase : authBase {apiKey , apiSecret },
33- }, nil
43+ func WithHTTPClient (httpClient * http.Client ) AgentClientOption {
44+ return func (c * AgentClient ) {
45+ c .httpClient = httpClient
46+ }
47+ }
48+
49+ func WithTwirpClientOptions (opts ... twirp.ClientOption ) AgentClientOption {
50+ return func (c * AgentClient ) {
51+ c .twirpOpts = opts
52+ }
3453}
3554
3655func (c * AgentClient ) CreateAgent (ctx context.Context , req * livekit.CreateAgentRequest ) (* livekit.CreateAgentResponse , error ) {
0 commit comments