Skip to content

Commit 738afba

Browse files
authored
Merge pull request #584 from posit-dev/feature/jep65-feature-flag
Move protocol version to Amalthea and add feature flag
2 parents fb210bf + 5c8c56d commit 738afba

File tree

9 files changed

+80
-16
lines changed

9 files changed

+80
-16
lines changed

crates/amalthea/src/socket/shell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::wire::jupyter_message::JupyterMessage;
4242
use crate::wire::jupyter_message::Message;
4343
use crate::wire::jupyter_message::ProtocolMessage;
4444
use crate::wire::jupyter_message::Status;
45+
use crate::wire::kernel_info_full_reply;
4546
use crate::wire::originator::Originator;
4647
use crate::wire::status::ExecutionState;
4748
use crate::wire::status::KernelStatus;
@@ -128,6 +129,7 @@ impl Shell {
128129
match msg {
129130
Message::KernelInfoRequest(req) => self.handle_request(req.clone(), |msg| {
130131
block_on(shell_handler.handle_info_request(msg))
132+
.map(kernel_info_full_reply::KernelInfoReply::from)
131133
}),
132134
Message::IsCompleteRequest(req) => self.handle_request(req, |msg| {
133135
block_on(shell_handler.handle_is_complete_request(msg))

crates/amalthea/src/wire/jupyter_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use serde::Serialize;
1111
use super::display_data::DisplayData;
1212
use super::handshake_reply::HandshakeReply;
1313
use super::handshake_request::HandshakeRequest;
14+
use super::kernel_info_full_reply::KernelInfoReply;
1415
use super::stream::StreamOutput;
1516
use super::update_display_data::UpdateDisplayData;
1617
use super::welcome::Welcome;
@@ -43,7 +44,6 @@ use crate::wire::interrupt_reply::InterruptReply;
4344
use crate::wire::interrupt_request::InterruptRequest;
4445
use crate::wire::is_complete_reply::IsCompleteReply;
4546
use crate::wire::is_complete_request::IsCompleteRequest;
46-
use crate::wire::kernel_info_reply::KernelInfoReply;
4747
use crate::wire::kernel_info_request::KernelInfoRequest;
4848
use crate::wire::originator::Originator;
4949
use crate::wire::shutdown_request::ShutdownRequest;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* kernel_info_full_reply.rs
3+
*
4+
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
5+
*
6+
*/
7+
8+
use serde::Deserialize;
9+
use serde::Serialize;
10+
11+
use crate::wire::help_link::HelpLink;
12+
use crate::wire::jupyter_message::MessageType;
13+
use crate::wire::jupyter_message::Status;
14+
use crate::wire::kernel_info_reply;
15+
use crate::wire::language_info::LanguageInfo;
16+
17+
/// Complete version of `kernel_info_reply`
18+
///
19+
/// Private to Amalthea. Includes fields owned by Amalthea such as the protocol
20+
/// version and feature flags.
21+
///
22+
/// Kernel authors should use [kernel_info_reply::KernelInfoReply] instead.
23+
#[derive(Debug, Serialize, Deserialize, Clone)]
24+
pub struct KernelInfoReply {
25+
/// Version of messaging protocol
26+
pub protocol_version: String,
27+
28+
/// List of feature flags supported by the kernel. See JEP 92.
29+
pub supported_features: Vec<String>,
30+
31+
/// The execution status ("ok" or "error")
32+
pub status: Status,
33+
34+
/// Information about the language the kernel supports
35+
pub language_info: LanguageInfo,
36+
37+
/// A startup banner
38+
pub banner: String,
39+
40+
/// Whether debugging is supported
41+
pub debugger: bool,
42+
43+
/// A list of help links
44+
pub help_links: Vec<HelpLink>,
45+
}
46+
47+
impl MessageType for KernelInfoReply {
48+
fn message_type() -> String {
49+
String::from("kernel_info_reply")
50+
}
51+
}
52+
53+
/// Adds Amalthea fields to partial [kernel_info_reply::KernelInfoReply].
54+
impl From<kernel_info_reply::KernelInfoReply> for KernelInfoReply {
55+
fn from(value: kernel_info_reply::KernelInfoReply) -> Self {
56+
Self {
57+
// These fields are set by Amalthea
58+
protocol_version: String::from("5.4"),
59+
supported_features: vec![String::from("iopub_welcome")],
60+
61+
// These fields are set by the Amalthea user
62+
status: value.status,
63+
language_info: value.language_info,
64+
banner: value.banner,
65+
debugger: value.debugger,
66+
help_links: value.help_links,
67+
}
68+
}
69+
}
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
/*
22
* kernel_info_reply.rs
33
*
4-
* Copyright (C) 2022 Posit Software, PBC. All rights reserved.
4+
* Copyright (C) 2022-2024 Posit Software, PBC. All rights reserved.
55
*
66
*/
77

88
use serde::Deserialize;
99
use serde::Serialize;
1010

1111
use crate::wire::help_link::HelpLink;
12-
use crate::wire::jupyter_message::MessageType;
1312
use crate::wire::jupyter_message::Status;
1413
use crate::wire::language_info::LanguageInfo;
1514

16-
/// Represents a reply to a kernel_info_request
15+
/// Represents a reply to a `kernel_info_request`
16+
///
17+
/// When implementing a kernel, use this struct. Amalthea is in charge of
18+
/// providing the `protocol_version` to complete the reply.
1719
#[derive(Debug, Serialize, Deserialize, Clone)]
1820
pub struct KernelInfoReply {
1921
/// The execution status ("ok" or "error")
2022
pub status: Status,
2123

22-
/// Version of messaging protocol
23-
pub protocol_version: String,
24-
2524
/// Information about the language the kernel supports
2625
pub language_info: LanguageInfo,
2726

@@ -34,9 +33,3 @@ pub struct KernelInfoReply {
3433
/// A list of help links
3534
pub help_links: Vec<HelpLink>,
3635
}
37-
38-
impl MessageType for KernelInfoReply {
39-
fn message_type() -> String {
40-
String::from("kernel_info_reply")
41-
}
42-
}

crates/amalthea/src/wire/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod interrupt_request;
3434
pub mod is_complete_reply;
3535
pub mod is_complete_request;
3636
pub mod jupyter_message;
37+
pub mod kernel_info_full_reply;
3738
pub mod kernel_info_reply;
3839
pub mod kernel_info_request;
3940
pub mod language_info;

crates/amalthea/tests/client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ fn test_amalthea_kernel_info() {
3838
frontend.recv_shell(),
3939
Message::KernelInfoReply(reply) => {
4040
assert_eq!(reply.content.language_info.name, "Test");
41+
assert_eq!(reply.content.protocol_version, "5.4");
42+
assert!(reply.content.supported_features.contains(&String::from("iopub_welcome")));
4143
}
4244
);
4345

crates/amalthea/tests/shell/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ impl ShellHandler for Shell {
102102
status: Status::Ok,
103103
banner: format!("Amalthea Echo {}", env!("CARGO_PKG_VERSION")),
104104
debugger: false,
105-
protocol_version: String::from("5.0"),
106105
help_links: Vec::new(),
107106
language_info: info,
108107
})

crates/ark/src/shell.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ impl ShellHandler for Shell {
168168
status: Status::Ok,
169169
banner: kernel_info.banner.clone(),
170170
debugger: false,
171-
protocol_version: String::from("5.3"),
172171
help_links: Vec::new(),
173172
language_info: info,
174173
})

crates/echo/src/shell.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ impl ShellHandler for Shell {
7777
status: Status::Ok,
7878
banner: format!("Amalthea Echo {}", env!("CARGO_PKG_VERSION")),
7979
debugger: false,
80-
protocol_version: String::from("5.0"),
8180
help_links: Vec::new(),
8281
language_info: info,
8382
})

0 commit comments

Comments
 (0)