MCPcopy Index your code
hub / github.com/coder/coder / ListSubAgents

Method ListSubAgents

coderd/agentapi/subagent.go:348–373  ·  view source on GitHub ↗
(ctx context.Context, _ *agentproto.ListSubAgentsRequest)

Source from the content-addressed store, hash-verified

346}
347
348func (a *SubAgentAPI) ListSubAgents(ctx context.Context, _ *agentproto.ListSubAgentsRequest) (*agentproto.ListSubAgentsResponse, error) {
349 //nolint:gocritic // This gives us only the permissions required to do the job.
350 ctx = dbauthz.AsSubAgentAPI(ctx, a.OrganizationID, a.OwnerID)
351
352 parentAgent, err := a.AgentFn(ctx)
353 if err != nil {
354 return nil, xerrors.Errorf("get parent agent: %w", err)
355 }
356
357 workspaceAgents, err := a.Database.GetWorkspaceAgentsByParentID(ctx, parentAgent.ID)
358 if err != nil {
359 return nil, err
360 }
361
362 agents := make([]*agentproto.SubAgent, len(workspaceAgents))
363
364 for i, agent := range workspaceAgents {
365 agents[i] = &agentproto.SubAgent{
366 Name: agent.Name,
367 Id: agent.ID[:],
368 AuthToken: agent.AuthToken[:],
369 }
370 }
371
372 return &agentproto.ListSubAgentsResponse{Agents: agents}, nil
373}

Callers 1

TestSubAgentAPIFunction · 0.95

Calls 3

AsSubAgentAPIFunction · 0.92
ErrorfMethod · 0.45

Tested by 1

TestSubAgentAPIFunction · 0.76