diff --git a/NAMESPACE b/NAMESPACE index 8f2065a..9cfc1e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,9 +1,9 @@ # Generated by roxygen2: do not edit by hand S3method(print,pal_response) +export(.pal_add) export(.pal_addin) export(.pal_init) -export(pal_add) import(rlang) importFrom(elmer,content_image_file) importFrom(glue,glue) diff --git a/R/pal-add-remove.R b/R/pal-add-remove.R index aceb0e1..13e4624 100644 --- a/R/pal-add-remove.R +++ b/R/pal-add-remove.R @@ -1,7 +1,7 @@ #' Creating custom pals #' #' @description -#' Users can create custom pals using the `pal_add()` function; after passing +#' Users can create custom pals using the `.pal_add()` function; after passing #' the function a role and prompt, the pal will be available on the command #' palette. #' @@ -15,20 +15,13 @@ #' [cli pal][pal_cli] `"replace"`s the selection, while the #' [roxygen pal][pal_roxygen] `"prefixes"` the selected code with documentation. #' -#' @details -#' `pal_add()` will register the add-in as coming from the pal package -#' itself—because of this, custom pals will be deleted when the pal -#' package is reinstalled. Include `pal_add()` code in your `.Rprofile` or -#' make a pal extension package using `pal_add(package = TRUE)` to create -#' persistent custom pals. -#' #' @returns #' `NULL`, invisibly. Called for its side effect: a pal with role `role` #' is registered with the pal package. #' #' @name pal_add_remove #' @export -pal_add <- function( +.pal_add <- function( role, prompt = NULL, interface = c("replace", "prefix", "suffix") @@ -45,7 +38,7 @@ pal_add <- function( } #' @rdname pal_add_remove -pal_remove <- function(role) { +.pal_remove <- function(role) { check_string(role) if (!role %in% list_pals()) { cli::cli_abort("No active pal with the given {.arg role}.") diff --git a/R/pal-init.R b/R/pal-init.R index 55e80b5..4e03818 100644 --- a/R/pal-init.R +++ b/R/pal-init.R @@ -4,12 +4,12 @@ #' **Users typically should not need to call this function.** #' #' * Create new pals that will automatically be registered with this function -#' with [pal_add()]. +#' with [.pal_add()]. #' * The [pal addin][.pal_addin()] will initialize needed pals on-the-fly. #' #' @param role The identifier for a pal prompt. By default one #' of `r glue::glue_collapse(paste0("[", glue::double_quote(default_roles), "]", "[pal_", default_roles, "]"), ", ", last = " or ")`, -#' though custom pals can be added with [pal_add()]. +#' though custom pals can be added with [.pal_add()]. #' @param fn A `new_*()` function, likely from the elmer package. Defaults #' to [elmer::chat_claude()]. To set a persistent alternative default, #' set the `.pal_fn` option; see examples below. @@ -52,7 +52,7 @@ if (!role %in% list_pals()) { cli::cli_abort(c( "No pals with role {.arg {role}} registered.", - "i" = "See {.fn pal_add}." + "i" = "See {.fn .pal_add}." )) } diff --git a/R/zzz.R b/R/zzz.R index 2c7b839..83d182b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -11,7 +11,7 @@ prompt <- paste0(readLines(prompts[idx]), collapse = "\n") interface <- roles_and_interfaces[[idx]][2] - pal_add(role = role, prompt = prompt, interface = interface) + .pal_add(role = role, prompt = prompt, interface = interface) } } diff --git a/man/dot-pal_init.Rd b/man/dot-pal_init.Rd index 36b3607..9e006a2 100644 --- a/man/dot-pal_init.Rd +++ b/man/dot-pal_init.Rd @@ -14,7 +14,7 @@ \arguments{ \item{role}{The identifier for a pal prompt. By default one of \link[=pal_cli]{"cli"}, \link[=pal_testthat]{"testthat"} or \link[=pal_roxygen]{"roxygen"}, -though custom pals can be added with \code{\link[=pal_add]{pal_add()}}.} +though custom pals can be added with \code{\link[=.pal_add]{.pal_add()}}.} \item{fn}{A \verb{new_*()} function, likely from the elmer package. Defaults to \code{\link[elmer:chat_claude]{elmer::chat_claude()}}. To set a persistent alternative default, @@ -30,7 +30,7 @@ set the \code{.pal_args} option; see examples below.} \strong{Users typically should not need to call this function.} \itemize{ \item Create new pals that will automatically be registered with this function -with \code{\link[=pal_add]{pal_add()}}. +with \code{\link[=.pal_add]{.pal_add()}}. \item The \link[=.pal_addin]{pal addin} will initialize needed pals on-the-fly. } } @@ -43,10 +43,10 @@ to look for your API credentials and will call needed functions by itself. \examples{ \dontshow{if (FALSE) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # to create a chat with claude: - .pal_init() +.pal_init() # or with OpenAI's 4o-mini: - .pal_init( +.pal_init( "chat_openai", model = "gpt-4o-mini" ) diff --git a/man/pal_add_remove.Rd b/man/pal_add_remove.Rd index 918265a..a396fcd 100644 --- a/man/pal_add_remove.Rd +++ b/man/pal_add_remove.Rd @@ -2,16 +2,16 @@ % Please edit documentation in R/pal-add-remove.R \name{pal_add_remove} \alias{pal_add_remove} -\alias{pal_add} -\alias{pal_remove} +\alias{.pal_add} +\alias{.pal_remove} \title{Creating custom pals} \usage{ -pal_add(role, prompt = NULL, interface = c("replace", "prefix", "suffix")) +.pal_add(role, prompt = NULL, interface = c("replace", "prefix", "suffix")) -pal_remove(role) +.pal_remove(role) } \arguments{ -\item{role}{A single string giving the \code{\link[= .pal_init]{ .pal_init()}} role.} +\item{role}{A single string giving the \code{\link[=.pal_init]{.pal_init()}} role.} \item{prompt}{A file path to a markdown file giving the system prompt or the output of \code{\link[elmer:interpolate]{elmer::interpolate()}}.} @@ -26,14 +26,7 @@ how the pal will interact with the selection. For example, the is registered with the pal package. } \description{ -Users can create custom pals using the \code{pal_add()} function; after passing +Users can create custom pals using the \code{.pal_add()} function; after passing the function a role and prompt, the pal will be available on the command palette. } -\details{ -\code{pal_add()} will register the add-in as coming from the pal package -itself—because of this, custom pals will be deleted when the pal -package is reinstalled. Include \code{pal_add()} code in your \code{.Rprofile} or -make a pal extension package using \code{pal_add(package = TRUE)} to create -persistent custom pals. -} diff --git a/man/pal_cli.Rd b/man/pal_cli.Rd index be801a2..4155eb1 100644 --- a/man/pal_cli.Rd +++ b/man/pal_cli.Rd @@ -175,7 +175,7 @@ Returns: Pals are typically interfaced with via the pal addin. To call the cli pal directly, use: -\if{html}{\out{
}}\preformatted{pal_cli <- .pal_init("cli") +\if{html}{\out{
}}\preformatted{pal_cli <- .pal_init("cli") }\if{html}{\out{
}} Then, to submit a query, run: diff --git a/man/pal_roxygen.Rd b/man/pal_roxygen.Rd index 68f376e..7b0c348 100644 --- a/man/pal_roxygen.Rd +++ b/man/pal_roxygen.Rd @@ -150,7 +150,7 @@ Returns: Pals are typically interfaced with via the pal addin. To call the roxygen pal directly, use: -\if{html}{\out{
}}\preformatted{pal_roxygen <- .pal_init("roxygen") +\if{html}{\out{
}}\preformatted{pal_roxygen <- .pal_init("roxygen") }\if{html}{\out{
}} Then, to submit a query, run: diff --git a/man/pal_testthat.Rd b/man/pal_testthat.Rd index 9cd39c7..5c83f62 100644 --- a/man/pal_testthat.Rd +++ b/man/pal_testthat.Rd @@ -168,7 +168,7 @@ Returns: Pals are typically interfaced with via the pal addin. To call the testthat pal directly, use: -\if{html}{\out{
}}\preformatted{pal_testthat <- .pal_init("testthat") +\if{html}{\out{
}}\preformatted{pal_testthat <- .pal_init("testthat") }\if{html}{\out{
}} Then, to submit a query, run: diff --git a/tests/testthat/_snaps/pal-add-remove.md b/tests/testthat/_snaps/pal-add-remove.md index 34356c3..b361a8f 100644 --- a/tests/testthat/_snaps/pal-add-remove.md +++ b/tests/testthat/_snaps/pal-add-remove.md @@ -9,48 +9,48 @@ # pal addition with bad inputs Code - pal_add(role = identity, prompt = "hey") + .pal_add(role = identity, prompt = "hey") Condition - Error in `pal_add()`: + Error in `.pal_add()`: ! `role` must be a single string, not a function. --- Code - pal_add(role = "sillyhead", prompt = "hey", interface = "no") + .pal_add(role = "sillyhead", prompt = "hey", interface = "no") Condition - Error in `pal_add()`: + Error in `.pal_add()`: ! `interface` should be one of "replace", "prefix", or "suffix". --- Code - pal_add(role = "sillyhead", prompt = "hey", interface = "suffix") + .pal_add(role = "sillyhead", prompt = "hey", interface = "suffix") Condition - Error in `pal_add()`: + Error in `.pal_add()`: ! Suffixing not implemented yet. --- Code - pal_add(role = "sillyhead", prompt = "hey", interface = NULL) + .pal_add(role = "sillyhead", prompt = "hey", interface = NULL) Condition - Error in `pal_add()`: + Error in `.pal_add()`: ! `interface` should be one of "replace", "prefix", or "suffix". # pal remove with bad inputs Code - pal_remove(role = identity) + .pal_remove(role = identity) Condition - Error in `pal_remove()`: + Error in `.pal_remove()`: ! `role` must be a single string, not a function. --- Code - pal_remove(role = "notAnActivePal") + .pal_remove(role = "notAnActivePal") Condition - Error in `pal_remove()`: + Error in `.pal_remove()`: ! No active pal with the given `role`. diff --git a/tests/testthat/_snaps/pal-init.md b/tests/testthat/_snaps/pal-init.md index 5d751ef..1b316b0 100644 --- a/tests/testthat/_snaps/pal-init.md +++ b/tests/testthat/_snaps/pal-init.md @@ -53,5 +53,5 @@ Condition Error in `.pal_init()`: ! No pals with role `beep bop boop` registered. - i See `pal_add()`. + i See `.pal_add()`. diff --git a/tests/testthat/test-pal-add-remove.R b/tests/testthat/test-pal-add-remove.R index aabcdb9..26bf746 100644 --- a/tests/testthat/test-pal-add-remove.R +++ b/tests/testthat/test-pal-add-remove.R @@ -4,7 +4,7 @@ test_that("pal addition and removal works", { withr::local_options(.pal_fn = NULL, .pal_args = NULL) boop_prompt <- "just reply with beep bop boop regardless of input" - pal_add("boopery", boop_prompt) + .pal_add("boopery", boop_prompt) expect_equal(.pal_prompt_boopery, boop_prompt) expect_true(is_function(.pal_rs_boopery)) @@ -18,7 +18,7 @@ test_that("pal addition and removal works", { res <- pal_boopery$chat("hey there") expect_true(grepl("bop", res)) - pal_remove("boopery") + .pal_remove("boopery") expect_false(".pal_last_boopery" %in% names(pal_env())) expect_false(".pal_prompt_boopery" %in% names(pal_env())) @@ -28,7 +28,7 @@ test_that("pal addition and removal works", { test_that("pal addition with bad inputs", { expect_snapshot( error = TRUE, - pal_add(role = identity, prompt = "hey") + .pal_add(role = identity, prompt = "hey") ) # TODO: decide on `prompt` interface and test @@ -36,25 +36,25 @@ test_that("pal addition with bad inputs", { expect_snapshot( error = TRUE, - pal_add(role = "sillyhead", prompt = "hey", interface = "no") + .pal_add(role = "sillyhead", prompt = "hey", interface = "no") ) expect_snapshot( error = TRUE, - pal_add(role = "sillyhead", prompt = "hey", interface = "suffix") + .pal_add(role = "sillyhead", prompt = "hey", interface = "suffix") ) expect_snapshot( error = TRUE, - pal_add(role = "sillyhead", prompt = "hey", interface = NULL) + .pal_add(role = "sillyhead", prompt = "hey", interface = NULL) ) }) test_that("pal remove with bad inputs", { expect_snapshot( error = TRUE, - pal_remove(role = identity) + .pal_remove(role = identity) ) expect_snapshot( error = TRUE, - pal_remove(role = "notAnActivePal") + .pal_remove(role = "notAnActivePal") ) })