Skip to content

Commit dbb96cc

Browse files
authored
Add AgentSimulationClient and CreateSourceZip (#874)
1 parent 65a5784 commit dbb96cc

File tree

5 files changed

+151
-10
lines changed

5 files changed

+151
-10
lines changed

agent_simulation_client.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731
1111
github.com/livekit/media-sdk v0.0.0-20260401192012-ea94ab340a57
1212
github.com/livekit/mediatransportutil v0.0.0-20251128105421-19c7a7b81c22
13-
github.com/livekit/protocol v1.45.1
13+
github.com/livekit/protocol v1.45.2-0.20260403151849-8a360e8d0221
1414
github.com/magefile/mage v1.15.0
1515
github.com/moby/buildkit v0.26.2
1616
github.com/moby/patternmatcher v0.6.0
@@ -60,7 +60,7 @@ require (
6060
github.com/frostbyte73/core v0.1.1
6161
github.com/fsnotify/fsnotify v1.9.0 // indirect
6262
github.com/gammazero/deque v1.2.1
63-
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
63+
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
6464
github.com/go-logr/logr v1.4.3 // indirect
6565
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
6666
github.com/gofrs/flock v0.13.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
101101
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
102102
github.com/gammazero/deque v1.2.1 h1:9fnQVFCCZ9/NOc7ccTNqzoKd1tCWOqeI05/lPqFPMGQ=
103103
github.com/gammazero/deque v1.2.1/go.mod h1:5nSFkzVm+afG9+gy0VIowlqVAW4N8zNcMne+CMQVD2g=
104-
github.com/go-jose/go-jose/v3 v3.0.4 h1:Wp5HA7bLQcKnf6YYao/4kpRpVMp/yf6+pJKV8WFSaNY=
105-
github.com/go-jose/go-jose/v3 v3.0.4/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
104+
github.com/go-jose/go-jose/v3 v3.0.5 h1:BLLJWbC4nMZOfuPVxoZIxeYsn6Nl2r1fITaJ78UQlVQ=
105+
github.com/go-jose/go-jose/v3 v3.0.5/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
106106
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
107107
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
108108
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -159,8 +159,8 @@ github.com/livekit/media-sdk v0.0.0-20260401192012-ea94ab340a57 h1:Y0dZHH9gY70h+
159159
github.com/livekit/media-sdk v0.0.0-20260401192012-ea94ab340a57/go.mod h1:7ssWiG+U4xnbvLih9WiZbhQP6zIKMjgXdUtIE1bm/E8=
160160
github.com/livekit/mediatransportutil v0.0.0-20251128105421-19c7a7b81c22 h1:dzCBxOGLLWVtQhL7OYK2EGN+5Q+23Mq/jfz4vQisirA=
161161
github.com/livekit/mediatransportutil v0.0.0-20251128105421-19c7a7b81c22/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
162-
github.com/livekit/protocol v1.45.1 h1:4cbynsPZW32gS2z6nUWfAfr4YaTUwZSKUiLpSpjX+lQ=
163-
github.com/livekit/protocol v1.45.1/go.mod h1:63AUi0vQak6Y6gPqSBHLc+ExYTUwEqF/m4b2IRW1iO0=
162+
github.com/livekit/protocol v1.45.2-0.20260403151849-8a360e8d0221 h1:loe7h+z1kOu/ojprFTYSZBbJVly7gdZgQ/ewElGeLPo=
163+
github.com/livekit/protocol v1.45.2-0.20260403151849-8a360e8d0221/go.mod h1:e6QdWDkfot+M2nRh0eitJUS0ZLuwvKCsfiz2pWWSG3s=
164164
github.com/livekit/psrpc v0.7.1 h1:ms37az0QTD3UXIWuUC5D/SkmKOlRMVRsI261eBWu/Vw=
165165
github.com/livekit/psrpc v0.7.1/go.mod h1:bZ4iHFQptTkbPnB0LasvRNu/OBYXEu1NA6O5BMFo9kk=
166166
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=

pkg/cloudagents/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/moby/patternmatcher"
2929
)
3030

31-
func createSourceTarball(
31+
func CreateSourceTarball(
3232
directory fs.FS,
3333
excludeFiles []string,
3434
w io.Writer,

pkg/cloudagents/upload.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ func uploadSource(
5555
excludeFiles []string,
5656
) error {
5757
var buf bytes.Buffer
58-
if err := createSourceTarball(directory, excludeFiles, &buf); err != nil {
58+
if err := CreateSourceTarball(directory, excludeFiles, &buf); err != nil {
5959
return fmt.Errorf("failed to sanitize source: %w", err)
6060
}
6161
if presignedPostRequest != nil {
62-
if err := multipartUpload(presignedPostRequest.Url, presignedPostRequest.Values, &buf); err != nil {
62+
if err := MultipartUpload(presignedPostRequest.Url, presignedPostRequest.Values, &buf); err != nil {
6363
return fmt.Errorf("multipart upload failed: %w", err)
6464
}
6565
} else {
@@ -89,7 +89,7 @@ func upload(presignedUrl string, buf *bytes.Buffer) error {
8989
return nil
9090
}
9191

92-
func multipartUpload(presignedURL string, fields map[string]string, buf *bytes.Buffer) error {
92+
func MultipartUpload(presignedURL string, fields map[string]string, buf *bytes.Buffer) error {
9393
var b bytes.Buffer
9494
w := multipart.NewWriter(&b)
9595
fileName, ok := fields["key"]

0 commit comments

Comments
 (0)