chasm_cli/providers/cloud/
mod.rs

1// Copyright (c) 2024-2026 Nervosys LLC
2// SPDX-License-Identifier: Apache-2.0
3//! Cloud-based LLM provider integrations
4//!
5//! This module provides clients for fetching conversation histories from
6//! cloud-based LLM services like ChatGPT, Claude, Perplexity, etc.
7//!
8//! ## Supported Providers
9//!
10//! - **Microsoft 365 Copilot** - Enterprise AI assistant in Office apps
11//! - **ChatGPT** - OpenAI's ChatGPT web interface conversations
12//! - **Anthropic** - Claude conversations
13//! - **Perplexity** - Perplexity AI conversations
14//! - **DeepSeek** - DeepSeek chat history
15//! - **Qwen** - Alibaba Qwen conversations
16//! - **Gemini** - Google Gemini conversations
17//! - **Mistral** - Mistral AI conversations
18//! - **Cohere** - Cohere chat history
19//! - **Grok** - xAI Grok conversations
20//! - **Groq** - Groq conversations
21//! - **Together** - Together AI conversations
22//! - **Fireworks** - Fireworks AI conversations
23//!
24//! ## Authentication
25//!
26//! Most providers require API keys or session tokens. These can be provided via:
27//! - Environment variables (e.g., `OPENAI_API_KEY`)
28//! - Configuration file (`~/.config/csm/config.json`)
29//! - Command-line arguments
30
31pub mod anthropic;
32pub mod chatgpt;
33pub mod common;
34pub mod deepseek;
35pub mod gemini;
36pub mod m365copilot;
37pub mod perplexity;
38
39pub use anthropic::AnthropicProvider;
40pub use chatgpt::ChatGPTProvider;
41pub use common::{CloudConversation, CloudMessage, CloudProvider, FetchOptions};
42pub use deepseek::DeepSeekProvider;
43pub use gemini::GeminiProvider;
44pub use m365copilot::M365CopilotProvider;
45pub use perplexity::PerplexityProvider;
46
47use super::config::ProviderType;
48use crate::models::ChatSession;
49use anyhow::Result;
50
51/// Get a cloud provider by type
52pub fn get_cloud_provider(
53    provider_type: ProviderType,
54    api_key: Option<String>,
55) -> Option<Box<dyn CloudProvider>> {
56    match provider_type {
57        ProviderType::M365Copilot => Some(Box::new(M365CopilotProvider::new(api_key))),
58        ProviderType::ChatGPT => Some(Box::new(ChatGPTProvider::new(api_key))),
59        ProviderType::Anthropic => Some(Box::new(AnthropicProvider::new(api_key))),
60        ProviderType::Perplexity => Some(Box::new(PerplexityProvider::new(api_key))),
61        ProviderType::DeepSeek => Some(Box::new(DeepSeekProvider::new(api_key))),
62        ProviderType::Gemini => Some(Box::new(GeminiProvider::new(api_key))),
63        _ => None,
64    }
65}
66
67/// Fetch all conversations from a cloud provider
68pub fn fetch_conversations(
69    provider_type: ProviderType,
70    api_key: Option<String>,
71    options: &FetchOptions,
72) -> Result<Vec<ChatSession>> {
73    let provider = get_cloud_provider(provider_type, api_key)
74        .ok_or_else(|| anyhow::anyhow!("Unsupported cloud provider: {}", provider_type))?;
75
76    provider.fetch_all_conversations(options)
77}