@@ -45,6 +45,7 @@ const (
45
45
ToolNameWorkspaceReadFile = "coder_workspace_read_file"
46
46
ToolNameWorkspaceWriteFile = "coder_workspace_write_file"
47
47
ToolNameWorkspaceEditFile = "coder_workspace_edit_file"
48
+ ToolNameWorkspaceEditFiles = "coder_workspace_edit_files"
48
49
)
49
50
50
51
func NewDeps (client * codersdk.Client , opts ... func (* Deps )) (Deps , error ) {
@@ -215,6 +216,7 @@ var All = []GenericTool{
215
216
WorkspaceReadFile .Generic (),
216
217
WorkspaceWriteFile .Generic (),
217
218
WorkspaceEditFile .Generic (),
219
+ WorkspaceEditFiles .Generic (),
218
220
}
219
221
220
222
type ReportTaskArgs struct {
@@ -1563,6 +1565,80 @@ var WorkspaceEditFile = Tool[WorkspaceEditFileArgs, codersdk.Response]{
1563
1565
},
1564
1566
}
1565
1567
1568
+ type WorkspaceEditFilesArgs struct {
1569
+ Workspace string `json:"workspace"`
1570
+ Files []workspacesdk.FileEdits `json:"files"`
1571
+ }
1572
+
1573
+ var WorkspaceEditFiles = Tool [WorkspaceEditFilesArgs , codersdk.Response ]{
1574
+ Tool : aisdk.Tool {
1575
+ Name : ToolNameWorkspaceEditFiles ,
1576
+ Description : `Edit one or more files in a workspace.` ,
1577
+ Schema : aisdk.Schema {
1578
+ Properties : map [string ]any {
1579
+ "workspace" : map [string ]any {
1580
+ "type" : "string" ,
1581
+ "description" : "The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used." ,
1582
+ },
1583
+ "files" : map [string ]any {
1584
+ "type" : "array" ,
1585
+ "description" : "An array of files to edit." ,
1586
+ "items" : []any {
1587
+ map [string ]any {
1588
+ "type" : "object" ,
1589
+ "properties" : map [string ]any {
1590
+ "path" : map [string ]any {
1591
+ "type" : "string" ,
1592
+ "description" : "The absolute path of the file to write in the workspace." ,
1593
+ },
1594
+ "edits" : map [string ]any {
1595
+ "type" : "array" ,
1596
+ "description" : "An array of edit operations." ,
1597
+ "items" : []any {
1598
+ map [string ]any {
1599
+ "type" : "object" ,
1600
+ "properties" : map [string ]any {
1601
+ "search" : map [string ]any {
1602
+ "type" : "string" ,
1603
+ "description" : "The old string to replace." ,
1604
+ },
1605
+ "replace" : map [string ]any {
1606
+ "type" : "string" ,
1607
+ "description" : "The new string that replaces the old string." ,
1608
+ },
1609
+ },
1610
+ "required" : []string {"search" , "replace" },
1611
+ },
1612
+ },
1613
+ },
1614
+ "required" : []string {"path" , "edits" },
1615
+ },
1616
+ },
1617
+ },
1618
+ },
1619
+ },
1620
+ Required : []string {"workspace" , "files" },
1621
+ },
1622
+ },
1623
+ UserClientOptional : true ,
1624
+ Handler : func (ctx context.Context , deps Deps , args WorkspaceEditFilesArgs ) (codersdk.Response , error ) {
1625
+ conn , err := newAgentConn (ctx , deps .coderClient , args .Workspace )
1626
+ if err != nil {
1627
+ return codersdk.Response {}, err
1628
+ }
1629
+ defer conn .Close ()
1630
+
1631
+ err = conn .EditFiles (ctx , workspacesdk.FileEditRequest {Files : args .Files })
1632
+ if err != nil {
1633
+ return codersdk.Response {}, err
1634
+ }
1635
+
1636
+ return codersdk.Response {
1637
+ Message : "File(s) edited successfully." ,
1638
+ }, nil
1639
+ },
1640
+ }
1641
+
1566
1642
// NormalizeWorkspaceInput converts workspace name input to standard format.
1567
1643
// Handles the following input formats:
1568
1644
// - workspace → workspace
0 commit comments