Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3cf985

Browse files
committed
feat: add task send and logs MCP tools
1 parentc84ab72 commita3cf985

File tree

3 files changed

+378
-8
lines changed

3 files changed

+378
-8
lines changed

‎coderd/database/dbfake/dbfake.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,21 @@ func (b WorkspaceBuildBuilder) WithAgent(mutations ...func([]*sdkproto.Agent) []
119119
returnb
120120
}
121121

122-
func (bWorkspaceBuildBuilder)WithTask()WorkspaceBuildBuilder {
122+
func (bWorkspaceBuildBuilder)WithTask(seed*sdkproto.App)WorkspaceBuildBuilder {
123123
//nolint: revive // returns modified struct
124124
b.taskAppID=uuid.New()
125+
ifseed==nil {
126+
seed=&sdkproto.App{}
127+
}
125128
returnb.Params(database.WorkspaceBuildParameter{
126129
Name:codersdk.AITaskPromptParameterName,
127130
Value:"list me",
128131
}).WithAgent(func(a []*sdkproto.Agent) []*sdkproto.Agent {
129132
a[0].Apps= []*sdkproto.App{
130133
{
131-
Id:b.taskAppID.String(),
132-
Slug:"vcode",
134+
Id:takeFirst(seed.Id,b.taskAppID.String()),
135+
Slug:takeFirst(seed.Slug,"vcode"),
136+
Url:takeFirst(seed.Url,""),
133137
},
134138
}
135139
returna

‎codersdk/toolsdk/toolsdk.go‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const (
5555
ToolNameDeleteTask="coder_delete_task"
5656
ToolNameListTasks="coder_list_tasks"
5757
ToolNameGetTaskStatus="coder_get_task_status"
58+
ToolNameSendTaskInput="coder_send_task_input"
59+
ToolNameGetTaskLogs="coder_get_task_logs"
5860
)
5961

6062
funcNewDeps(client*codersdk.Client,opts...func(*Deps)) (Deps,error) {
@@ -233,6 +235,8 @@ var All = []GenericTool{
233235
DeleteTask.Generic(),
234236
ListTasks.Generic(),
235237
GetTaskStatus.Generic(),
238+
SendTaskInput.Generic(),
239+
GetTaskLogs.Generic(),
236240
}
237241

238242
typeReportTaskArgsstruct {
@@ -2033,6 +2037,107 @@ var GetTaskStatus = Tool[GetTaskStatusArgs, GetTaskStatusResponse]{
20332037
},
20342038
}
20352039

2040+
typeSendTaskInputArgsstruct {
2041+
TaskIDstring`json:"task_id"`
2042+
Inputstring`json:"input"`
2043+
}
2044+
2045+
varSendTaskInput=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,depsDeps,argsSendTaskInputArgs) (codersdk.Response,error) {
2065+
ifargs.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+
iferr!=nil {
2074+
ws,err:=normalizedNamedWorkspace(ctx,deps.coderClient,args.TaskID)
2075+
iferr!=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+
iferr!=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+
typeGetTaskLogsArgsstruct {
2096+
TaskIDstring`json:"task_id"`
2097+
}
2098+
2099+
varGetTaskLogs=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,depsDeps,argsGetTaskLogsArgs) (codersdk.TaskLogsResponse,error) {
2115+
ifargs.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+
iferr!=nil {
2124+
ws,err:=normalizedNamedWorkspace(ctx,deps.coderClient,args.TaskID)
2125+
iferr!=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+
iferr!=nil {
2134+
return codersdk.TaskLogsResponse{},xerrors.Errorf("get task logs %q: %w",args.TaskID,err)
2135+
}
2136+
2137+
returnlogs,nil
2138+
},
2139+
}
2140+
20362141
// normalizedNamedWorkspace normalizes the workspace name before getting the
20372142
// workspace by name.
20382143
funcnormalizedNamedWorkspace(ctx context.Context,client*codersdk.Client,namestring) (codersdk.Workspace,error) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp