-
Notifications
You must be signed in to change notification settings - Fork 490
Added Agent route operations #1717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "github.com/digitalocean/doctl" | ||
| "github.com/digitalocean/doctl/commands/displayers" | ||
| "github.com/digitalocean/doctl/do" | ||
| "github.com/digitalocean/godo" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // AgentRouteCmd creates the agent route command and its subcommands. | ||
| func AgentRouteCmd() *Command { | ||
| cmd := &Command{ | ||
| Command: &cobra.Command{ | ||
| Use: "route", | ||
| Aliases: []string{"routes", "r"}, | ||
| Short: "Display commands for working with GenAI agent routes", | ||
| Long: "The subcommands of `doctl genai agent route` manage your GenAI agent routes.", | ||
| }, | ||
| } | ||
|
|
||
| cmdAddAgentRoute := CmdBuilder( | ||
| cmd, | ||
| RunAgentRouteAdd, | ||
| "add", | ||
| "Adds an agent route to an agent", | ||
| "Use this command to add an agent route to an agent. The command requires values for the "+"`"+"--parent-agent-id"+"` and "+"`"+"--child-agent-id"+"`"+" flags.", | ||
| Writer, | ||
| aliasOpt("c"), | ||
| displayerType(&displayers.AgentRoute{}), | ||
| ) | ||
| AddStringFlag(cmdAddAgentRoute, doctl.ArgParentAgentId, "", "", "Parent agent ID (required)", requiredOpt()) | ||
| AddStringFlag(cmdAddAgentRoute, doctl.ArgChildAgentId, "", "", "Child agent ID (required)", requiredOpt()) | ||
| AddStringFlag(cmdAddAgentRoute, doctl.ArgAgentRouteId, "", "", "Unique id of linkage") | ||
| AddStringFlag(cmdAddAgentRoute, doctl.ArgAgentRouteName, "", "", "Route name") | ||
| AddStringFlag(cmdAddAgentRoute, doctl.ArgAgentRouteIfCase, "", "", "Describes the case in which the child agent should be used") | ||
| cmdAddAgentRoute.Example = `doctl genai agent route add --parent-agent-id "12345678-1234-1234-1234-123456789012" --child-agent-id "12345678-1234-1234-1234-123456789013"` | ||
|
|
||
| cmdUpdateAgentRoute := CmdBuilder( | ||
| cmd, | ||
| RunAgentRouteUpdate, | ||
| "update", | ||
| "Updates an agent route to an agent", | ||
| "Use this command to updates an agent route to an agent.The command requires values for the "+"`"+"--parent-agent-id"+"` and "+"`"+"--child-agent-id"+"`"+" flags.", | ||
| Writer, | ||
| aliasOpt("u"), | ||
| displayerType(&displayers.AgentRoute{}), | ||
| ) | ||
| AddStringFlag(cmdUpdateAgentRoute, doctl.ArgParentAgentId, "", "", "Parent agent ID (required)", requiredOpt()) | ||
| AddStringFlag(cmdUpdateAgentRoute, doctl.ArgChildAgentId, "", "", "Child agent ID (required)", requiredOpt()) | ||
| AddStringFlag(cmdUpdateAgentRoute, doctl.ArgAgentRouteId, "", "", "Unique id of linkage") | ||
| AddStringFlag(cmdUpdateAgentRoute, doctl.ArgAgentRouteName, "", "", "Route name") | ||
| AddStringFlag(cmdUpdateAgentRoute, doctl.ArgAgentRouteIfCase, "", "", "Describes the case in which the child agent should be used") | ||
| cmdUpdateAgentRoute.Example = `doctl genai agent route update --parent-agent-id "12345678-1234-1234-1234-123456789012" --child-agent-id "12345678-1234-1234-1234-123456789013" --route-name "test_route" --if-case "use this to get test information"` | ||
|
|
||
| cmdDeleteAgentRoute := CmdBuilder( | ||
| cmd, | ||
| RunAgentRouteDelete, | ||
| "delete", | ||
| "Deletes an agent route to an agent", | ||
| "Use this command to delete an agent route to an agent. The command requires values for the "+"`"+"--parent-agent-id"+"` and "+"`"+"--child-agent-id"+"`"+" flags.", | ||
| Writer, | ||
| aliasOpt("d", "del", "rm"), | ||
| ) | ||
| AddStringFlag(cmdDeleteAgentRoute, doctl.ArgParentAgentId, "", "", "Parent agent ID (required)", requiredOpt()) | ||
| AddStringFlag(cmdDeleteAgentRoute, doctl.ArgChildAgentId, "", "", "Child agent ID (required)", requiredOpt()) | ||
| AddBoolFlag(cmdDeleteAgentRoute, doctl.ArgForce, doctl.ArgShortForce, false, "Force route deletion without confirmation") | ||
| cmdDeleteAgentRoute.Example = `doctl genai agent route delete --parent-agent-id "12345678-1234-1234-1234-123456789012" --child-agent-id "12345678-1234-1234-1234-123456789013"` | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| // RunAgentRouteAdd adds a route to an agent. | ||
| func RunAgentRouteAdd(c *CmdConfig) error { | ||
| parentAgentID, err := c.Doit.GetString(c.NS, doctl.ArgParentAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| childAgentID, err := c.Doit.GetString(c.NS, doctl.ArgChildAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| routeResponse, err := c.GenAI().AddAgentRoute(parentAgentID, childAgentID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.Display(&displayers.AgentRoute{AgentRouteResponses: []do.AgentRouteResponse{*routeResponse}}) | ||
| } | ||
|
|
||
| // RunAgentRouteUpdate updates a route to an agent. | ||
| func RunAgentRouteUpdate(c *CmdConfig) error { | ||
| parentAgentID, err := c.Doit.GetString(c.NS, doctl.ArgParentAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| childAgentID, err := c.Doit.GetString(c.NS, doctl.ArgChildAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| routeUUID, _ := c.Doit.GetString(c.NS, doctl.ArgAgentRouteId) | ||
| routeName, _ := c.Doit.GetString(c.NS, doctl.ArgAgentRouteName) | ||
| ifCase, _ := c.Doit.GetString(c.NS, doctl.ArgAgentRouteIfCase) | ||
|
|
||
| req := &godo.AgentRouteUpdateRequest{ | ||
| ChildAgentUuid: childAgentID, | ||
| IfCase: ifCase, | ||
| ParentAgentUuid: parentAgentID, | ||
| RouteName: routeName, | ||
| UUID: routeUUID, | ||
| } | ||
|
|
||
| routeResponse, err := c.GenAI().UpdateAgentRoute(parentAgentID, childAgentID, req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.Display(&displayers.AgentRoute{AgentRouteResponses: []do.AgentRouteResponse{*routeResponse}}) | ||
| } | ||
|
|
||
| // RunAgentRouteDelete deletes a route to an agent. | ||
| func RunAgentRouteDelete(c *CmdConfig) error { | ||
| parentAgentID, err := c.Doit.GetString(c.NS, doctl.ArgParentAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| childAgentID, err := c.Doit.GetString(c.NS, doctl.ArgChildAgentId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| force, err := c.Doit.GetBool(c.NS, doctl.ArgForce) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if force || AskForConfirmDelete("Agent Route", 1) == nil { | ||
| err := c.GenAI().DeleteAgentRoute(parentAgentID, childAgentID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| notice("Agent route deleted successfully") | ||
| return nil | ||
| } | ||
|
|
||
| return c.GenAI().DeleteAgentRoute(parentAgentID, childAgentID) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/digitalocean/doctl" | ||
| "github.com/digitalocean/doctl/do" | ||
| "github.com/digitalocean/godo" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var ( | ||
| testParentAgentID = "12345678-1234-1234-1234-123456789012" | ||
| testChildAgentID = "12345678-1234-1234-1234-123456789013" | ||
| testRouteUUID = "12345678-1234-1234-1234-123456789014" | ||
|
|
||
| testAgentRouteResponse = &do.AgentRouteResponse{ | ||
| AgentRouteResponse: &godo.AgentRouteResponse{ | ||
| ParentAgentUuid: testParentAgentID, | ||
| ChildAgentUuid: testChildAgentID, | ||
| UUID: testRouteUUID, | ||
| Rollback: false, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| func TestAgentRouteAdd(t *testing.T) { | ||
| withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
| tm.genAI.EXPECT().AddAgentRoute(testParentAgentID, testChildAgentID).Return(testAgentRouteResponse, nil) | ||
|
|
||
| config.Args = []string{} | ||
| config.Doit.Set(config.NS, doctl.ArgParentAgentId, testParentAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgChildAgentId, testChildAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteId, testRouteUUID) | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteName, "test_route") | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteIfCase, "test if case") | ||
|
|
||
| err := RunAgentRouteAdd(config) | ||
| assert.NoError(t, err) | ||
| }) | ||
| } | ||
|
|
||
| func TestAgentRouteUpdate(t *testing.T) { | ||
| withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
| expectedReq := &godo.AgentRouteUpdateRequest{ | ||
| ParentAgentUuid: testParentAgentID, | ||
| ChildAgentUuid: testChildAgentID, | ||
| UUID: testRouteUUID, | ||
| RouteName: "test_route", | ||
| IfCase: "test if case", | ||
| } | ||
|
|
||
| tm.genAI.EXPECT().UpdateAgentRoute(testParentAgentID, testChildAgentID, expectedReq).Return(testAgentRouteResponse, nil) | ||
|
|
||
| config.Args = []string{} | ||
| config.Doit.Set(config.NS, doctl.ArgParentAgentId, testParentAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgChildAgentId, testChildAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteId, testRouteUUID) | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteName, "test_route") | ||
| config.Doit.Set(config.NS, doctl.ArgAgentRouteIfCase, "test if case") | ||
|
|
||
| err := RunAgentRouteUpdate(config) | ||
| assert.NoError(t, err) | ||
| }) | ||
| } | ||
|
|
||
| func TestAgentRouteDelete(t *testing.T) { | ||
| withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
| tm.genAI.EXPECT().DeleteAgentRoute(testParentAgentID, testChildAgentID).Return(nil) | ||
|
|
||
| config.Args = []string{} | ||
| config.Doit.Set(config.NS, doctl.ArgParentAgentId, testParentAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgChildAgentId, testChildAgentID) | ||
| config.Doit.Set(config.NS, doctl.ArgForce, true) | ||
|
|
||
| err := RunAgentRouteDelete(config) | ||
| assert.NoError(t, err) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.