mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
default
This commit is contained in:
@@ -542,7 +542,7 @@ impl Session {
|
||||
);
|
||||
|
||||
// Create the mutable state for the Session.
|
||||
let state = SessionState::new(session_configuration.clone(), config.model_context_window);
|
||||
let state = SessionState::new(session_configuration.clone());
|
||||
|
||||
let services = SessionServices {
|
||||
mcp_connection_manager,
|
||||
@@ -876,7 +876,7 @@ impl Session {
|
||||
turn_context: &TurnContext,
|
||||
rollout_items: &[RolloutItem],
|
||||
) -> CodexResult<Vec<ResponseItem>> {
|
||||
let mut history = ConversationHistory::new(turn_context.client.get_model_context_window());
|
||||
let mut history = ConversationHistory::new();
|
||||
for item in rollout_items {
|
||||
match item {
|
||||
RolloutItem::ResponseItem(response_item) => {
|
||||
@@ -1543,8 +1543,7 @@ pub(crate) async fn run_task(
|
||||
// For normal turns, continue recording to the session history as before.
|
||||
let is_review_mode = turn_context.is_review_mode;
|
||||
|
||||
let mut review_thread_history: ConversationHistory =
|
||||
ConversationHistory::new(turn_context.client.get_model_context_window());
|
||||
let mut review_thread_history: ConversationHistory = ConversationHistory::new();
|
||||
if is_review_mode {
|
||||
// Seed review threads with environment context so the model knows the working directory.
|
||||
review_thread_history
|
||||
@@ -2570,7 +2569,7 @@ mod tests {
|
||||
original_config_do_not_use: Arc::clone(&config),
|
||||
};
|
||||
|
||||
let state = SessionState::new(session_configuration.clone(), config.model_context_window);
|
||||
let state = SessionState::new(session_configuration.clone());
|
||||
|
||||
let services = SessionServices {
|
||||
mcp_connection_manager: McpConnectionManager::default(),
|
||||
@@ -2638,7 +2637,7 @@ mod tests {
|
||||
original_config_do_not_use: Arc::clone(&config),
|
||||
};
|
||||
|
||||
let state = SessionState::new(session_configuration.clone(), config.model_context_window);
|
||||
let state = SessionState::new(session_configuration.clone());
|
||||
|
||||
let services = SessionServices {
|
||||
mcp_connection_manager: McpConnectionManager::default(),
|
||||
@@ -2861,8 +2860,7 @@ mod tests {
|
||||
turn_context: &TurnContext,
|
||||
) -> CodexResult<(Vec<RolloutItem>, Vec<ResponseItem>)> {
|
||||
let mut rollout_items = Vec::new();
|
||||
let mut live_history =
|
||||
ConversationHistory::new(turn_context.client.get_model_context_window());
|
||||
let mut live_history = ConversationHistory::new();
|
||||
|
||||
let initial_context = session.build_initial_context(turn_context);
|
||||
for item in &initial_context {
|
||||
|
||||
@@ -17,12 +17,7 @@ pub(crate) struct ConversationHistory {
|
||||
}
|
||||
|
||||
impl ConversationHistory {
|
||||
pub(crate) fn new(model_context_window: Option<i64>) -> Self {
|
||||
let token_info = model_context_window.map(|context_window| TokenUsageInfo {
|
||||
total_token_usage: TokenUsage::default(),
|
||||
last_token_usage: TokenUsage::default(),
|
||||
model_context_window: Some(context_window),
|
||||
});
|
||||
pub(crate) fn new() -> Self {
|
||||
let tokenizer = match Tokenizer::try_default() {
|
||||
Ok(tokenizer) => Some(tokenizer),
|
||||
Err(error) => {
|
||||
@@ -32,7 +27,7 @@ impl ConversationHistory {
|
||||
};
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
token_info,
|
||||
token_info: Some(TokenUsageInfo::default()),
|
||||
tokenizer,
|
||||
}
|
||||
}
|
||||
@@ -408,12 +403,6 @@ impl ConversationHistory {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ConversationHistory {
|
||||
fn default() -> Self {
|
||||
Self::new(None)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn error_or_panic(message: String) {
|
||||
if cfg!(debug_assertions) || env!("CARGO_PKG_VERSION").contains("alpha") {
|
||||
@@ -460,7 +449,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn create_history_with_items(items: Vec<ResponseItem>) -> ConversationHistory {
|
||||
let mut h = ConversationHistory::new(None);
|
||||
let mut h = ConversationHistory::new();
|
||||
h.record_items(items.iter()).unwrap();
|
||||
h
|
||||
}
|
||||
@@ -477,7 +466,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn filters_non_api_messages() {
|
||||
let mut h = ConversationHistory::default();
|
||||
let mut h = ConversationHistory::new();
|
||||
// System message is not an API message; Other is ignored.
|
||||
let system = ResponseItem::Message {
|
||||
id: None,
|
||||
|
||||
@@ -18,13 +18,10 @@ pub(crate) struct SessionState {
|
||||
|
||||
impl SessionState {
|
||||
/// Create a new session state mirroring previous `State::default()` semantics.
|
||||
pub(crate) fn new(
|
||||
session_configuration: SessionConfiguration,
|
||||
model_context_window: Option<i64>,
|
||||
) -> Self {
|
||||
pub(crate) fn new(session_configuration: SessionConfiguration) -> Self {
|
||||
Self {
|
||||
session_configuration,
|
||||
history: ConversationHistory::new(model_context_window),
|
||||
history: ConversationHistory::new(),
|
||||
latest_rate_limits: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,7 +575,7 @@ pub struct TokenUsage {
|
||||
pub total_tokens: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS, Default)]
|
||||
pub struct TokenUsageInfo {
|
||||
/// The total token usage for the session. accumulated from all turns.
|
||||
pub total_token_usage: TokenUsage,
|
||||
|
||||
Reference in New Issue
Block a user