mirror of
https://github.com/openai/codex.git
synced 2026-10-25 18:28:38 +00:00
Merge 5dd91e47fe into sapling-pr-archive-bolinfest
This commit is contained in:
@@ -21,6 +21,9 @@ pub struct Config {
|
||||
/// Optional override of model selection.
|
||||
pub model: String,
|
||||
|
||||
/// Key into the model_providers map that specifies which provider to use.
|
||||
pub model_provider_id: String,
|
||||
|
||||
/// Info needed to make an API request to the model.
|
||||
pub model_provider: ModelProviderInfo,
|
||||
|
||||
@@ -219,21 +222,22 @@ impl Config {
|
||||
model_providers.entry(key).or_insert(provider);
|
||||
}
|
||||
|
||||
let model_provider_name = provider
|
||||
let model_provider_id = provider
|
||||
.or(cfg.model_provider)
|
||||
.unwrap_or_else(|| "openai".to_string());
|
||||
let model_provider = model_providers
|
||||
.get(&model_provider_name)
|
||||
.get(&model_provider_id)
|
||||
.ok_or_else(|| {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
format!("Model provider `{model_provider_name}` not found"),
|
||||
format!("Model provider `{model_provider_id}` not found"),
|
||||
)
|
||||
})?
|
||||
.clone();
|
||||
|
||||
let config = Self {
|
||||
model: model.or(cfg.model).unwrap_or_else(default_model),
|
||||
model_provider_id,
|
||||
model_provider,
|
||||
cwd: cwd.map_or_else(
|
||||
|| {
|
||||
|
||||
@@ -162,12 +162,8 @@ impl ChatWidget<'_> {
|
||||
}
|
||||
|
||||
fn submit_welcome_message(&mut self) -> std::result::Result<(), SendError<AppEvent>> {
|
||||
self.handle_codex_event(Event {
|
||||
id: "welcome".to_string(),
|
||||
msg: EventMsg::AgentMessage {
|
||||
message: "Welcome to codex!".to_string(),
|
||||
},
|
||||
})?;
|
||||
self.conversation_history.add_welcome_message();
|
||||
self.request_redraw()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,10 @@ impl ConversationHistoryWidget {
|
||||
self.scroll_position = usize::MAX;
|
||||
}
|
||||
|
||||
pub fn add_welcome_message(&mut self) {
|
||||
self.add_to_history(HistoryCell::new_welcome_message());
|
||||
}
|
||||
|
||||
pub fn add_user_message(&mut self, message: String) {
|
||||
self.add_to_history(HistoryCell::new_user_prompt(message));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ pub(crate) enum PatchEventType {
|
||||
/// `Vec<Line<'static>>` representation to make it easier to display in a
|
||||
/// scrollable list.
|
||||
pub(crate) enum HistoryCell {
|
||||
/// Welcome message.
|
||||
WelcomeMessage { lines: Vec<Line<'static>> },
|
||||
|
||||
/// Message from the user.
|
||||
UserPrompt { lines: Vec<Line<'static>> },
|
||||
|
||||
@@ -88,6 +91,18 @@ pub(crate) enum HistoryCell {
|
||||
const TOOL_CALL_MAX_LINES: usize = 5;
|
||||
|
||||
impl HistoryCell {
|
||||
pub(crate) fn new_welcome_message() -> Self {
|
||||
let lines: Vec<Line<'static>> = vec![
|
||||
Line::from(vec![
|
||||
"OpenAI ".into(),
|
||||
"Codex".bold(),
|
||||
" (research preview)".dim(),
|
||||
]),
|
||||
Line::from(""),
|
||||
];
|
||||
HistoryCell::WelcomeMessage { lines }
|
||||
}
|
||||
|
||||
pub(crate) fn new_user_prompt(message: String) -> Self {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
lines.push(Line::from("user".cyan().bold()));
|
||||
@@ -258,19 +273,16 @@ impl HistoryCell {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
|
||||
lines.push(Line::from("codex session:".magenta().bold()));
|
||||
lines.push(Line::from(vec!["↳ model: ".bold(), model.into()]));
|
||||
lines.push(Line::from(vec![
|
||||
"↳ cwd: ".bold(),
|
||||
config.cwd.display().to_string().into(),
|
||||
]));
|
||||
lines.push(Line::from(vec![
|
||||
"↳ approval: ".bold(),
|
||||
format!("{:?}", config.approval_policy).into(),
|
||||
]));
|
||||
lines.push(Line::from(vec![
|
||||
"↳ sandbox: ".bold(),
|
||||
format!("{:?}", config.sandbox_policy).into(),
|
||||
]));
|
||||
let entries = vec![
|
||||
("workdir", config.cwd.display().to_string()),
|
||||
("model", model),
|
||||
("provider", config.model_provider_id.clone()),
|
||||
("approval", format!("{:?}", config.approval_policy)),
|
||||
("sandbox", format!("{:?}", config.sandbox_policy)),
|
||||
];
|
||||
for (key, value) in entries {
|
||||
lines.push(Line::from(vec![format!("{key}: ").bold(), value.into()]));
|
||||
}
|
||||
lines.push(Line::from(""));
|
||||
|
||||
HistoryCell::SessionInfo { lines }
|
||||
@@ -338,7 +350,8 @@ impl HistoryCell {
|
||||
|
||||
pub(crate) fn lines(&self) -> &Vec<Line<'static>> {
|
||||
match self {
|
||||
HistoryCell::UserPrompt { lines, .. }
|
||||
HistoryCell::WelcomeMessage { lines, .. }
|
||||
| HistoryCell::UserPrompt { lines, .. }
|
||||
| HistoryCell::AgentMessage { lines, .. }
|
||||
| HistoryCell::BackgroundEvent { lines, .. }
|
||||
| HistoryCell::ErrorEvent { lines, .. }
|
||||
|
||||
Reference in New Issue
Block a user