Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Imports:
cli,
ellmer,
jsonlite,
nanonext (>= 1.5.2.9016),
nanonext (>= 1.5.2.9019),
promises,
rlang
Depends: R (>= 4.1.0)
Expand Down
9 changes: 9 additions & 0 deletions R/acquaint-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
#' @import rlang
## usethis namespace: end
NULL

.onLoad <- function(libname, pkgname) {
acquaint_socket <<- switch(
Sys.info()[["sysname"]],
Linux = "abstract://acquaint-socket",
Windows = "ipc://acquaint-socket",
"ipc:///tmp/acquaint-socket"
)
}
21 changes: 10 additions & 11 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ mcp_session <- function() {

the$session_socket <- nanonext::socket("poly")
i <- 1L
suppressWarnings(
while (i < 1024L) {
# prevent indefinite loop
nanonext::listen(
the$session_socket,
url = sprintf("%s%d", acquaint_socket, i)
) ||
break
i <- i + 1L
}
)
while (i < 1024L) {
# prevent indefinite loop
nanonext::listen(
the$session_socket,
url = sprintf("%s%d", acquaint_socket, i),
fail = "none"
) ||
break
i <- i + 1L
}
the$session <- i

schedule_handle_message_from_server()
Expand Down
35 changes: 17 additions & 18 deletions R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ list_r_sessions <- function() {
on.exit(nanonext::reap(sock))
cv <- nanonext::cv()
monitor <- nanonext::monitor(sock, cv)
suppressWarnings(
for (i in seq_len(1024L)) {
if (
nanonext::dial(
sock,
url = sprintf("%s%d", acquaint_socket, i),
autostart = NA
) &&
i > 8L
)
break
}
)
for (i in seq_len(1024L)) {
if (
nanonext::dial(
sock,
url = sprintf("%s%d", acquaint_socket, i),
autostart = NA,
fail = "none"
) &&
i > 8L
)
break
}
pipes <- nanonext::read_monitor(monitor)
res <- lapply(
pipes,
function(x) nanonext::recv_aio(sock, mode = "string")
function(x) nanonext::recv_aio(sock, mode = "string", timeout = 5000L)
)
lapply(
pipes,
Expand All @@ -47,14 +46,14 @@ list_r_sessions_tool <-
)
)

select_r_session <- function(i) {
select_r_session <- function(session) {
nanonext::reap(the$server_socket[["dialer"]][[1L]])
attr(the$server_socket, "dialer") <- NULL
nanonext::dial(
the$server_socket,
url = sprintf("%s%d", acquaint_socket, as.integer(i))
url = sprintf("%s%d", acquaint_socket, session)
)
paste0("Selected session ", i, " successfully.")
sprintf("Selected session %d successfully.", session)
}

select_r_session_tool <-
Expand All @@ -72,7 +71,7 @@ select_r_session_tool <-
"Your choice of session will persist after the tool is called; only",
"call this tool more than once if you need to switch between sessions."
),
i = ellmer::type_integer("The index of the R session to select.")
session = ellmer::type_integer("The R session number to select.")
)

get_acquaint_tools <- function() {
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
the <- new_environment()

acquaint_socket <- "ipc:///tmp/acquaint-socket"
acquaint_socket <- NULL

jsonrpc_response <- function(id, result = NULL, error = NULL) {
if (!xor(is.null(result), is.null(error))) {
Expand Down