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

Method captureSharedScreenshot

coderd/x/chatd/chattool/computeruse.go:375–422  ·  view source on GitHub ↗
(
	ctx context.Context,
	conn workspacesdk.AgentConn,
	declaredWidth, declaredHeight int,
)

Source from the content-addressed store, hash-verified

373}
374
375func (t *computerUseTool) captureSharedScreenshot(
376 ctx context.Context,
377 conn workspacesdk.AgentConn,
378 declaredWidth, declaredHeight int,
379) (fantasy.ToolResponse, error) {
380 screenResp, err := executeScreenshotAction(ctx, conn, declaredWidth, declaredHeight)
381 if err != nil {
382 return fantasy.NewTextErrorResponse(
383 fmt.Sprintf("screenshot failed: %v", err),
384 ), nil
385 }
386
387 screenData, err := base64.StdEncoding.DecodeString(screenResp.ScreenshotData)
388 if err != nil {
389 t.logger.Error(ctx, "failed to decode screenshot base64 in captureSharedScreenshot",
390 slog.Error(err),
391 )
392 return fantasy.NewTextErrorResponse(
393 fmt.Sprintf("failed to decode screenshot data: %v", err),
394 ), nil
395 }
396
397 attachmentName := fmt.Sprintf(
398 "screenshot-%s.png",
399 t.clock.Now().UTC().Format("2006-01-02T15-04-05Z"),
400 )
401 if t.storeFile == nil {
402 t.logger.Warn(ctx, "screenshot attachment storage is not configured")
403 return fantasy.NewImageResponse(screenData, "image/png"), nil
404 }
405
406 response := fantasy.NewImageResponse(screenData, "image/png")
407
408 attachment, err := storeScreenshotAttachment(
409 ctx,
410 t.storeFile,
411 attachmentName,
412 screenResp.ScreenshotData,
413 )
414 if err != nil {
415 t.logger.Warn(ctx, "failed to persist screenshot attachment",
416 slog.F("attachment_name", attachmentName),
417 slog.Error(err),
418 )
419 return response, nil
420 }
421 return WithAttachments(response, attachment), nil
422}
423
424func executeScreenshotAction(
425 ctx context.Context,

Callers 2

runOpenAIComputerUseMethod · 0.95

Calls 6

executeScreenshotActionFunction · 0.85
WithAttachmentsFunction · 0.85
DecodeStringMethod · 0.80
FormatMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected