Home / Documentation / API Reference

🔧 API Reference

Documentation complète de l'API François : Tauri Commands, Stores Zustand, Services TypeScript, et Configuration.

📦 Architecture Overview

François utilise une architecture Tauri + React + TypeScript avec trois couches principales :

  • Backend Rust : Tauri Commands pour les opérations système (filesystem, GPU, processes)
  • State Management : 14 Zustand stores pour la gestion d'état réactive
  • Services TypeScript : 30+ services pour l'Autopilot, le GPU, l'Observer, et les intégrations externes

🦀 Tauri Commands (Rust Backend)

Les Tauri Commands sont des fonctions Rust exposées au frontend TypeScript via l'API invoke().

Filesystem Commands

// Read file
invoke('read_file', { path: '/path/to/file.ts' })
  → Promise<string>

// Write file
invoke('write_file', { path: '/path/to/file.ts', content: 'code...' })
  → Promise<void>

// List directory
invoke('list_directory', { path: '/path/to/dir' })
  → Promise<FileEntry[]>

// Search files (glob)
invoke('search_files', { pattern: '**/*.ts', cwd: '/project' })
  → Promise<string[]>

// Watch directory
invoke('watch_directory', { path: '/project' })
  → void (events via event listeners)

GPU Commands

// Initialize GPU backend
invoke('gpu_init', { backend: 'metal' | 'cuda' | 'vulkan' })
  → Promise<GpuStatus>

// GPU grep
invoke('gpu_grep', {
  pattern: 'function\\s+\\w+',
  files: string[],
  options: { case_sensitive: boolean, regex: boolean }
})
  → Promise<GrepResult[]>

// GPU parse
invoke('gpu_parse_file', { path: '/file.ts', language: 'typescript' })
  → Promise<AstNode>

// GPU status
invoke('gpu_status')
  → Promise<{ available: boolean, backend: string, memory: number }>

Autopilot Commands

// Start mission
invoke('autopilot_start', {
  mission: {
    description: 'Create REST API with JWT',
    complexity: 7,
    mode: 'standard' | 'fast'
  }
})
  → Promise<MissionId>

// Get mission status
invoke('autopilot_status', { mission_id: string })
  → Promise<MissionStatus>

// Abort mission
invoke('autopilot_abort', { mission_id: string })
  → Promise<void>

Observer Commands

// Get metrics
invoke('observer_get_metrics')
  → Promise<ObserverMetrics>

// Get health score
invoke('observer_health_score')
  → Promise<number>  // 0-100

// Get timeline events
invoke('observer_timeline', {
  start: timestamp,
  end: timestamp,
  types?: string[]
})
  → Promise<TimelineEvent[]>

Process Commands

// Execute command
invoke('execute_command', {
  command: 'npm test',
  cwd: '/project',
  env?: Record<string, string>
})
  → Promise<CommandOutput>

// Kill process
invoke('kill_process', { pid: number })
  → Promise<void>

🏪 Zustand Stores (State Management)

François utilise 14 Zustand stores pour gérer l'état de l'application de manière réactive.

1. useProjectStore

interface ProjectStore {
  // State
  currentProject: Project | null
  files: FileTree
  openFiles: FileEntry[]
  activeFile: FileEntry | null

  // Actions
  loadProject: (path: string) => Promise<void>
  openFile: (path: string) => void
  closeFile: (path: string) => void
  setActiveFile: (path: string) => void
  refreshFiles: () => Promise<void>
}

// Usage
const { currentProject, openFile } = useProjectStore()
openFile('/src/App.tsx')

2. useEditorStore

interface EditorStore {
  // State
  monaco: Monaco | null
  editor: IStandaloneCodeEditor | null
  theme: string
  fontSize: number
  tabSize: number

  // Actions
  setMonaco: (monaco: Monaco) => void
  setEditor: (editor: IStandaloneCodeEditor) => void
  changeTheme: (theme: string) => void
  updateSettings: (settings: EditorSettings) => void
}

3. useAutopilotStore

interface AutopilotStore {
  // State
  missions: Mission[]
  activeMission: Mission | null
  currentAgent: AgentType | null
  fsmState: FSMState

  // Actions
  startMission: (description: string) => Promise<void>
  abortMission: (id: string) => Promise<void>
  transitionState: (from: FSMState, to: FSMState) => void
}

4. useObserverStore

interface ObserverStore {
  // State
  metrics: ObserverMetrics
  healthScore: number
  alerts: Alert[]
  timeline: TimelineEvent[]

  // Actions
  updateMetrics: () => Promise<void>
  acknowledgeAlert: (id: string) => void
  exportTimeline: (format: 'json' | 'csv') => void
}

5. useGpuStore

interface GpuStore {
  // State
  available: boolean
  backend: 'metal' | 'cuda' | 'vulkan' | null
  memory: number
  utilization: number

  // Actions
  initialize: (backend?: string) => Promise<void>
  getStatus: () => Promise<GpuStatus>
}

6. useChatStore

interface ChatStore {
  // State
  messages: Message[]
  isStreaming: boolean
  model: 'sonnet' | 'opus' | 'haiku'

  // Actions
  sendMessage: (content: string) => Promise<void>
  clearHistory: () => void
  changeModel: (model: string) => void
}

Autres Stores

  • useSettingsStore - Configuration globale
  • useThemeStore - Gestion des thèmes
  • useNotificationStore - Toast notifications
  • useTerminalStore - Terminal intégré
  • useGitStore - Opérations Git
  • useSearchStore - Recherche globale
  • useExtensionStore - Extensions Monaco
  • useVoiceStore - Voice control

🔧 TypeScript Services

AutopilotService

class AutopilotService {
  // Start mission
  async startMission(description: string, mode: 'standard' | 'fast'): Promise<Mission>

  // Agent coordination
  async executeAgent(agent: AgentType, context: AgentContext): Promise<AgentResult>

  // FSM management
  transitionState(mission: Mission, from: FSMState, to: FSMState): void

  // Loop detection
  detectLoop(mission: Mission): boolean
}

// Usage
import { autopilotService } from '@/services/autopilot'

const mission = await autopilotService.startMission(
  'Create REST API with JWT',
  'standard'
)

GpuService

class GpuService {
  // Initialize backend
  async initialize(backend?: 'metal' | 'cuda' | 'vulkan'): Promise<void>

  // GPU grep
  async grep(pattern: string, files: string[]): Promise<GrepResult[]>

  // GPU parse
  async parseFile(path: string, language: string): Promise<AstNode>

  // Get status
  async getStatus(): Promise<GpuStatus>
}

ObserverService

class ObserverService {
  // Performance monitoring
  async trackPerformance(metric: PerformanceMetric): Promise<void>

  // Error tracking
  async logError(error: Error, context: ErrorContext): Promise<void>

  // Resource monitoring
  async getResourceUsage(): Promise<ResourceMetrics>

  // Health score
  async calculateHealthScore(): Promise<number>

  // Timeline
  async addTimelineEvent(event: TimelineEvent): Promise<void>
}

ClaudeService

class ClaudeService {
  // Send message
  async sendMessage(
    messages: Message[],
    options?: {
      model?: 'sonnet' | 'opus' | 'haiku'
      temperature?: number
      max_tokens?: number
      stream?: boolean
    }
  ): Promise<Message>

  // Stream message
  streamMessage(
    messages: Message[],
    onChunk: (chunk: string) => void
  ): Promise<void>
}

FileService

class FileService {
  // Read file
  async readFile(path: string): Promise<string>

  // Write file
  async writeFile(path: string, content: string): Promise<void>

  // List directory
  async listDirectory(path: string): Promise<FileEntry[]>

  // Watch directory
  watchDirectory(path: string, onChange: (events: FileEvent[]) => void): () => void
}

⚙️ Configuration API

Configuration File

François stocke sa configuration dans ~/.francois/config.json :

{
  "anthropic_api_key": "sk-ant-xxxxx",
  "default_model": "sonnet",
  "gpu": {
    "enabled": true,
    "backend": "metal",
    "memory_limit": 4096
  },
  "autopilot": {
    "enabled": true,
    "analyst_model": "sonnet",
    "architect_model": "opus",
    "coder_model": "sonnet",
    "reviewer_model": "opus",
    "tester_model": "haiku",
    "devops_model": "sonnet"
  },
  "observer": {
    "enabled": true,
    "timeline_retention": "24h",
    "health_threshold": 50
  },
  "editor": {
    "theme": "francois-dark",
    "font_family": "JetBrains Mono",
    "font_size": 14,
    "tab_size": 2,
    "minimap": true
  },
  "voice": {
    "enabled": false,
    "language": "fr-FR"
  }
}

ConfigService

class ConfigService {
  // Get config value
  get<T>(key: string): T | undefined

  // Set config value
  async set(key: string, value: any): Promise<void>

  // List all config
  async list(): Promise<Record<string, any>>

  // Reset to defaults
  async reset(): Promise<void>
}

// Usage
import { configService } from '@/services/config'

// Get value
const apiKey = configService.get<string>('anthropic_api_key')

// Set value
await configService.set('default_model', 'opus')

// Nested keys
await configService.set('gpu.backend', 'cuda')

📡 Event System

François utilise un système d'événements pour la communication entre composants.

Event Types

type FrancoisEvent =
  | { type: 'file:changed', path: string }
  | { type: 'file:created', path: string }
  | { type: 'file:deleted', path: string }
  | { type: 'mission:started', mission: Mission }
  | { type: 'mission:completed', mission: Mission }
  | { type: 'mission:failed', mission: Mission, error: Error }
  | { type: 'agent:transition', from: AgentType, to: AgentType }
  | { type: 'fsm:transition', from: FSMState, to: FSMState }
  | { type: 'observer:alert', alert: Alert }
  | { type: 'observer:health', score: number }
  | { type: 'gpu:status', status: GpuStatus }

EventBus

class EventBus {
  // Subscribe to events
  on<T extends FrancoisEvent>(
    type: T['type'],
    handler: (event: T) => void
  ): () => void

  // Emit event
  emit<T extends FrancoisEvent>(event: T): void

  // Once
  once<T extends FrancoisEvent>(
    type: T['type'],
    handler: (event: T) => void
  ): void
}

// Usage
import { eventBus } from '@/services/eventBus'

// Subscribe
const unsubscribe = eventBus.on('mission:started', (event) => {
  console.log('Mission started:', event.mission.id)
})

// Emit
eventBus.emit({ type: 'mission:started', mission })

// Cleanup
unsubscribe()

🔐 Types & Interfaces

Core Types

interface Project {
  id: string
  name: string
  path: string
  language: string
  framework?: string
  git?: {
    branch: string
    remote: string
  }
}

interface FileEntry {
  path: string
  name: string
  type: 'file' | 'directory'
  size: number
  modified: number
  language?: string
}

interface Message {
  id: string
  role: 'user' | 'assistant'
  content: string
  timestamp: number
  model?: string
}

interface Mission {
  id: string
  description: string
  complexity: number
  mode: 'standard' | 'fast'
  status: MissionStatus
  fsmState: FSMState
  agents: AgentExecution[]
  startTime: number
  endTime?: number
}

type MissionStatus = 'idle' | 'running' | 'paused' | 'completed' | 'failed'

type FSMState =
  | 'IDLE'
  | 'ANALYZING'
  | 'CLARIFYING'
  | 'PLANNING'
  | 'EXECUTING'
  | 'TESTING'
  | 'FIXING'
  | 'REVIEWING'
  | 'DEPLOYING'
  | 'COMPLETED'

type AgentType =
  | 'analyst'
  | 'architect'
  | 'coder'
  | 'tester'
  | 'reviewer'
  | 'devops'
  | 'orchestrator'
  | 'fullstack'

interface AgentExecution {
  agent: AgentType
  startTime: number
  endTime?: number
  result?: AgentResult
  confidence: number
}

interface ObserverMetrics {
  performance: {
    fps: number
    latency_p50: number
    latency_p95: number
    latency_p99: number
    throughput: number
  }
  resources: {
    cpu: number
    ram: number
    gpu: number
    disk: number
  }
  errors: {
    total: number
    by_level: Record<ErrorLevel, number>
  }
  health: {
    score: number
    status: 'healthy' | 'degraded' | 'critical'
  }
}
💡 Pro Tip

Utilisez TypeScript et activez strict: true dans votre tsconfig.json pour bénéficier de l'autocomplétion complète de l'API François.

📚 Example: Complete Workflow

import { useProjectStore } from '@/stores/project'
import { useAutopilotStore } from '@/stores/autopilot'
import { autopilotService } from '@/services/autopilot'
import { eventBus } from '@/services/eventBus'

async function createFeature() {
  // 1. Load project
  const { loadProject, currentProject } = useProjectStore.getState()
  await loadProject('/path/to/project')

  // 2. Start Autopilot mission
  const mission = await autopilotService.startMission(
    'Add user authentication with JWT',
    'standard'
  )

  // 3. Listen to mission events
  eventBus.on('mission:completed', (event) => {
    console.log('✅ Mission completed:', event.mission.id)
    console.log('Files changed:', event.mission.filesChanged)
  })

  eventBus.on('agent:transition', (event) => {
    console.log(`🤖 Agent transition: ${event.from} → ${event.to}`)
  })

  // 4. Monitor health
  const { updateMetrics, healthScore } = useObserverStore.getState()
  await updateMetrics()

  if (healthScore < 50) {
    console.warn('⚠️ Low health score:', healthScore)
  }
}