|
| 1 | +// Copyright 2025 LiveKit, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package lksdk |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "net/http" |
| 20 | + |
| 21 | + "github.com/twitchtv/twirp" |
| 22 | + |
| 23 | + "github.com/livekit/protocol/livekit" |
| 24 | +) |
| 25 | + |
| 26 | +type AgentSimulationClient struct { |
| 27 | + simulationClient livekit.AgentSimulation |
| 28 | + authBase |
| 29 | +} |
| 30 | + |
| 31 | +func NewAgentSimulationClient(url string, apiKey string, apiSecret string, opts ...twirp.ClientOption) *AgentSimulationClient { |
| 32 | + client := livekit.NewAgentSimulationProtobufClient(url, &http.Client{}, opts...) |
| 33 | + return &AgentSimulationClient{ |
| 34 | + simulationClient: client, |
| 35 | + authBase: authBase{apiKey, apiSecret}, |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func (c *AgentSimulationClient) CreateSimulationRun(ctx context.Context, req *livekit.SimulationRun_Create_Request) (*livekit.SimulationRun_Create_Response, error) { |
| 40 | + ctx, err := c.withAuth(ctx, withVideoGrant{}) |
| 41 | + if err != nil { |
| 42 | + return nil, err |
| 43 | + } |
| 44 | + return c.simulationClient.CreateSimulationRun(ctx, req) |
| 45 | +} |
| 46 | + |
| 47 | +func (c *AgentSimulationClient) ConfirmSimulationSourceUpload(ctx context.Context, req *livekit.SimulationRun_ConfirmSourceUpload_Request) (*livekit.SimulationRun_ConfirmSourceUpload_Response, error) { |
| 48 | + ctx, err := c.withAuth(ctx, withVideoGrant{}) |
| 49 | + if err != nil { |
| 50 | + return nil, err |
| 51 | + } |
| 52 | + return c.simulationClient.ConfirmSimulationSourceUpload(ctx, req) |
| 53 | +} |
| 54 | + |
| 55 | +func (c *AgentSimulationClient) GetSimulationRun(ctx context.Context, req *livekit.SimulationRun_Get_Request) (*livekit.SimulationRun_Get_Response, error) { |
| 56 | + ctx, err := c.withAuth(ctx, withVideoGrant{}) |
| 57 | + if err != nil { |
| 58 | + return nil, err |
| 59 | + } |
| 60 | + return c.simulationClient.GetSimulationRun(ctx, req) |
| 61 | +} |
| 62 | + |
| 63 | +func (c *AgentSimulationClient) ListSimulationRuns(ctx context.Context, req *livekit.SimulationRun_List_Request) (*livekit.SimulationRun_List_Response, error) { |
| 64 | + ctx, err := c.withAuth(ctx, withVideoGrant{}) |
| 65 | + if err != nil { |
| 66 | + return nil, err |
| 67 | + } |
| 68 | + return c.simulationClient.ListSimulationRuns(ctx, req) |
| 69 | +} |
| 70 | + |
| 71 | +func (c *AgentSimulationClient) CancelSimulationRun(ctx context.Context, req *livekit.SimulationRun_Cancel_Request) (*livekit.SimulationRun_Cancel_Response, error) { |
| 72 | + ctx, err := c.withAuth(ctx, withVideoGrant{}) |
| 73 | + if err != nil { |
| 74 | + return nil, err |
| 75 | + } |
| 76 | + return c.simulationClient.CancelSimulationRun(ctx, req) |
| 77 | +} |
0 commit comments