R/ai_tool_read_currently_open_file.R

Defines functions read_currently_open_file

#' @importFrom rstudioapi getSourceEditorContext
read_currently_open_file <- function(args) {
  if (!validate_command_args(ai_tool_read_currently_open_file, args)) {
    stop("Invalid arguments for ReadCurrentlyOpenFile")
  }
  context <- getSourceEditorContext()
  if (is.null(context)) {
    return(list(filepath = "NO CURRENT FILE", content = "There are no files currently open."))
  }
  filepath <- context$path
  if (nchar(filepath) == 0) {
    filepath <- "ACTIVE_R_DOCUMENT"
  }
  list(filepath = filepath, content = paste(context$contents, collapse = "\n"))
}

ai_tool_read_currently_open_file <- list(
  name = "ReadCurrentlyOpenFile",
  parameters = list(),
  display_title = "Read Currently Open File",
  would_like_to = "Read the current file",
  is_currently = "Reading the current file",
  has_already = "Read the current file",
  readonly = TRUE,
  execute = read_currently_open_file
)

Try the myownrobs package in your browser

Any scripts or data that you put into this service are public.

myownrobs documentation built on Nov. 5, 2025, 5:52 p.m.