From 69404694251f12ddc58a84e39901d8e51b15bf59 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 2 Oct 2025 16:53:48 -0400 Subject: [PATCH 1/3] feat(chat_mod_server): Add `$append()` function --- pkg-r/R/chat_app.R | 8 ++++++++ pkg-r/man/chat_app.Rd | 3 +++ 2 files changed, 11 insertions(+) diff --git a/pkg-r/R/chat_app.R b/pkg-r/R/chat_app.R index 552df10..dd24daa 100644 --- a/pkg-r/R/chat_app.R +++ b/pkg-r/R/chat_app.R @@ -81,6 +81,9 @@ #' * `update_user_input()`: A function to update the chat input or submit a #' new user input. Takes the same arguments as [update_chat_user_input()], #' except for `id` and `session`, which are supplied automatically. +#' * `append()`: A function to append a new message to the chat UI. Takes +#' the same arguments as [chat_append()], except for `id` and `session`, +#' which are supplied automatically. #' * `clear()`: A function to clear the chat history and the chat UI. #' `clear()` takes an optional list of `messages` used to initialize the #' chat after clearing. `messages` should be a list of messages, where @@ -224,6 +227,10 @@ chat_mod_server <- function( ) } + chat_append_mod <- function(response, role = "assistant", icon = NULL) { + chat_append("chat", response, role = role, icon = icon, session = session) + } + client_clear <- function( messages = NULL, client_history = c("clear", "set", "append", "keep") @@ -271,6 +278,7 @@ chat_mod_server <- function( last_turn = shiny::reactive(last_turn()), last_input = shiny::reactive(last_input()), client = client, + append = chat_append_mod, update_user_input = chat_update_user_input, clear = client_clear ) diff --git a/pkg-r/man/chat_app.Rd b/pkg-r/man/chat_app.Rd index 923eb8a..49b51bf 100644 --- a/pkg-r/man/chat_app.Rd +++ b/pkg-r/man/chat_app.Rd @@ -55,6 +55,9 @@ and a list with: \item \code{update_user_input()}: A function to update the chat input or submit a new user input. Takes the same arguments as \code{\link[=update_chat_user_input]{update_chat_user_input()}}, except for \code{id} and \code{session}, which are supplied automatically. +\item \code{append()}: A function to append a new message to the chat UI. Takes +the same arguments as \code{\link[=chat_append]{chat_append()}}, except for \code{id} and \code{session}, +which are supplied automatically. \item \code{clear()}: A function to clear the chat history and the chat UI. \code{clear()} takes an optional list of \code{messages} used to initialize the chat after clearing. \code{messages} should be a list of messages, where From 367324bf4516025bde78040e7d62458cf9cef5f4 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 2 Oct 2025 17:09:15 -0400 Subject: [PATCH 2/3] chore: update NEWS --- pkg-r/NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg-r/NEWS.md b/pkg-r/NEWS.md index 2f07280..596231a 100644 --- a/pkg-r/NEWS.md +++ b/pkg-r/NEWS.md @@ -10,7 +10,7 @@ * Added `chat_append(icon=...)` and `chat_ui(icon_assistant=...)` for customizing the icon that appears next to assistant responses. (#88) -* `chat_mod_server()` now returns a list of reactives for `last_input` and `last_turn`, as well and functions to `update_user_input()` and `clear()` the chat. (#130) +* `chat_mod_server()` now returns a list of reactives for `last_input` and `last_turn`, as well functions to `update_user_input()`, `append()` and `clear()` the chat. (#130, #143, #145) ## Improvements From a3dc95970830011b4b5f3e51054142fc5e484c62 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 2 Oct 2025 17:11:12 -0400 Subject: [PATCH 3/3] docs: fix typos --- pkg-r/R/chat_app.R | 2 +- pkg-r/man/chat_app.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg-r/R/chat_app.R b/pkg-r/R/chat_app.R index dd24daa..e23d6b9 100644 --- a/pkg-r/R/chat_app.R +++ b/pkg-r/R/chat_app.R @@ -74,7 +74,7 @@ #' * `chat_app()` returns a [shiny::shinyApp()] object. #' * `chat_mod_ui()` returns the UI for a shinychat module. #' * `chat_mod_server()` includes the shinychat module server logic, and -#' and a list with: +#' returns a list containing: #' #' * `last_input`: A reactive value containing the last user input. #' * `last_turn`: A reactive value containing the last assistant turn. diff --git a/pkg-r/man/chat_app.Rd b/pkg-r/man/chat_app.Rd index 49b51bf..468b522 100644 --- a/pkg-r/man/chat_app.Rd +++ b/pkg-r/man/chat_app.Rd @@ -48,7 +48,7 @@ in \code{\link[=chat_ui]{chat_ui()}}.} \item \code{chat_app()} returns a \code{\link[shiny:shinyApp]{shiny::shinyApp()}} object. \item \code{chat_mod_ui()} returns the UI for a shinychat module. \item \code{chat_mod_server()} includes the shinychat module server logic, and -and a list with: +returns a list containing: \itemize{ \item \code{last_input}: A reactive value containing the last user input. \item \code{last_turn}: A reactive value containing the last assistant turn.