tftsr-devops_investigation/src/stores/settingsStore.ts
Shaun Arman 093495a653
Some checks failed
Test / rust-fmt-check (pull_request) Failing after 0s
Test / rust-clippy (pull_request) Failing after 1s
Test / rust-tests (pull_request) Failing after 0s
Test / frontend-typecheck (pull_request) Failing after 16s
Test / frontend-tests (pull_request) Failing after 18s
PR Review Automation / review (pull_request) Failing after 4m13s
feat: full copy from apollo_nxt-trcaa with complete sanitization
Complete backport of all features from apollo_nxt-trcaa repository:
- Three-tier shell execution safety system (Tier 1: auto, Tier 2: approve, Tier 3: deny)
- Ollama function calling with tool use support
- AI provider tool calling auto-detection
- kubectl binary bundling and management
- kubeconfig upload and context management
- Shell approval modal with real-time UI
- MCP protocol HTTP transport with custom headers
- Enhanced security audit logging
- Comprehensive test coverage (275+ tests)
- Updated CI/CD workflows for Gitea Actions
- Complete documentation (ADRs, wiki, release notes)

Sanitization applied to all files:
- Removed all MSI, Motorola, VNXT, Vesta references
- Replaced internal infrastructure references with TFTSR equivalents
- Updated all URLs and API endpoints
- Sanitized commit history references in documentation

Technical changes:
- New modules: shell/classifier, shell/executor, shell/kubectl, shell/kubeconfig
- Enhanced AI providers: ollama.rs, openai.rs with function calling
- New Tauri commands: shell execution, kubeconfig management, tool calling detection
- Database migrations: shell_execution_audit table
- Frontend: ShellApprovalModal, ShellExecution, KubeconfigManager pages
- CI/CD: kubectl bundling, multi-platform builds, Gitea Actions integration

Version: 1.0.8

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-06-05 14:12:43 -05:00

70 lines
2.6 KiB
TypeScript

import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { AppSettings, ProviderConfig } from "@/lib/tauriCommands";
interface SettingsState extends AppSettings {
addProvider: (provider: ProviderConfig) => void;
updateProvider: (index: number, provider: ProviderConfig) => void;
removeProvider: (index: number) => void;
setProviders: (providers: ProviderConfig[]) => void;
setActiveProvider: (name: string) => void;
setTheme: (theme: "light" | "dark") => void;
getActiveProvider: () => ProviderConfig | undefined;
pii_enabled_patterns: Record<string, boolean>;
setPiiPattern: (id: string, enabled: boolean) => void;
}
export const useSettingsStore = create<SettingsState>()(
persist(
(set, get) => ({
theme: "dark" as const,
ai_providers: [] as ProviderConfig[],
active_provider: undefined,
default_provider: "ollama",
default_model: "llama3.2:3b",
ollama_url: "http://localhost:11434",
addProvider: (provider) =>
set((state) => ({ ai_providers: [...state.ai_providers, provider] })),
updateProvider: (index, provider) =>
set((state) => {
const providers = [...state.ai_providers];
providers[index] = provider;
return { ai_providers: providers };
}),
removeProvider: (index) =>
set((state) => ({
ai_providers: state.ai_providers.filter((_, i) => i !== index),
})),
setProviders: (providers) => set({ ai_providers: providers }),
setActiveProvider: (name) => set({ active_provider: name }),
setTheme: (theme) => set({ theme }),
pii_enabled_patterns: Object.fromEntries(
["email", "ip_address", "phone", "ssn", "credit_card", "hostname", "password", "api_key"]
.map((id) => [id, true])
) as Record<string, boolean>,
setPiiPattern: (id: string, enabled: boolean) =>
set((state) => ({
pii_enabled_patterns: { ...state.pii_enabled_patterns, [id]: enabled },
})),
getActiveProvider: () => {
const state = get();
return state.ai_providers.find((p) => p.name === state.active_provider)
?? state.ai_providers[0];
},
}),
{
name: "trcaa-settings",
// Don't persist ai_providers to localStorage - they're stored in encrypted database
partialize: (state) => ({
theme: state.theme,
active_provider: state.active_provider,
default_provider: state.default_provider,
default_model: state.default_model,
ollama_url: state.ollama_url,
pii_enabled_patterns: state.pii_enabled_patterns,
}),
}
)
);