MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / handle_add

Method handle_add

crates/chat-cli/src/cli/chat/cli/knowledge.rs:256–312  ·  view source on GitHub ↗
(
        os: &Os,
        session: &mut ChatSession,
        name: &str,
        path: &str,
        include_patterns: &[String],
        exclude_patterns: &[String],
        index_type: &Option<Stri

Source from the content-addressed store, hash-verified

254 }
255
256 async fn handle_add(
257 os: &Os,
258 session: &mut ChatSession,
259 name: &str,
260 path: &str,
261 include_patterns: &[String],
262 exclude_patterns: &[String],
263 index_type: &Option<String>,
264 ) -> OperationResult {
265 match Self::validate_and_sanitize_path(os, path) {
266 Ok(sanitized_path) => {
267 let agent = Self::get_agent(session);
268
269 let async_knowledge_store = match KnowledgeStore::get_async_instance(os, agent).await {
270 Ok(store) => store,
271 Err(e) => return OperationResult::Error(format!("Error accessing knowledge base: {}", e)),
272 };
273 let mut store = async_knowledge_store.lock().await;
274
275 let include = if include_patterns.is_empty() {
276 Self::get_db_patterns(os, crate::database::settings::Setting::KnowledgeDefaultIncludePatterns)
277 } else {
278 include_patterns.to_vec()
279 };
280
281 let exclude = if exclude_patterns.is_empty() {
282 Self::get_db_patterns(os, crate::database::settings::Setting::KnowledgeDefaultExcludePatterns)
283 } else {
284 exclude_patterns.to_vec()
285 };
286
287 let embedding_type_resolved = index_type.clone().or_else(|| {
288 os.database
289 .settings
290 .get(crate::database::settings::Setting::KnowledgeIndexType)
291 .and_then(|v| v.as_str().map(|s| s.to_string()))
292 });
293
294 let options = crate::util::knowledge_store::AddOptions::new()
295 .with_include_patterns(include)
296 .with_exclude_patterns(exclude)
297 .with_embedding_type(embedding_type_resolved);
298
299 match store.add(name, &sanitized_path.clone(), options).await {
300 Ok(message) => OperationResult::Info(message),
301 Err(e) => {
302 if e.contains("Invalid include pattern") || e.contains("Invalid exclude pattern") {
303 OperationResult::Error(e)
304 } else {
305 OperationResult::Error(format!("Failed to add: {}", e))
306 }
307 },
308 }
309 },
310 Err(e) => OperationResult::Error(format!("Invalid path: {}", e)),
311 }
312 }
313

Callers

nothing calls this directly

Calls 11

mapMethod · 0.80
to_stringMethod · 0.80
with_embedding_typeMethod · 0.80
with_exclude_patternsMethod · 0.80
with_include_patternsMethod · 0.80
ErrorEnum · 0.50
is_emptyMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected