Skip to content

Commit 4e71824

Browse files
committed
add AgentSimulationClient, export CreateSourceTarball and MultipartUpload
Adds new client for the agent simulation API. Exports CreateSourceTarball and MultipartUpload for use by external callers (livekit-cli).
1 parent 7f973aa commit 4e71824

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

agent_simulation_client.go

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

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)