tftsr-devops_investigation/src-tauri/src/ai/provider.rs
Shaun Arman 3adb5c3d48
Some checks failed
Test / frontend-typecheck (pull_request) Successful in 1m56s
Test / frontend-tests (pull_request) Successful in 1m53s
Test / rust-fmt-check (pull_request) Failing after 4m47s
Test / rust-clippy (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
feat(ai): add tool-calling and integration search as AI data source
This commit implements two major features:

1. Integration Search as Primary AI Data Source
   - Confluence, ServiceNow, and Azure DevOps searches execute before AI queries
   - Search results injected as system context for AI providers
   - Parallel search execution for performance
   - Webview-based fetch for HttpOnly cookie support
   - Persistent browser windows maintain authenticated sessions

2. AI Tool-Calling (Function Calling)
   - Allows AI to automatically execute functions during conversation
   - Implemented for OpenAI-compatible providers and MSI GenAI
   - Created add_ado_comment tool for updating Azure DevOps tickets
   - Iterative tool-calling loop supports multi-step workflows
   - Extensible architecture for adding new tools

Key Files:
- src-tauri/src/ai/tools.rs (NEW) - Tool definitions
- src-tauri/src/integrations/*_search.rs (NEW) - Integration search modules
- src-tauri/src/integrations/webview_fetch.rs (NEW) - HttpOnly cookie workaround
- src-tauri/src/commands/ai.rs - Tool execution and integration search
- src-tauri/src/ai/openai.rs - Tool-calling for OpenAI and MSI GenAI
- All providers updated with tools parameter support

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-06 13:22:02 -05:00

33 lines
1.1 KiB
Rust

use async_trait::async_trait;
use crate::ai::{ChatResponse, Message, ProviderInfo, Tool};
use crate::state::ProviderConfig;
#[async_trait]
pub trait Provider: Send + Sync {
fn name(&self) -> &str;
fn info(&self) -> ProviderInfo;
async fn chat(
&self,
messages: Vec<Message>,
config: &ProviderConfig,
tools: Option<Vec<Tool>>,
) -> anyhow::Result<ChatResponse>;
}
pub fn create_provider(config: &ProviderConfig) -> Box<dyn Provider> {
// Match on provider_type (the kind), falling back to name for legacy configs
let kind = if config.provider_type.is_empty() {
config.name.as_str()
} else {
config.provider_type.as_str()
};
match kind {
"anthropic" => Box::new(crate::ai::anthropic::AnthropicProvider),
"gemini" => Box::new(crate::ai::gemini::GeminiProvider),
"mistral" => Box::new(crate::ai::mistral::MistralProvider),
"ollama" => Box::new(crate::ai::ollama::OllamaProvider),
_ => Box::new(crate::ai::openai::OpenAiProvider), // default: OpenAI-compatible
}
}