Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions pkg-r/R/chat.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Shiny chat UI and server for commons agents
#'
#' These functions wrap [shinychat::chat_app()], [shinychat::chat_ui()], and
#' These functions wrap [shinychat::page_chat()], [shinychat::chat_ui()], and
#' [shinychat::chat_server()] for commons agents. The server verifies each
#' `<commons-citation>` the model writes against its own context, measure
#' definitions, and data documentation as the answer streams, and rewrites
Expand Down Expand Up @@ -54,21 +54,24 @@ commons_app <- function(client, ...) {
check_commons_client(client)

ui <- function(req) {
bslib::page_fillable(
commons_ui(
"chat",
height = "100%",
with_commons_chat_assets(
shinychat::page_chat(
"commons",
id = "chat",
enable_cancel = TRUE,
allow_attachments = TRUE
),
if (rlang::is_interactive()) {
shiny::actionButton(
"close_btn",
label = "",
class = "btn-close",
style = "position: fixed; top: 6px; right: 6px;"
allow_attachments = TRUE,
toolbar_global = bslib::toolbar(
bslib::input_dark_mode(),
if (rlang::is_interactive()) {
shiny::actionButton(
"close_btn",
label = "",
class = "btn-close",
`aria-label` = "Close"
)
}
)
}
)
)
}

Expand All @@ -89,9 +92,7 @@ commons_app <- function(client, ...) {
#' @export
commons_ui <- function(id, ...) {
check_chat_packages()
register_commons_icon_resources()
ui <- shinychat::chat_ui(id, icon_assistant = htmltools::HTML(""), ...)
htmltools::attachDependencies(ui, commons_chat_dependency(), append = TRUE)
with_commons_chat_assets(shinychat::chat_ui(id, ...))
}

#' @rdname commons_app
Expand Down Expand Up @@ -172,6 +173,11 @@ register_commons_icon_resources <- function() {
)
}

with_commons_chat_assets <- function(ui) {
register_commons_icon_resources()
htmltools::attachDependencies(ui, commons_chat_dependency(), append = TRUE)
}

# Asset mtimes ride in the version so the dependency URL changes whenever
# the files do; browsers otherwise cache edited assets under the stable
# version's URL indefinitely.
Expand Down
Loading
Loading