mirror of
https://github.com/coder/coder.git
synced 2026-06-06 22:48:19 +00:00
80a172f932
- Moves `coderd/chatd/`, `coderd/gitsync/`, `enterprise/coderd/chatd/` under `x/` parent directories to signal instability - Adds `Experimental:` glue code comments in `coderd/coderd.go` > 🤖 This PR was created with the help of Coder Agents, and was reviewed by my human. 🧑💻
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package chattool
|
|
|
|
import (
|
|
"context"
|
|
|
|
"charm.land/fantasy"
|
|
|
|
"github.com/coder/coder/v2/codersdk/workspacesdk"
|
|
)
|
|
|
|
type EditFilesOptions struct {
|
|
GetWorkspaceConn func(context.Context) (workspacesdk.AgentConn, error)
|
|
}
|
|
|
|
type EditFilesArgs struct {
|
|
Files []workspacesdk.FileEdits `json:"files"`
|
|
}
|
|
|
|
func EditFiles(options EditFilesOptions) fantasy.AgentTool {
|
|
return fantasy.NewAgentTool(
|
|
"edit_files",
|
|
"Perform search-and-replace edits on one or more files in the workspace."+
|
|
" Each file can have multiple edits applied atomically.",
|
|
func(ctx context.Context, args EditFilesArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) {
|
|
if options.GetWorkspaceConn == nil {
|
|
return fantasy.NewTextErrorResponse("workspace connection resolver is not configured"), nil
|
|
}
|
|
conn, err := options.GetWorkspaceConn(ctx)
|
|
if err != nil {
|
|
return fantasy.NewTextErrorResponse(err.Error()), nil
|
|
}
|
|
return executeEditFilesTool(ctx, conn, args)
|
|
},
|
|
)
|
|
}
|
|
|
|
func executeEditFilesTool(
|
|
ctx context.Context,
|
|
conn workspacesdk.AgentConn,
|
|
args EditFilesArgs,
|
|
) (fantasy.ToolResponse, error) {
|
|
if len(args.Files) == 0 {
|
|
return fantasy.NewTextErrorResponse("files is required"), nil
|
|
}
|
|
|
|
if err := conn.EditFiles(ctx, workspacesdk.FileEditRequest{Files: args.Files}); err != nil {
|
|
return fantasy.NewTextErrorResponse(err.Error()), nil
|
|
}
|
|
return toolResponse(map[string]any{"ok": true}), nil
|
|
}
|