mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
* refactor: deduplicate tool parameter extraction and remove dead stub tools Delete 4 never-registered stub tools (marketplace, restaurant, ecommerce, taskrabbit) removing ~625 lines of dead code. Add require_str/require_param helpers to tool.rs and refactor ~30 call sites across 10 tool files from 4-6 line inline extractions to single-line calls. Consolidate worker HTTP client with get_json/post_json helpers, reducing boilerplate in 4 methods. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: return JSON from orchestrator /complete endpoint The report_complete handler returned bare StatusCode::OK (no body), which broke the post_json helper that expects a JSON response. Return {"status": "ok"} for consistency with other worker endpoints. Addresses review feedback on PR #98. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
78 lines
2.2 KiB
Rust
78 lines
2.2 KiB
Rust
//! Time estimation.
|
|
|
|
use std::collections::HashMap;
|
|
use std::time::Duration;
|
|
|
|
/// Estimates time for tools and operations.
|
|
pub struct TimeEstimator {
|
|
/// Base durations per tool.
|
|
tool_durations: HashMap<String, Duration>,
|
|
}
|
|
|
|
impl TimeEstimator {
|
|
/// Create a new time estimator.
|
|
pub fn new() -> Self {
|
|
let mut tool_durations = HashMap::new();
|
|
|
|
// Default tool durations
|
|
tool_durations.insert("http".to_string(), Duration::from_secs(5));
|
|
tool_durations.insert("echo".to_string(), Duration::from_millis(10));
|
|
tool_durations.insert("time".to_string(), Duration::from_millis(1));
|
|
tool_durations.insert("json".to_string(), Duration::from_millis(5));
|
|
|
|
Self { tool_durations }
|
|
}
|
|
|
|
/// Estimate duration for a tool call.
|
|
pub fn estimate_tool(&self, tool_name: &str) -> Duration {
|
|
self.tool_durations
|
|
.get(tool_name)
|
|
.copied()
|
|
.unwrap_or(Duration::from_secs(5)) // Default for unknown tools
|
|
}
|
|
|
|
/// Estimate LLM response time.
|
|
pub fn estimate_llm_response(&self, estimated_tokens: u32) -> Duration {
|
|
// Rough estimate: ~50 tokens/second
|
|
let seconds = estimated_tokens as f64 / 50.0;
|
|
Duration::from_secs_f64(seconds.max(1.0))
|
|
}
|
|
|
|
/// Set a tool's base duration.
|
|
pub fn set_tool_duration(&mut self, tool_name: impl Into<String>, duration: Duration) {
|
|
self.tool_durations.insert(tool_name.into(), duration);
|
|
}
|
|
|
|
/// Get all tool durations.
|
|
pub fn all_tool_durations(&self) -> &HashMap<String, Duration> {
|
|
&self.tool_durations
|
|
}
|
|
}
|
|
|
|
impl Default for TimeEstimator {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_tool_time_estimation() {
|
|
let estimator = TimeEstimator::new();
|
|
|
|
assert!(estimator.estimate_tool("echo") < Duration::from_secs(1));
|
|
assert!(estimator.estimate_tool("http") >= Duration::from_secs(1));
|
|
}
|
|
|
|
#[test]
|
|
fn test_llm_time_estimation() {
|
|
let estimator = TimeEstimator::new();
|
|
|
|
let duration = estimator.estimate_llm_response(500);
|
|
assert!(duration >= Duration::from_secs(1));
|
|
}
|
|
}
|