@@ -55,6 +55,8 @@ const (
55
55
ToolNameDeleteTask = "coder_delete_task"
56
56
ToolNameListTasks = "coder_list_tasks"
57
57
ToolNameGetTaskStatus = "coder_get_task_status"
58
+ ToolNameSendTaskInput = "coder_send_task_input"
59
+ ToolNameGetTaskLogs = "coder_get_task_logs"
58
60
)
59
61
60
62
func NewDeps (client * codersdk.Client ,opts ... func (* Deps )) (Deps ,error ) {
@@ -233,6 +235,8 @@ var All = []GenericTool{
233
235
DeleteTask .Generic (),
234
236
ListTasks .Generic (),
235
237
GetTaskStatus .Generic (),
238
+ SendTaskInput .Generic (),
239
+ GetTaskLogs .Generic (),
236
240
}
237
241
238
242
type ReportTaskArgs struct {
@@ -2033,6 +2037,107 @@ var GetTaskStatus = Tool[GetTaskStatusArgs, GetTaskStatusResponse]{
2033
2037
},
2034
2038
}
2035
2039
2040
+ type SendTaskInputArgs struct {
2041
+ TaskID string `json:"task_id"`
2042
+ Input string `json:"input"`
2043
+ }
2044
+
2045
+ var SendTaskInput = Tool [SendTaskInputArgs , codersdk.Response ]{
2046
+ Tool : aisdk.Tool {
2047
+ Name :ToolNameSendTaskInput ,
2048
+ Description :`Send input to a running task.` ,
2049
+ Schema : aisdk.Schema {
2050
+ Properties :map [string ]any {
2051
+ "task_id" :map [string ]any {
2052
+ "type" :"string" ,
2053
+ "description" :taskIDDescription ("prompt" ),
2054
+ },
2055
+ "input" :map [string ]any {
2056
+ "type" :"string" ,
2057
+ "description" :"The input to send to the task." ,
2058
+ },
2059
+ },
2060
+ Required : []string {"task_id" ,"input" },
2061
+ },
2062
+ },
2063
+ UserClientOptional :true ,
2064
+ Handler :func (ctx context.Context ,deps Deps ,args SendTaskInputArgs ) (codersdk.Response ,error ) {
2065
+ if args .TaskID == "" {
2066
+ return codersdk.Response {},xerrors .New ("task_id is required" )
2067
+ }
2068
+
2069
+ expClient := codersdk .NewExperimentalClient (deps .coderClient )
2070
+
2071
+ id ,err := uuid .Parse (args .TaskID )
2072
+ owner := codersdk .Me
2073
+ if err != nil {
2074
+ ws ,err := normalizedNamedWorkspace (ctx ,deps .coderClient ,args .TaskID )
2075
+ if err != nil {
2076
+ return codersdk.Response {},xerrors .Errorf ("get task workspace %q: %w" ,args .TaskID ,err )
2077
+ }
2078
+ owner = ws .OwnerName
2079
+ id = ws .ID
2080
+ }
2081
+
2082
+ err = expClient .TaskSend (ctx ,owner ,id , codersdk.TaskSendRequest {
2083
+ Input :args .Input ,
2084
+ })
2085
+ if err != nil {
2086
+ return codersdk.Response {},xerrors .Errorf ("send task input %q: %w" ,args .TaskID ,err )
2087
+ }
2088
+
2089
+ return codersdk.Response {
2090
+ Message :"Input received." ,
2091
+ },nil
2092
+ },
2093
+ }
2094
+
2095
+ type GetTaskLogsArgs struct {
2096
+ TaskID string `json:"task_id"`
2097
+ }
2098
+
2099
+ var GetTaskLogs = Tool [GetTaskLogsArgs , codersdk.TaskLogsResponse ]{
2100
+ Tool : aisdk.Tool {
2101
+ Name :ToolNameGetTaskLogs ,
2102
+ Description :`Get the logs of a task.` ,
2103
+ Schema : aisdk.Schema {
2104
+ Properties :map [string ]any {
2105
+ "task_id" :map [string ]any {
2106
+ "type" :"string" ,
2107
+ "description" :taskIDDescription ("query" ),
2108
+ },
2109
+ },
2110
+ Required : []string {"task_id" },
2111
+ },
2112
+ },
2113
+ UserClientOptional :true ,
2114
+ Handler :func (ctx context.Context ,deps Deps ,args GetTaskLogsArgs ) (codersdk.TaskLogsResponse ,error ) {
2115
+ if args .TaskID == "" {
2116
+ return codersdk.TaskLogsResponse {},xerrors .New ("task_id is required" )
2117
+ }
2118
+
2119
+ expClient := codersdk .NewExperimentalClient (deps .coderClient )
2120
+
2121
+ id ,err := uuid .Parse (args .TaskID )
2122
+ owner := codersdk .Me
2123
+ if err != nil {
2124
+ ws ,err := normalizedNamedWorkspace (ctx ,deps .coderClient ,args .TaskID )
2125
+ if err != nil {
2126
+ return codersdk.TaskLogsResponse {},xerrors .Errorf ("get task workspace %q: %w" ,args .TaskID ,err )
2127
+ }
2128
+ owner = ws .OwnerName
2129
+ id = ws .ID
2130
+ }
2131
+
2132
+ logs ,err := expClient .TaskLogs (ctx ,owner ,id )
2133
+ if err != nil {
2134
+ return codersdk.TaskLogsResponse {},xerrors .Errorf ("get task logs %q: %w" ,args .TaskID ,err )
2135
+ }
2136
+
2137
+ return logs ,nil
2138
+ },
2139
+ }
2140
+
2036
2141
// normalizedNamedWorkspace normalizes the workspace name before getting the
2037
2142
// workspace by name.
2038
2143
func normalizedNamedWorkspace (ctx context.Context ,client * codersdk.Client ,name string ) (codersdk.Workspace ,error ) {