Skip to content

Commit

Permalink
Merge pull request #584 from posit-dev/feature/jep65-feature-flag
Browse files Browse the repository at this point in the history
Move protocol version to Amalthea and add feature flag
  • Loading branch information
lionel- authored Oct 15, 2024
2 parents fb210bf + 5c8c56d commit 738afba
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 16 deletions.
2 changes: 2 additions & 0 deletions crates/amalthea/src/socket/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::wire::jupyter_message::JupyterMessage;
use crate::wire::jupyter_message::Message;
use crate::wire::jupyter_message::ProtocolMessage;
use crate::wire::jupyter_message::Status;
use crate::wire::kernel_info_full_reply;
use crate::wire::originator::Originator;
use crate::wire::status::ExecutionState;
use crate::wire::status::KernelStatus;
Expand Down Expand Up @@ -128,6 +129,7 @@ impl Shell {
match msg {
Message::KernelInfoRequest(req) => self.handle_request(req.clone(), |msg| {
block_on(shell_handler.handle_info_request(msg))
.map(kernel_info_full_reply::KernelInfoReply::from)
}),
Message::IsCompleteRequest(req) => self.handle_request(req, |msg| {
block_on(shell_handler.handle_is_complete_request(msg))
Expand Down
2 changes: 1 addition & 1 deletion crates/amalthea/src/wire/jupyter_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use serde::Serialize;
use super::display_data::DisplayData;
use super::handshake_reply::HandshakeReply;
use super::handshake_request::HandshakeRequest;
use super::kernel_info_full_reply::KernelInfoReply;
use super::stream::StreamOutput;
use super::update_display_data::UpdateDisplayData;
use super::welcome::Welcome;
Expand Down Expand Up @@ -43,7 +44,6 @@ use crate::wire::interrupt_reply::InterruptReply;
use crate::wire::interrupt_request::InterruptRequest;
use crate::wire::is_complete_reply::IsCompleteReply;
use crate::wire::is_complete_request::IsCompleteRequest;
use crate::wire::kernel_info_reply::KernelInfoReply;
use crate::wire::kernel_info_request::KernelInfoRequest;
use crate::wire::originator::Originator;
use crate::wire::shutdown_request::ShutdownRequest;
Expand Down
69 changes: 69 additions & 0 deletions crates/amalthea/src/wire/kernel_info_full_reply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* kernel_info_full_reply.rs
*
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
*
*/

use serde::Deserialize;
use serde::Serialize;

use crate::wire::help_link::HelpLink;
use crate::wire::jupyter_message::MessageType;
use crate::wire::jupyter_message::Status;
use crate::wire::kernel_info_reply;
use crate::wire::language_info::LanguageInfo;

/// Complete version of `kernel_info_reply`
///
/// Private to Amalthea. Includes fields owned by Amalthea such as the protocol
/// version and feature flags.
///
/// Kernel authors should use [kernel_info_reply::KernelInfoReply] instead.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct KernelInfoReply {
/// Version of messaging protocol
pub protocol_version: String,

/// List of feature flags supported by the kernel. See JEP 92.
pub supported_features: Vec<String>,

/// The execution status ("ok" or "error")
pub status: Status,

/// Information about the language the kernel supports
pub language_info: LanguageInfo,

/// A startup banner
pub banner: String,

/// Whether debugging is supported
pub debugger: bool,

/// A list of help links
pub help_links: Vec<HelpLink>,
}

impl MessageType for KernelInfoReply {
fn message_type() -> String {
String::from("kernel_info_reply")
}
}

/// Adds Amalthea fields to partial [kernel_info_reply::KernelInfoReply].
impl From<kernel_info_reply::KernelInfoReply> for KernelInfoReply {
fn from(value: kernel_info_reply::KernelInfoReply) -> Self {
Self {
// These fields are set by Amalthea
protocol_version: String::from("5.4"),
supported_features: vec![String::from("iopub_welcome")],

// These fields are set by the Amalthea user
status: value.status,
language_info: value.language_info,
banner: value.banner,
debugger: value.debugger,
help_links: value.help_links,
}
}
}
17 changes: 5 additions & 12 deletions crates/amalthea/src/wire/kernel_info_reply.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/*
* kernel_info_reply.rs
*
* Copyright (C) 2022 Posit Software, PBC. All rights reserved.
* Copyright (C) 2022-2024 Posit Software, PBC. All rights reserved.
*
*/

use serde::Deserialize;
use serde::Serialize;

use crate::wire::help_link::HelpLink;
use crate::wire::jupyter_message::MessageType;
use crate::wire::jupyter_message::Status;
use crate::wire::language_info::LanguageInfo;

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

/// Version of messaging protocol
pub protocol_version: String,

/// Information about the language the kernel supports
pub language_info: LanguageInfo,

Expand All @@ -34,9 +33,3 @@ pub struct KernelInfoReply {
/// A list of help links
pub help_links: Vec<HelpLink>,
}

impl MessageType for KernelInfoReply {
fn message_type() -> String {
String::from("kernel_info_reply")
}
}
1 change: 1 addition & 0 deletions crates/amalthea/src/wire/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod interrupt_request;
pub mod is_complete_reply;
pub mod is_complete_request;
pub mod jupyter_message;
pub mod kernel_info_full_reply;
pub mod kernel_info_reply;
pub mod kernel_info_request;
pub mod language_info;
Expand Down
2 changes: 2 additions & 0 deletions crates/amalthea/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ fn test_amalthea_kernel_info() {
frontend.recv_shell(),
Message::KernelInfoReply(reply) => {
assert_eq!(reply.content.language_info.name, "Test");
assert_eq!(reply.content.protocol_version, "5.4");
assert!(reply.content.supported_features.contains(&String::from("iopub_welcome")));
}
);

Expand Down
1 change: 0 additions & 1 deletion crates/amalthea/tests/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl ShellHandler for Shell {
status: Status::Ok,
banner: format!("Amalthea Echo {}", env!("CARGO_PKG_VERSION")),
debugger: false,
protocol_version: String::from("5.0"),
help_links: Vec::new(),
language_info: info,
})
Expand Down
1 change: 0 additions & 1 deletion crates/ark/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ impl ShellHandler for Shell {
status: Status::Ok,
banner: kernel_info.banner.clone(),
debugger: false,
protocol_version: String::from("5.3"),
help_links: Vec::new(),
language_info: info,
})
Expand Down
1 change: 0 additions & 1 deletion crates/echo/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl ShellHandler for Shell {
status: Status::Ok,
banner: format!("Amalthea Echo {}", env!("CARGO_PKG_VERSION")),
debugger: false,
protocol_version: String::from("5.0"),
help_links: Vec::new(),
language_info: info,
})
Expand Down

0 comments on commit 738afba

Please sign in to comment.