feat: add lesson export and import functionality

- Implemented `LessonExport` and `LessonImport` actions in the action module.
- Added corresponding command parsing for lesson export and import.
- Created functions to handle lesson export and import in the memory module.
- Updated state management to reflect changes after lesson operations.
- Introduced deferred operations for handling asynchronous tasks in the event loop.
- Enhanced the tool execution context to include graduated checks for file operations.
- Added OAuth support with PKCE for secure authorization flows.
- Implemented a loopback server for handling OAuth redirects.
- Refactored various modules to improve code organization and maintainability.
This commit is contained in:
asepharyana
2026-07-11 18:23:01 +07:00
parent cc03bd79b6
commit c1ad206a00
49 changed files with 1088 additions and 12 deletions
+38
View File
@@ -0,0 +1,38 @@
use crate::dto::chat::message::ChatMessage;
const MAX_WIRE_TOKENS: usize = 8000;
const MIN_MESSAGES_BEFORE_SHAPE: usize = 20;
const ENGAGE_HYSTERESIS: usize = 5;
pub fn should_shape(total_messages: usize, prev_shaped: bool) -> bool {
if total_messages < MIN_MESSAGES_BEFORE_SHAPE {
return false;
}
let threshold = if prev_shaped {
MIN_MESSAGES_BEFORE_SHAPE + ENGAGE_HYSTERESIS
} else {
MIN_MESSAGES_BEFORE_SHAPE
};
total_messages >= threshold
}
pub fn shape_messages(messages: &[ChatMessage], token_count: usize) -> Vec<ChatMessage> {
if token_count <= MAX_WIRE_TOKENS || messages.len() < 10 {
return messages.to_vec();
}
let keep_recent = messages
.iter()
.rev()
.take(MAX_WIRE_TOKENS / 200)
.cloned()
.collect::<Vec<_>>();
let mut result = Vec::new();
if let Some(first) = messages.first() {
result.push(first.clone());
}
result.push(ChatMessage::system(
"[prior conversation compacted]".to_string(),
));
result.extend(keep_recent.into_iter().rev());
result
}