Skip to content

Commit cc5c2ac

Browse files
committed
add missed namespace code from rebase
Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
1 parent 1aad612 commit cc5c2ac

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

go/api/client/agent.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ package client
33
import (
44
"context"
55
"fmt"
6+
"net/url"
67

78
api "github.com/kagent-dev/kagent/go/api/httpapi"
89
"github.com/kagent-dev/kagent/go/api/v1alpha2"
910
)
1011

1112
// Agent defines the agent operations
1213
type Agent interface {
13-
ListAgents(ctx context.Context) (*api.StandardResponse[[]api.AgentResponse], error)
14+
ListAgents(ctx context.Context, opts ...ListAgentsOptions) (*api.StandardResponse[[]api.AgentResponse], error)
1415
CreateAgent(ctx context.Context, request *v1alpha2.Agent) (*api.StandardResponse[*v1alpha2.Agent], error)
1516
GetAgent(ctx context.Context, agentRef string) (*api.StandardResponse[*api.AgentResponse], error)
1617
UpdateAgent(ctx context.Context, request *v1alpha2.Agent) (*api.StandardResponse[*v1alpha2.Agent], error)
1718
DeleteAgent(ctx context.Context, agentRef string) error
1819
}
1920

21+
// ListAgentsOptions configures ListAgents requests.
22+
type ListAgentsOptions struct {
23+
Namespace string
24+
}
25+
2026
// agentClient handles agent-related requests
2127
type agentClient struct {
2228
client *BaseClient
@@ -27,14 +33,23 @@ func NewAgentClient(client *BaseClient) Agent {
2733
return &agentClient{client: client}
2834
}
2935

30-
// ListAgents lists all agents for a user
31-
func (c *agentClient) ListAgents(ctx context.Context) (*api.StandardResponse[[]api.AgentResponse], error) {
36+
// ListAgents lists all agents for a user. When Namespace is set, only agents in that namespace are returned.
37+
func (c *agentClient) ListAgents(ctx context.Context, opts ...ListAgentsOptions) (*api.StandardResponse[[]api.AgentResponse], error) {
38+
if len(opts) > 1 {
39+
return nil, fmt.Errorf("ListAgents accepts at most one options argument")
40+
}
41+
3242
userID := c.client.GetUserIDOrDefault("")
3343
if userID == "" {
3444
return nil, fmt.Errorf("userID is required")
3545
}
3646

37-
resp, err := c.client.Get(ctx, "/api/agents", userID)
47+
path := "/api/agents"
48+
if len(opts) > 0 && opts[0].Namespace != "" {
49+
path += "?namespace=" + url.QueryEscape(opts[0].Namespace)
50+
}
51+
52+
resp, err := c.client.Get(ctx, path, userID)
3853
if err != nil {
3954
return nil, err
4055
}

0 commit comments

Comments
 (0)