Skip to content

Commit 71edb4a

Browse files
authored
resolve coercion error from session (#32)
1 parent 58f16a5 commit 71edb4a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

R/session.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ handle_message_from_server <- function(msg) {
118118
)
119119

120120
# cat(paste(capture.output(str(body)), collapse="\n"), file=stderr())
121-
122121
} else {
123122
body <- jsonrpc_response(
124123
data$id,
@@ -136,6 +135,12 @@ handle_message_from_server <- function(msg) {
136135
}
137136

138137
as_tool_call_result <- function(data, result) {
138+
is_error <- FALSE
139+
if (inherits(result, "btw::BtwToolResult")) {
140+
is_error <- !is.null(result@error)
141+
result <- result@value %||% result@error
142+
}
143+
139144
jsonrpc_response(
140145
data$id,
141146
list(
@@ -145,7 +150,7 @@ as_tool_call_result <- function(data, result) {
145150
text = paste(result, collapse = "\n")
146151
)
147152
),
148-
isError = FALSE
153+
isError = is_error
149154
)
150155
)
151156
}

0 commit comments

Comments
 (0)