|
| 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, withAgentGrant{SimulationAdmin: true}) |
| 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, withAgentGrant{SimulationAdmin: true}) |
| 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, withAgentGrant{SimulationAdmin: true}) |
| 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, withAgentGrant{SimulationAdmin: true}) |
| 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, withAgentGrant{SimulationAdmin: true}) |
| 73 | + if err != nil { |
| 74 | + return nil, err |
| 75 | + } |
| 76 | + return c.simulationClient.CancelSimulationRun(ctx, req) |
| 77 | +} |
| 78 | + |
| 79 | +func (c *AgentSimulationClient) CreateScenario(ctx context.Context, req *livekit.Scenario_Create_Request) (*livekit.Scenario_Create_Response, error) { |
| 80 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 81 | + if err != nil { |
| 82 | + return nil, err |
| 83 | + } |
| 84 | + return c.simulationClient.CreateScenario(ctx, req) |
| 85 | +} |
| 86 | + |
| 87 | +func (c *AgentSimulationClient) CreateScenarioFromSession(ctx context.Context, req *livekit.Scenario_CreateFromSession_Request) (*livekit.Scenario_CreateFromSession_Response, error) { |
| 88 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 89 | + if err != nil { |
| 90 | + return nil, err |
| 91 | + } |
| 92 | + return c.simulationClient.CreateScenarioFromSession(ctx, req) |
| 93 | +} |
| 94 | + |
| 95 | +func (c *AgentSimulationClient) DeleteScenario(ctx context.Context, req *livekit.Scenario_Delete_Request) (*livekit.Scenario_Delete_Response, error) { |
| 96 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 97 | + if err != nil { |
| 98 | + return nil, err |
| 99 | + } |
| 100 | + return c.simulationClient.DeleteScenario(ctx, req) |
| 101 | +} |
| 102 | + |
| 103 | +func (c *AgentSimulationClient) UpdateScenario(ctx context.Context, req *livekit.Scenario_Update_Request) (*livekit.Scenario_Update_Response, error) { |
| 104 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 105 | + if err != nil { |
| 106 | + return nil, err |
| 107 | + } |
| 108 | + return c.simulationClient.UpdateScenario(ctx, req) |
| 109 | +} |
| 110 | + |
| 111 | +func (c *AgentSimulationClient) CreateScenarioGroup(ctx context.Context, req *livekit.ScenarioGroup_Create_Request) (*livekit.ScenarioGroup_Create_Response, error) { |
| 112 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 113 | + if err != nil { |
| 114 | + return nil, err |
| 115 | + } |
| 116 | + return c.simulationClient.CreateScenarioGroup(ctx, req) |
| 117 | +} |
| 118 | + |
| 119 | +func (c *AgentSimulationClient) DeleteScenarioGroup(ctx context.Context, req *livekit.ScenarioGroup_Delete_Request) (*livekit.ScenarioGroup_Delete_Response, error) { |
| 120 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 121 | + if err != nil { |
| 122 | + return nil, err |
| 123 | + } |
| 124 | + return c.simulationClient.DeleteScenarioGroup(ctx, req) |
| 125 | +} |
| 126 | + |
| 127 | +func (c *AgentSimulationClient) ListScenarioGroups(ctx context.Context, req *livekit.ScenarioGroup_List_Request) (*livekit.ScenarioGroup_List_Response, error) { |
| 128 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 129 | + if err != nil { |
| 130 | + return nil, err |
| 131 | + } |
| 132 | + return c.simulationClient.ListScenarioGroups(ctx, req) |
| 133 | +} |
| 134 | + |
| 135 | +func (c *AgentSimulationClient) ListScenarios(ctx context.Context, req *livekit.Scenario_List_Request) (*livekit.Scenario_List_Response, error) { |
| 136 | + ctx, err := c.withAuth(ctx, withAgentGrant{SimulationAdmin: true}) |
| 137 | + if err != nil { |
| 138 | + return nil, err |
| 139 | + } |
| 140 | + return c.simulationClient.ListScenarios(ctx, req) |
| 141 | +} |
0 commit comments