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

Method invoke

crates/chat-cli/src/cli/chat/tools/knowledge.rs:312–526  ·  view source on GitHub ↗
(
        &self,
        os: &Os,
        _updates: &mut impl Write,
        agent: Option<&crate::cli::Agent>,
    )

Source from the content-addressed store, hash-verified

310 }
311
312 pub async fn invoke(
313 &self,
314 os: &Os,
315 _updates: &mut impl Write,
316 agent: Option<&crate::cli::Agent>,
317 ) -> Result<InvokeOutput> {
318 let async_knowledge_store = KnowledgeStore::get_async_instance(os, agent)
319 .await
320 .map_err(|e| eyre::eyre!("Failed to access knowledge base: {}", e))?;
321 let mut store = async_knowledge_store.lock().await;
322
323 let result = match self {
324 Knowledge::Add(add) => {
325 // For path indexing, we'll show a progress message first
326 let path = crate::cli::chat::tools::sanitize_path_tool_arg(os, &add.value);
327 let value_to_use = if path.exists() {
328 path.to_string_lossy().to_string()
329 } else {
330 // If it's not a valid path, use the original value (might be text content)
331 add.value.clone()
332 };
333
334 match store
335 .add(
336 &add.name,
337 &value_to_use,
338 crate::util::knowledge_store::AddOptions::with_db_defaults(os),
339 )
340 .await
341 {
342 Ok(context_id) => format!(
343 "Added '{}' to knowledge base with ID: {}. Track active jobs in '/knowledge status' with provided id.",
344 add.name, context_id
345 ),
346 Err(e) => format!("Failed to add to knowledge base: {}", e),
347 }
348 },
349 Knowledge::Remove(remove) => {
350 if !remove.context_id.is_empty() {
351 // Remove by ID
352 match store.remove_by_id(&remove.context_id).await {
353 Ok(_) => format!("Removed context with ID '{}' from knowledge base", remove.context_id),
354 Err(e) => format!("Failed to remove context by ID: {}", e),
355 }
356 } else if !remove.name.is_empty() {
357 // Remove by name
358 match store.remove_by_name(&remove.name).await {
359 Ok(_) => format!("Removed context with name '{}' from knowledge base", remove.name),
360 Err(e) => format!("Failed to remove context by name: {}", e),
361 }
362 } else if !remove.path.is_empty() {
363 // Remove by path
364 let sanitized_path = crate::cli::chat::tools::sanitize_path_tool_arg(os, &remove.path);
365 match store.remove_by_path(sanitized_path.to_string_lossy().as_ref()).await {
366 Ok(_) => format!("Removed context with path '{}' from knowledge base", remove.path),
367 Err(e) => format!("Failed to remove context by path: {}", e),
368 }
369 } else {

Callers

nothing calls this directly

Calls 15

sanitize_path_tool_argFunction · 0.85
to_stringMethod · 0.80
remove_by_idMethod · 0.80
remove_by_nameMethod · 0.80
remove_by_pathMethod · 0.80
update_context_by_idMethod · 0.80
update_by_pathMethod · 0.80
get_allMethod · 0.80
TextClass · 0.50
existsMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected