Add context with flexible options
(&mut self, name: &str, path_str: &str, options: AddOptions)
| 287 | |
| 288 | /// Add context with flexible options |
| 289 | pub async fn add(&mut self, name: &str, path_str: &str, options: AddOptions) -> Result<String, String> { |
| 290 | let path_buf = std::path::PathBuf::from(path_str); |
| 291 | let canonical_path = path_buf |
| 292 | .canonicalize() |
| 293 | .map_err(|_io_error| format!("❌ Path does not exist: {}", path_str))?; |
| 294 | |
| 295 | // Use provided description or generate default |
| 296 | let description = options |
| 297 | .description |
| 298 | .unwrap_or_else(|| format!("Knowledge context for {}", name)); |
| 299 | |
| 300 | // Create AddContextRequest with all options |
| 301 | let request = AddContextRequest { |
| 302 | path: canonical_path.clone(), |
| 303 | name: name.to_string(), |
| 304 | description: if !options.include_patterns.is_empty() || !options.exclude_patterns.is_empty() { |
| 305 | let mut full_description = description; |
| 306 | if !options.include_patterns.is_empty() { |
| 307 | full_description.push_str(&format!(" [Include: {}]", options.include_patterns.join(", "))); |
| 308 | } |
| 309 | if !options.exclude_patterns.is_empty() { |
| 310 | full_description.push_str(&format!(" [Exclude: {}]", options.exclude_patterns.join(", "))); |
| 311 | } |
| 312 | full_description |
| 313 | } else { |
| 314 | description |
| 315 | }, |
| 316 | persistent: true, |
| 317 | include_patterns: if options.include_patterns.is_empty() { |
| 318 | None |
| 319 | } else { |
| 320 | Some(options.include_patterns.clone()) |
| 321 | }, |
| 322 | exclude_patterns: if options.exclude_patterns.is_empty() { |
| 323 | None |
| 324 | } else { |
| 325 | Some(options.exclude_patterns.clone()) |
| 326 | }, |
| 327 | embedding_type: match options.embedding_type.as_ref() { |
| 328 | Some(s) => match EmbeddingType::from_str(s) { |
| 329 | Some(et) => Some(et), |
| 330 | None => { |
| 331 | return Err(format!("Invalid embedding type '{}'. Valid options are: fast, best", s)); |
| 332 | }, |
| 333 | }, |
| 334 | None => None, |
| 335 | }, |
| 336 | }; |
| 337 | |
| 338 | match self.agent_client.add_context(request).await { |
| 339 | Ok((operation_id, _)) => { |
| 340 | let mut message = format!( |
| 341 | "🚀 Started indexing '{}'\n📁 Path: {}\n🆔 Operation ID: {}", |
| 342 | name, |
| 343 | canonical_path.display(), |
| 344 | &operation_id.to_string()[..8] |
| 345 | ); |
| 346 | if !options.include_patterns.is_empty() || !options.exclude_patterns.is_empty() { |
no test coverage detected