mirror of
https://github.com/openai/codex.git
synced 2026-11-22 07:13:50 +00:00
Support Codex Apps auth elicitations (#19193)
## Summary - request URL-mode MCP elicitations when Codex Apps tool calls fail with connector auth metadata - route Codex Apps auth URL elicitations into the TUI app-link flow ## Test plan - `just fmt` - `cargo test -p codex-core mcp_tool_call::tests` - `cargo test -p codex-mcp` - `cargo test -p codex-tui bottom_pane::app_link_view::tests` - `just fix -p codex-core` - `just fix -p codex-mcp` - `just fix -p codex-tui` Also attempted broader local runs: - `cargo test -p codex-core` fails in unrelated config/request-permission/proxy-sensitive tests under the current Codex Desktop environment. - `cargo test -p codex-tui` fails in unrelated status snapshots/trust-default tests because the ambient environment renders workspace-write/network permission defaults.
This commit is contained in:
1 parent
22326e263c
commit
f9a907aebe
25 files changed
+1748
-78
No files matched your search
@@ -17,6 +17,7 @@ use ratatui::widgets::Paragraph;
|
||||
use ratatui::widgets::Widget;
|
||||
use ratatui::widgets::Wrap;
|
||||
use textwrap::wrap;
|
||||
use url::Url;
|
||||
|
||||
use super::CancellationEvent;
|
||||
use super::bottom_pane_view::BottomPaneView;
|
||||
@@ -34,6 +35,13 @@ use crate::style::user_message_style;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::adaptive_wrap_lines;
|
||||
|
||||
const MCP_CODEX_APPS_SERVER_NAME: &str = "codex_apps";
|
||||
const MCP_TOOL_CODEX_APPS_META_KEY: &str = "_codex_apps";
|
||||
const CONNECTOR_AUTH_FAILURE_META_KEY: &str = "connector_auth_failure";
|
||||
const CONNECTOR_AUTH_FAILURE_IS_AUTH_FAILURE_KEY: &str = "is_auth_failure";
|
||||
const CONNECTOR_AUTH_FAILURE_CONNECTOR_ID_KEY: &str = "connector_id";
|
||||
const CONNECTOR_AUTH_FAILURE_CONNECTOR_NAME_KEY: &str = "connector_name";
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum AppLinkScreen {
|
||||
Link,
|
||||
@@ -44,6 +52,8 @@ enum AppLinkScreen {
|
||||
pub(crate) enum AppLinkSuggestionType {
|
||||
Install,
|
||||
Enable,
|
||||
Auth,
|
||||
ExternalAction,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -53,6 +63,7 @@ pub(crate) struct AppLinkElicitationTarget {
|
||||
pub(crate) request_id: AppServerRequestId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct AppLinkViewParams {
|
||||
pub(crate) app_id: String,
|
||||
pub(crate) title: String,
|
||||
@@ -66,6 +77,152 @@ pub(crate) struct AppLinkViewParams {
|
||||
pub(crate) elicitation_target: Option<AppLinkElicitationTarget>,
|
||||
}
|
||||
|
||||
impl AppLinkViewParams {
|
||||
pub(crate) fn from_url_app_server_request(
|
||||
thread_id: ThreadId,
|
||||
server_name: &str,
|
||||
request_id: AppServerRequestId,
|
||||
request: &codex_app_server_protocol::McpServerElicitationRequest,
|
||||
) -> Option<Self> {
|
||||
let codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta,
|
||||
message,
|
||||
url,
|
||||
elicitation_id,
|
||||
} = request
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
if server_name == MCP_CODEX_APPS_SERVER_NAME {
|
||||
let url = validate_external_url(url, /*require_chatgpt_host*/ true)?;
|
||||
return Self::from_codex_apps_auth_url_parts(
|
||||
thread_id,
|
||||
server_name,
|
||||
request_id,
|
||||
meta.as_ref(),
|
||||
message,
|
||||
url.as_str(),
|
||||
elicitation_id,
|
||||
);
|
||||
}
|
||||
|
||||
let url = validate_external_url(url, /*require_chatgpt_host*/ false)?;
|
||||
Some(Self::from_generic_url_parts(
|
||||
thread_id,
|
||||
server_name,
|
||||
request_id,
|
||||
message,
|
||||
url.as_str(),
|
||||
elicitation_id,
|
||||
))
|
||||
}
|
||||
|
||||
fn from_codex_apps_auth_url_parts(
|
||||
thread_id: ThreadId,
|
||||
server_name: &str,
|
||||
request_id: AppServerRequestId,
|
||||
meta: Option<&serde_json::Value>,
|
||||
message: &str,
|
||||
url: &str,
|
||||
elicitation_id: &str,
|
||||
) -> Option<Self> {
|
||||
let auth_failure = meta?
|
||||
.as_object()?
|
||||
.get(MCP_TOOL_CODEX_APPS_META_KEY)?
|
||||
.as_object()?
|
||||
.get(CONNECTOR_AUTH_FAILURE_META_KEY)?
|
||||
.as_object()?;
|
||||
if auth_failure
|
||||
.get(CONNECTOR_AUTH_FAILURE_IS_AUTH_FAILURE_KEY)
|
||||
.and_then(serde_json::Value::as_bool)
|
||||
!= Some(true)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let app_id = auth_failure
|
||||
.get(CONNECTOR_AUTH_FAILURE_CONNECTOR_ID_KEY)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.unwrap_or(elicitation_id)
|
||||
.to_string();
|
||||
let title = auth_failure
|
||||
.get(CONNECTOR_AUTH_FAILURE_CONNECTOR_NAME_KEY)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.unwrap_or(app_id.as_str())
|
||||
.to_string();
|
||||
|
||||
Some(Self {
|
||||
app_id,
|
||||
title,
|
||||
description: None,
|
||||
instructions: "Sign in to this app in your browser, then return here.".to_string(),
|
||||
url: url.to_string(),
|
||||
is_installed: true,
|
||||
is_enabled: true,
|
||||
suggest_reason: Some(message.to_string()),
|
||||
suggestion_type: Some(AppLinkSuggestionType::Auth),
|
||||
elicitation_target: Some(AppLinkElicitationTarget {
|
||||
thread_id,
|
||||
server_name: server_name.to_string(),
|
||||
request_id,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
fn from_generic_url_parts(
|
||||
thread_id: ThreadId,
|
||||
server_name: &str,
|
||||
request_id: AppServerRequestId,
|
||||
message: &str,
|
||||
url: &str,
|
||||
elicitation_id: &str,
|
||||
) -> Self {
|
||||
Self {
|
||||
app_id: elicitation_id.to_string(),
|
||||
title: "Action required".to_string(),
|
||||
description: Some(format!("Server: {server_name}")),
|
||||
instructions: "Complete the requested action in your browser, then return here."
|
||||
.to_string(),
|
||||
url: url.to_string(),
|
||||
is_installed: true,
|
||||
is_enabled: true,
|
||||
suggest_reason: Some(message.to_string()),
|
||||
suggestion_type: Some(AppLinkSuggestionType::ExternalAction),
|
||||
elicitation_target: Some(AppLinkElicitationTarget {
|
||||
thread_id,
|
||||
server_name: server_name.to_string(),
|
||||
request_id,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_external_url(url: &str, require_chatgpt_host: bool) -> Option<Url> {
|
||||
let parsed = Url::parse(url).ok()?;
|
||||
if parsed.scheme() != "https" || parsed.host_str().is_none() {
|
||||
return None;
|
||||
}
|
||||
if !parsed.username().is_empty() || parsed.password().is_some() {
|
||||
return None;
|
||||
}
|
||||
if require_chatgpt_host && !is_allowed_chatgpt_auth_host(parsed.host_str()?) {
|
||||
return None;
|
||||
}
|
||||
Some(parsed)
|
||||
}
|
||||
|
||||
fn is_allowed_chatgpt_auth_host(host: &str) -> bool {
|
||||
let host = host.to_ascii_lowercase();
|
||||
host == "chatgpt.com"
|
||||
|| host == "chatgpt-staging.com"
|
||||
|| host.ends_with(".chatgpt.com")
|
||||
|| host.ends_with(".chatgpt-staging.com")
|
||||
}
|
||||
|
||||
pub(crate) struct AppLinkView {
|
||||
app_id: String,
|
||||
title: String,
|
||||
@@ -116,6 +273,19 @@ impl AppLinkView {
|
||||
}
|
||||
|
||||
fn action_labels(&self) -> Vec<&'static str> {
|
||||
if self.is_auth_suggestion() {
|
||||
return match self.screen {
|
||||
AppLinkScreen::Link => vec!["Open sign-in URL", "Back"],
|
||||
AppLinkScreen::InstallConfirmation => vec!["I already signed in", "Back"],
|
||||
};
|
||||
}
|
||||
if self.is_external_action_suggestion() {
|
||||
return match self.screen {
|
||||
AppLinkScreen::Link => vec!["Open link", "Back"],
|
||||
AppLinkScreen::InstallConfirmation => vec!["I finished", "Back"],
|
||||
};
|
||||
}
|
||||
|
||||
match self.screen {
|
||||
AppLinkScreen::Link => {
|
||||
if self.is_installed {
|
||||
@@ -148,6 +318,19 @@ impl AppLinkView {
|
||||
self.elicitation_target.is_some()
|
||||
}
|
||||
|
||||
fn is_auth_suggestion(&self) -> bool {
|
||||
self.is_tool_suggestion() && self.suggestion_type == Some(AppLinkSuggestionType::Auth)
|
||||
}
|
||||
|
||||
fn is_external_action_suggestion(&self) -> bool {
|
||||
self.is_tool_suggestion()
|
||||
&& self.suggestion_type == Some(AppLinkSuggestionType::ExternalAction)
|
||||
}
|
||||
|
||||
fn is_browser_action_suggestion(&self) -> bool {
|
||||
self.is_auth_suggestion() || self.is_external_action_suggestion()
|
||||
}
|
||||
|
||||
fn resolve_elicitation(&self, decision: McpServerElicitationAction) {
|
||||
let Some(target) = self.elicitation_target.as_ref() else {
|
||||
return;
|
||||
@@ -167,20 +350,26 @@ impl AppLinkView {
|
||||
self.complete = true;
|
||||
}
|
||||
|
||||
fn open_chatgpt_link(&mut self) {
|
||||
fn open_external_url(&mut self) {
|
||||
self.app_event_tx.send(AppEvent::OpenUrlInBrowser {
|
||||
url: self.url.clone(),
|
||||
});
|
||||
if !self.is_installed {
|
||||
if !self.is_installed || self.is_browser_action_suggestion() {
|
||||
self.screen = AppLinkScreen::InstallConfirmation;
|
||||
self.selected_action = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_connectors_and_close(&mut self) {
|
||||
self.app_event_tx.send(AppEvent::RefreshConnectors {
|
||||
force_refetch: true,
|
||||
});
|
||||
fn complete_external_flow_and_close(&mut self) {
|
||||
let should_refresh_connectors = self
|
||||
.elicitation_target
|
||||
.as_ref()
|
||||
.is_none_or(|target| target.server_name == MCP_CODEX_APPS_SERVER_NAME);
|
||||
if should_refresh_connectors {
|
||||
self.app_event_tx.send(AppEvent::RefreshConnectors {
|
||||
force_refetch: true,
|
||||
});
|
||||
}
|
||||
if self.is_tool_suggestion() {
|
||||
self.resolve_elicitation(McpServerElicitationAction::Accept);
|
||||
}
|
||||
@@ -209,22 +398,42 @@ impl AppLinkView {
|
||||
match self.suggestion_type {
|
||||
Some(AppLinkSuggestionType::Enable) => match self.screen {
|
||||
AppLinkScreen::Link => match self.selected_action {
|
||||
0 => self.open_chatgpt_link(),
|
||||
0 => self.open_external_url(),
|
||||
1 if self.is_installed => self.toggle_enabled(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
AppLinkScreen::InstallConfirmation => match self.selected_action {
|
||||
0 => self.refresh_connectors_and_close(),
|
||||
0 => self.complete_external_flow_and_close(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
},
|
||||
Some(AppLinkSuggestionType::Auth) => match self.screen {
|
||||
AppLinkScreen::Link => match self.selected_action {
|
||||
0 => self.open_external_url(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
AppLinkScreen::InstallConfirmation => match self.selected_action {
|
||||
0 => self.complete_external_flow_and_close(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
},
|
||||
Some(AppLinkSuggestionType::ExternalAction) => match self.screen {
|
||||
AppLinkScreen::Link => match self.selected_action {
|
||||
0 => self.open_external_url(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
AppLinkScreen::InstallConfirmation => match self.selected_action {
|
||||
0 => self.complete_external_flow_and_close(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
},
|
||||
Some(AppLinkSuggestionType::Install) | None => match self.screen {
|
||||
AppLinkScreen::Link => match self.selected_action {
|
||||
0 => self.open_chatgpt_link(),
|
||||
0 => self.open_external_url(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
AppLinkScreen::InstallConfirmation => match self.selected_action {
|
||||
0 => self.refresh_connectors_and_close(),
|
||||
0 => self.complete_external_flow_and_close(),
|
||||
_ => self.decline_tool_suggestion(),
|
||||
},
|
||||
},
|
||||
@@ -234,12 +443,12 @@ impl AppLinkView {
|
||||
|
||||
match self.screen {
|
||||
AppLinkScreen::Link => match self.selected_action {
|
||||
0 => self.open_chatgpt_link(),
|
||||
0 => self.open_external_url(),
|
||||
1 if self.is_installed => self.toggle_enabled(),
|
||||
_ => self.complete = true,
|
||||
},
|
||||
AppLinkScreen::InstallConfirmation => match self.selected_action {
|
||||
0 => self.refresh_connectors_and_close(),
|
||||
0 => self.complete_external_flow_and_close(),
|
||||
_ => self.back_to_link_screen(),
|
||||
},
|
||||
}
|
||||
@@ -280,31 +489,42 @@ impl AppLinkView {
|
||||
}
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
if self.is_installed {
|
||||
let is_browser_action_suggestion = self.is_browser_action_suggestion();
|
||||
if self.is_installed && !is_browser_action_suggestion {
|
||||
for line in wrap("Use $ to insert this app into the prompt.", usable_width) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
|
||||
if is_browser_action_suggestion {
|
||||
lines.push(Line::from("URL".dim()));
|
||||
for line in wrap(&self.url, usable_width) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
|
||||
let instructions = self.instructions.trim();
|
||||
if !instructions.is_empty() {
|
||||
for line in wrap(instructions, usable_width) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
for line in wrap(
|
||||
"Newly installed apps can take a few minutes to appear in /apps.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
if !self.is_installed {
|
||||
if !is_browser_action_suggestion {
|
||||
for line in wrap(
|
||||
"After installed, use $ to insert this app into the prompt.",
|
||||
"Newly installed apps can take a few minutes to appear in /apps.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
if !self.is_installed {
|
||||
for line in wrap(
|
||||
"After installed, use $ to insert this app into the prompt.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
@@ -316,24 +536,82 @@ impl AppLinkView {
|
||||
let usable_width = width.max(1) as usize;
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
|
||||
lines.push(Line::from("Finish App Setup".bold()));
|
||||
let is_auth_suggestion = self.is_auth_suggestion();
|
||||
let is_external_action_suggestion = self.is_external_action_suggestion();
|
||||
let is_codex_apps_auth = is_auth_suggestion
|
||||
&& self
|
||||
.elicitation_target
|
||||
.as_ref()
|
||||
.is_some_and(|target| target.server_name == MCP_CODEX_APPS_SERVER_NAME);
|
||||
lines.push(Line::from(
|
||||
if is_auth_suggestion {
|
||||
if is_codex_apps_auth {
|
||||
"Finish App Sign In"
|
||||
} else {
|
||||
"Finish Authentication"
|
||||
}
|
||||
} else if is_external_action_suggestion {
|
||||
"Finish in Browser"
|
||||
} else {
|
||||
"Finish App Setup"
|
||||
}
|
||||
.bold(),
|
||||
));
|
||||
lines.push(Line::from(""));
|
||||
|
||||
for line in wrap(
|
||||
"Complete app setup on ChatGPT in the browser window that just opened.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
for line in wrap(
|
||||
"Sign in there if needed, then return here and select \"I already Installed it\".",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
if is_auth_suggestion {
|
||||
for line in wrap(
|
||||
if is_codex_apps_auth {
|
||||
"Sign in to the app on ChatGPT in the browser window that just opened."
|
||||
} else {
|
||||
"Complete authentication in the browser window that just opened."
|
||||
},
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
for line in wrap(
|
||||
"Then return here and select \"I already signed in\".",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
} else if is_external_action_suggestion {
|
||||
for line in wrap(
|
||||
"Complete the requested action in the browser window that just opened.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
for line in wrap("Then return here and select \"I finished\".", usable_width) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
} else {
|
||||
for line in wrap(
|
||||
"Complete app setup on ChatGPT in the browser window that just opened.",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
for line in wrap(
|
||||
"Sign in there if needed, then return here and select \"I already Installed it\".",
|
||||
usable_width,
|
||||
) {
|
||||
lines.push(Line::from(line.into_owned()));
|
||||
}
|
||||
}
|
||||
|
||||
lines.push(Line::from(""));
|
||||
lines.push(Line::from(vec!["Setup URL:".dim()]));
|
||||
lines.push(Line::from(vec![
|
||||
if is_auth_suggestion {
|
||||
"Sign-in URL:"
|
||||
} else if is_external_action_suggestion {
|
||||
"Link:"
|
||||
} else {
|
||||
"Setup URL:"
|
||||
}
|
||||
.dim(),
|
||||
]));
|
||||
let url_line = Line::from(vec![self.url.clone().cyan().underlined()]);
|
||||
lines.extend(adaptive_wrap_lines(
|
||||
vec![url_line],
|
||||
@@ -586,6 +864,135 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn generic_url_target() -> AppLinkElicitationTarget {
|
||||
AppLinkElicitationTarget {
|
||||
thread_id: ThreadId::try_from("00000000-0000-0000-0000-000000000002")
|
||||
.expect("valid thread id"),
|
||||
server_name: "payments".to_string(),
|
||||
request_id: AppServerRequestId::String("request-2".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn auth_url_request(url: &str) -> codex_app_server_protocol::McpServerElicitationRequest {
|
||||
codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: Some(serde_json::json!({
|
||||
"_codex_apps": {
|
||||
"connector_auth_failure": {
|
||||
"is_auth_failure": true,
|
||||
"connector_id": "connector_calendar",
|
||||
"connector_name": "Google Calendar",
|
||||
},
|
||||
},
|
||||
})),
|
||||
message: "Reconnect Google Calendar on ChatGPT.".to_string(),
|
||||
url: url.to_string(),
|
||||
elicitation_id: "codex_apps_auth_call_123".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_apps_auth_url_elicitation_builds_auth_app_link_params() {
|
||||
let target = suggestion_target();
|
||||
let request =
|
||||
auth_url_request("https://chatgpt.com/apps/google-calendar/connector_calendar");
|
||||
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
)
|
||||
.expect("expected auth app link params");
|
||||
|
||||
assert_eq!(params.app_id, "connector_calendar");
|
||||
assert_eq!(params.title, "Google Calendar");
|
||||
assert_eq!(
|
||||
params.url,
|
||||
"https://chatgpt.com/apps/google-calendar/connector_calendar"
|
||||
);
|
||||
assert_eq!(params.suggestion_type, Some(AppLinkSuggestionType::Auth));
|
||||
assert_eq!(params.elicitation_target, Some(target));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_codex_apps_url_elicitation_builds_generic_app_link_params() {
|
||||
let target = generic_url_target();
|
||||
let request = codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: None,
|
||||
message: "Review the payment details to continue.".to_string(),
|
||||
url: "https://payments.example/checkout/123".to_string(),
|
||||
elicitation_id: "payment-123".to_string(),
|
||||
};
|
||||
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
)
|
||||
.expect("expected generic URL app link params");
|
||||
|
||||
assert_eq!(
|
||||
params,
|
||||
AppLinkViewParams {
|
||||
app_id: "payment-123".to_string(),
|
||||
title: "Action required".to_string(),
|
||||
description: Some("Server: payments".to_string()),
|
||||
instructions: "Complete the requested action in your browser, then return here."
|
||||
.to_string(),
|
||||
url: "https://payments.example/checkout/123".to_string(),
|
||||
is_installed: true,
|
||||
is_enabled: true,
|
||||
suggest_reason: Some("Review the payment details to continue.".to_string()),
|
||||
suggestion_type: Some(AppLinkSuggestionType::ExternalAction),
|
||||
elicitation_target: Some(target),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_apps_auth_url_elicitation_rejects_untrusted_urls() {
|
||||
let target = suggestion_target();
|
||||
for url in [
|
||||
"http://chatgpt.com/apps/google-calendar/connector_calendar",
|
||||
"https://user:pass@chatgpt.com/apps/google-calendar/connector_calendar",
|
||||
"https://chatgpt.com.evil.example/apps/google-calendar/connector_calendar",
|
||||
"https://evilchatgpt.com/apps/google-calendar/connector_calendar",
|
||||
] {
|
||||
let request = auth_url_request(url);
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
);
|
||||
assert!(params.is_none(), "expected {url} to be rejected");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_url_elicitation_rejects_untrusted_urls() {
|
||||
let target = generic_url_target();
|
||||
for url in [
|
||||
"http://payments.example/checkout/123",
|
||||
"https://user:pass@payments.example/checkout/123",
|
||||
] {
|
||||
let request = codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: None,
|
||||
message: "Review the payment details to continue.".to_string(),
|
||||
url: url.to_string(),
|
||||
elicitation_id: "payment-123".to_string(),
|
||||
};
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
);
|
||||
assert!(params.is_none(), "expected {url} to be rejected");
|
||||
}
|
||||
}
|
||||
|
||||
fn render_snapshot(view: &AppLinkView, area: Rect) -> String {
|
||||
let mut buf = Buffer::empty(area);
|
||||
view.render(area, &mut buf);
|
||||
@@ -717,6 +1124,58 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_url_elicitation_resolves_without_connector_refresh() {
|
||||
let (tx_raw, mut rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let target = generic_url_target();
|
||||
let request = codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: None,
|
||||
message: "Review the payment details to continue.".to_string(),
|
||||
url: "https://payments.example/checkout/123".to_string(),
|
||||
elicitation_id: "payment-123".to_string(),
|
||||
};
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
)
|
||||
.expect("expected generic URL app link params");
|
||||
let mut view = AppLinkView::new(params, tx);
|
||||
|
||||
view.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
match rx.try_recv() {
|
||||
Ok(AppEvent::OpenUrlInBrowser { url }) => {
|
||||
assert_eq!(url, "https://payments.example/checkout/123");
|
||||
}
|
||||
Ok(other) => panic!("unexpected app event: {other:?}"),
|
||||
Err(err) => panic!("missing app event: {err}"),
|
||||
}
|
||||
assert_eq!(view.screen, AppLinkScreen::InstallConfirmation);
|
||||
|
||||
view.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
match rx.try_recv() {
|
||||
Ok(AppEvent::SubmitThreadOp { thread_id, op }) => {
|
||||
assert_eq!(thread_id, target.thread_id);
|
||||
assert_eq!(
|
||||
op,
|
||||
Op::ResolveElicitation {
|
||||
server_name: "payments".to_string(),
|
||||
request_id: AppServerRequestId::String("request-2".to_string()),
|
||||
decision: McpServerElicitationAction::Accept,
|
||||
content: None,
|
||||
meta: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
Ok(other) => panic!("unexpected app event: {other:?}"),
|
||||
Err(err) => panic!("missing app event: {err}"),
|
||||
}
|
||||
assert!(rx.try_recv().is_err());
|
||||
assert!(view.is_complete());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn install_confirmation_does_not_split_long_url_like_token_without_scheme() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
@@ -1076,4 +1535,94 @@ mod tests {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_suggestion_with_reason_snapshot() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let view = AppLinkView::new(
|
||||
AppLinkViewParams {
|
||||
app_id: "connector_google_calendar".to_string(),
|
||||
title: "Google Calendar".to_string(),
|
||||
description: None,
|
||||
instructions: "Sign in to this app in your browser, then return here.".to_string(),
|
||||
url: "https://chatgpt.com/apps/google-calendar/connector_google_calendar"
|
||||
.to_string(),
|
||||
is_installed: true,
|
||||
is_enabled: true,
|
||||
suggest_reason: Some("Reconnect Google Calendar on ChatGPT.".to_string()),
|
||||
suggestion_type: Some(AppLinkSuggestionType::Auth),
|
||||
elicitation_target: Some(suggestion_target()),
|
||||
},
|
||||
tx,
|
||||
);
|
||||
|
||||
assert_snapshot!(
|
||||
"app_link_view_auth_suggestion_with_reason",
|
||||
render_snapshot(
|
||||
&view,
|
||||
Rect::new(0, 0, 72, view.desired_height(/*width*/ 72))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_url_elicitation_snapshot() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let target = generic_url_target();
|
||||
let request = codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: None,
|
||||
message: "Review the payment details to continue.".to_string(),
|
||||
url: "https://payments.example/checkout/123".to_string(),
|
||||
elicitation_id: "payment-123".to_string(),
|
||||
};
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
)
|
||||
.expect("expected generic URL app link params");
|
||||
let view = AppLinkView::new(params, tx);
|
||||
|
||||
assert_snapshot!(
|
||||
"app_link_view_generic_url_elicitation",
|
||||
render_snapshot(
|
||||
&view,
|
||||
Rect::new(0, 0, 72, view.desired_height(/*width*/ 72))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_url_elicitation_confirmation_snapshot() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let target = generic_url_target();
|
||||
let request = codex_app_server_protocol::McpServerElicitationRequest::Url {
|
||||
meta: None,
|
||||
message: "Review the payment details to continue.".to_string(),
|
||||
url: "https://payments.example/checkout/123".to_string(),
|
||||
elicitation_id: "payment-123".to_string(),
|
||||
};
|
||||
let params = AppLinkViewParams::from_url_app_server_request(
|
||||
target.thread_id,
|
||||
&target.server_name,
|
||||
target.request_id.clone(),
|
||||
&request,
|
||||
)
|
||||
.expect("expected generic URL app link params");
|
||||
let mut view = AppLinkView::new(params, tx);
|
||||
|
||||
view.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
|
||||
assert_snapshot!(
|
||||
"app_link_view_generic_url_elicitation_confirmation",
|
||||
render_snapshot(
|
||||
&view,
|
||||
Rect::new(0, 0, 72, view.desired_height(/*width*/ 72))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1315,6 +1315,12 @@ impl BottomPane {
|
||||
AppLinkSuggestionType::Enable => {
|
||||
"Enable this app to use it for the current request.".to_string()
|
||||
}
|
||||
AppLinkSuggestionType::Auth => unreachable!(
|
||||
"auth uses URL mode elicitation, not tool suggestion forms"
|
||||
),
|
||||
AppLinkSuggestionType::ExternalAction => unreachable!(
|
||||
"external actions use URL mode elicitation, not tool suggestion forms"
|
||||
),
|
||||
},
|
||||
url: install_url,
|
||||
is_installed,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/app_link_view.rs
|
||||
expression: "render_snapshot(&view, Rect::new(0, 0, 72, view.desired_height(72)))"
|
||||
---
|
||||
|
||||
Google Calendar
|
||||
|
||||
Reconnect Google Calendar on ChatGPT.
|
||||
|
||||
URL
|
||||
https://chatgpt.com/apps/google-calendar/connector_google_calendar
|
||||
|
||||
Sign in to this app in your browser, then return here.
|
||||
|
||||
|
||||
› 1. Open sign-in URL
|
||||
2. Back
|
||||
Use tab / ↑ ↓ to move, enter to select, esc to close
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/app_link_view.rs
|
||||
expression: "render_snapshot(&view, Rect::new(0, 0, 72, view.desired_height(72)))"
|
||||
---
|
||||
|
||||
Action required
|
||||
Server: payments
|
||||
|
||||
Review the payment details to continue.
|
||||
|
||||
URL
|
||||
https://payments.example/checkout/123
|
||||
|
||||
Complete the requested action in your browser, then return here.
|
||||
|
||||
|
||||
› 1. Open link
|
||||
2. Back
|
||||
Use tab / ↑ ↓ to move, enter to select, esc to close
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/app_link_view.rs
|
||||
expression: "render_snapshot(&view, Rect::new(0, 0, 72, view.desired_height(72)))"
|
||||
---
|
||||
|
||||
Finish in Browser
|
||||
|
||||
Complete the requested action in the browser window that just
|
||||
opened.
|
||||
Then return here and select "I finished".
|
||||
|
||||
Link:
|
||||
https://payments.example/checkout/123
|
||||
|
||||
› 1. I finished
|
||||
2. Back
|
||||
Use tab / ↑ ↓ to move, enter to select, esc to close
|
||||
Reference in new issue
Block a user