claude_code_switcher/templates/
longcat.rs

1//! Longcat AI provider template implementation
2
3use crate::{
4    settings::{ClaudeSettings, Permissions},
5    snapshots::SnapshotScope,
6    templates::Template,
7};
8use std::collections::HashMap;
9
10/// Longcat AI provider template
11#[derive(Debug, Clone)]
12pub struct LongcatTemplate;
13
14impl Template for LongcatTemplate {
15    fn template_type(&self) -> crate::templates::TemplateType {
16        crate::templates::TemplateType::Longcat
17    }
18
19    fn env_var_name(&self) -> &'static str {
20        "LONGCAT_API_KEY"
21    }
22
23    fn display_name(&self) -> &'static str {
24        "Longcat"
25    }
26
27    fn description(&self) -> &'static str {
28        "Longcat Flash Chat API - Fast and efficient conversational AI"
29    }
30
31    fn create_settings(&self, api_key: &str, scope: &SnapshotScope) -> ClaudeSettings {
32        let mut settings = ClaudeSettings::new();
33
34        if matches!(scope, SnapshotScope::Common | SnapshotScope::All) {
35            settings.model = Some("LongCat-Flash-Chat".to_string());
36
37            settings.permissions = Some(Permissions {
38                allow: Some(vec![
39                    "Bash".to_string(),
40                    "Read".to_string(),
41                    "Write".to_string(),
42                    "Edit".to_string(),
43                    "MultiEdit".to_string(),
44                    "Glob".to_string(),
45                    "Grep".to_string(),
46                    "WebFetch".to_string(),
47                ]),
48                ask: None,
49                deny: Some(vec!["WebSearch".to_string()]),
50                additional_directories: None,
51                default_mode: None,
52                disable_bypass_permissions_mode: None,
53            });
54        }
55
56        if matches!(scope, SnapshotScope::Env | SnapshotScope::All) {
57            let mut env = HashMap::new();
58            env.insert("ANTHROPIC_AUTH_TOKEN".to_string(), api_key.to_string());
59            env.insert(
60                "ANTHROPIC_BASE_URL".to_string(),
61                "https://api.longcat.chat/anthropic".to_string(),
62            );
63            env.insert(
64                "ANTHROPIC_MODEL".to_string(),
65                "LongCat-Flash-Chat".to_string(),
66            );
67            env.insert(
68                "ANTHROPIC_SMALL_FAST_MODEL".to_string(),
69                "LongCat-Flash-Chat".to_string(),
70            );
71            env.insert(
72                "ANTHROPIC_DEFAULT_SONNET_MODEL".to_string(),
73                "LongCat-Flash-Chat".to_string(),
74            );
75            env.insert(
76                "CLAUDE_CODE_MAX_OUTPUT_TOKENS".to_string(),
77                "8192".to_string(),
78            );
79            env.insert(
80                "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC".to_string(),
81                "1".to_string(),
82            );
83            settings.env = Some(env);
84        }
85
86        settings
87    }
88}
89
90/// Create Longcat template settings (legacy compatibility function)
91pub fn create_longcat_template(api_key: &str, scope: &SnapshotScope) -> ClaudeSettings {
92    let template = LongcatTemplate;
93    template.create_settings(api_key, scope)
94}