MCPcopy Index your code
hub / github.com/coder/coder / runAnthropicComputerUse

Method runAnthropicComputerUse

coderd/x/chatd/chattool/computeruse.go:178–240  ·  view source on GitHub ↗
(
	ctx context.Context,
	call fantasy.ToolCall,
)

Source from the content-addressed store, hash-verified

176}
177
178func (t *computerUseTool) runAnthropicComputerUse(
179 ctx context.Context,
180 call fantasy.ToolCall,
181) (fantasy.ToolResponse, error) {
182 input, err := fantasyanthropic.ParseComputerUseInput(call.Input)
183 if err != nil {
184 return fantasy.NewTextErrorResponse(
185 fmt.Sprintf("invalid computer use input: %v", err),
186 ), nil
187 }
188
189 conn, err := t.getWorkspaceConn(ctx)
190 if err != nil {
191 return fantasy.NewTextErrorResponse(
192 fmt.Sprintf("failed to connect to workspace: %v", err),
193 ), nil
194 }
195
196 declaredWidth, declaredHeight := t.declaredActionDimensions()
197
198 // For wait actions, sleep then return a screenshot.
199 if input.Action == fantasyanthropic.ActionWait {
200 t.wait(ctx, input.Duration)
201 return t.captureScreenshot(ctx, conn, declaredWidth, declaredHeight)
202 }
203
204 // For screenshot action, use ExecuteDesktopAction.
205 if input.Action == fantasyanthropic.ActionScreenshot {
206 return t.captureSharedScreenshot(ctx, conn, declaredWidth, declaredHeight)
207 }
208
209 // Build the action request.
210 action := t.desktopAction(string(input.Action), declaredWidth, declaredHeight)
211 if input.Coordinate != ([2]int64{}) {
212 coord := coordinateFromInt64(input.Coordinate[0], input.Coordinate[1])
213 action.Coordinate = &coord
214 }
215 if input.StartCoordinate != ([2]int64{}) {
216 coord := coordinateFromInt64(input.StartCoordinate[0], input.StartCoordinate[1])
217 action.StartCoordinate = &coord
218 }
219 if input.Text != "" {
220 action.Text = &input.Text
221 }
222 if input.Duration > 0 {
223 d := int(input.Duration)
224 action.Duration = &d
225 }
226 if input.ScrollAmount > 0 {
227 s := int(input.ScrollAmount)
228 action.ScrollAmount = &s
229 }
230 if input.ScrollDirection != "" {
231 action.ScrollDirection = &input.ScrollDirection
232 }
233
234 if resp, done := t.executeDesktopAction(ctx, conn, action); done {
235 return resp, nil

Callers 1

RunMethod · 0.95

Calls 8

waitMethod · 0.95
captureScreenshotMethod · 0.95
desktopActionMethod · 0.95
executeDesktopActionMethod · 0.95
getWorkspaceConnMethod · 0.80
coordinateFromInt64Function · 0.70

Tested by

no test coverage detected