Skip to content

Commit 31bfaad

Browse files
Apikeys agent (#1716)
* Adding commands for Agent API Keys * Adding changes for API Keys and list version * Incorporating review comments * Updating modules modifying vendor * Fixing unit tests
1 parent d08294d commit 31bfaad

13 files changed

+1157
-1
lines changed

args.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,4 +794,13 @@ const (
794794

795795
// ArgFunctionRouteOutputSchema is the output schema of the function route
796796
ArgFunctionRouteOutputSchema = "output-schema"
797+
798+
// ArgAgentAPIKeyName is the name of API Key of the agent.
799+
ArgAgentAPIKeyName = "name"
800+
801+
// ArgAgentUUID is the uuid of the apikey.
802+
ArgAPIkeyUUID = "api-key-uuid"
803+
804+
// ArgAPIKeyForce forces API Key deletion without confirmation.
805+
ArgAPIKeyForce = "force"
797806
)

commands/displayers/genai.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
type Agent struct {
1010
Agents do.Agents
1111
}
12+
type ApiKeyInfo struct {
13+
ApiKeyInfo do.ApiKeys
14+
}
15+
16+
type AgentVersion struct {
17+
AgentVersions do.AgentVersions
18+
}
1219

1320
var _ Displayable = &Agent{}
1421

@@ -293,3 +300,106 @@ func (a *AgentRoute) KV() []map[string]any {
293300

294301
return out
295302
}
303+
304+
var _ Displayable = &ApiKeyInfo{}
305+
306+
func (v *ApiKeyInfo) JSON(out io.Writer) error {
307+
return writeJSON(v.ApiKeyInfo, out)
308+
}
309+
310+
func (a *ApiKeyInfo) Cols() []string {
311+
return []string{
312+
"Id",
313+
"Name",
314+
"CreatedBy",
315+
"SecretKey",
316+
"DeletedAt",
317+
"CreatedAt",
318+
}
319+
}
320+
321+
func (a *ApiKeyInfo) ColMap() map[string]string {
322+
return map[string]string{
323+
"Id": "ID",
324+
"Name": "Name",
325+
"SecretKey": "Secret Key",
326+
"CreatedBy": "Created By",
327+
"DeletedAt": "Deleted At",
328+
"CreatedAt": "Created At",
329+
}
330+
}
331+
332+
func (a *ApiKeyInfo) KV() []map[string]any {
333+
if a == nil || a.ApiKeyInfo == nil {
334+
return []map[string]any{}
335+
}
336+
out := make([]map[string]any, 0, len(a.ApiKeyInfo))
337+
for _, apikey := range a.ApiKeyInfo {
338+
339+
out = append(out, map[string]any{
340+
"Id": apikey.Uuid,
341+
"Name": apikey.Name,
342+
"SecretKey": apikey.SecretKey,
343+
"CreatedBy": apikey.CreatedBy,
344+
"CreatedAt": apikey.CreatedAt,
345+
"DeletedAt": apikey.DeletedAt,
346+
})
347+
}
348+
return out
349+
}
350+
351+
var _ Displayable = &AgentVersion{}
352+
353+
func (v *AgentVersion) JSON(out io.Writer) error {
354+
return writeJSON(v.AgentVersions, out)
355+
}
356+
357+
func (a *AgentVersion) Cols() []string {
358+
return []string{
359+
"AgentUuid",
360+
"CanRollback",
361+
"CreatedAt",
362+
"CreatedByEmail",
363+
"CurrentlyApplied",
364+
"ID",
365+
"ModelName",
366+
"Name",
367+
"VersionHash",
368+
}
369+
}
370+
371+
func (a *AgentVersion) ColMap() map[string]string {
372+
return map[string]string{
373+
"AgentUuid": "Agent UUID",
374+
"CanRollback": "Can Rollback",
375+
"CreatedAt": "Created At",
376+
"CreatedByEmail": "Created By Email",
377+
"CurrentlyApplied": "Currently Applied",
378+
"ID": "ID",
379+
"ModelName": "Model Name",
380+
"Name": "Name",
381+
"VersionHash": "Version Hash",
382+
}
383+
}
384+
385+
func (a *AgentVersion) KV() []map[string]any {
386+
if a == nil || a.AgentVersions == nil {
387+
return []map[string]any{}
388+
}
389+
out := make([]map[string]any, 0, len(a.AgentVersions))
390+
for _, v := range a.AgentVersions {
391+
392+
out = append(out, map[string]any{
393+
"AgentUuid": v.AgentUuid,
394+
"CanRollback": v.CanRollback,
395+
"CreatedAt": v.CreatedAt,
396+
"CreatedByEmail": v.CreatedByEmail,
397+
"CurrentlyApplied": v.CurrentlyApplied,
398+
"ID": v.ID,
399+
"ModelName": v.ModelName,
400+
"Name": v.Name,
401+
"VersionHash": v.VersionHash,
402+
})
403+
}
404+
return out
405+
}

commands/genai_agent.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func AgentCmd() *Command {
2020
Long: "The subcommands of `doctl genai agent` manage your GenAI agents.",
2121
},
2222
}
23+
cmd.AddCommand(AgentAPIKeyCmd())
2324

2425
// Add the agent route command as a subcommand to genai agent
2526
cmd.AddCommand(AgentRouteCmd())
@@ -137,6 +138,30 @@ func AgentCmd() *Command {
137138
AddStringFlag(cmdAgentUpdateVisibility, "visibility", "", "", "Agent deployment visibility. Possible Options: `VISIBILITY_PLAYGROUND`, `VISIBILITY_PUBLIC`, `VISIBILITY_PRIVATE`. Default: `VISIBILITY_UNKNOWN`", requiredOpt())
138139
cmdAgentUpdateVisibility.Example = `The following example updates the visibility of an agent with the ID ` + "`" + `12345678-1234-1234-1234-123456789012` + "`" + ` to ` + "`" + `VISIBILITY_PUBLIC` + "`" + `: doctl genai agent update-visibility 12345678-1234-1234-1234-123456789012 --visibility 'VISIBILITY_PUBLIC'`
139140

141+
AgentVersionDetails := `
142+
- The Agent ID
143+
- Can it be rollbacked
144+
- The Version creation date, in ISO8601 combined date and time format
145+
- The Email of the user who created the agent
146+
- Whether the version is currently active,
147+
- The Agent version ID
148+
- The Agent version model name
149+
- The Agent version name
150+
- The Agent version hash`
151+
152+
cmdAgentListVersions := CmdBuilder(
153+
cmd,
154+
RunAgentListVersions,
155+
"list-versions",
156+
"List versions for an agent",
157+
"Retrieves a list of all the versions for an agent on your account including the following information for each version:\n"+
158+
AgentVersionDetails,
159+
Writer,
160+
aliasOpt("lv", "list-versions"),
161+
displayerType(&displayers.AgentVersion{}),
162+
)
163+
cmdAgentListVersions.Example = `The following example retrieves a list of all versions for an Agent with ID ` + "`" + `12345678-1234-1234-1234-123456789012` + "`" + ` : doctl genai agent list-versions 12345678-1234-1234-1234-123456789012`
164+
140165
return cmd
141166
}
142167

@@ -314,3 +339,21 @@ func RunAgentUpdateVisibility(c *CmdConfig) error {
314339
}
315340
return c.Display(&displayers.Agent{Agents: do.Agents{*agent}})
316341
}
342+
343+
// RunAgentListVersions lists all versions for an agent.
344+
func RunAgentListVersions(c *CmdConfig) error {
345+
if len(c.Args) < 1 {
346+
return doctl.NewMissingArgsErr(c.NS)
347+
}
348+
agentID := c.Args[0]
349+
350+
agentVersions, err := c.GenAI().ListAgentVersions(agentID)
351+
if err != nil {
352+
return err
353+
}
354+
355+
filtered := make(do.AgentVersions, 0, len(agentVersions))
356+
filtered = append(filtered, agentVersions...)
357+
358+
return c.Display(&displayers.AgentVersion{AgentVersions: filtered})
359+
}

0 commit comments

Comments
 (0)