API Reference
Complete reference for Tauri commands and events.
Commands
File Operations
read_file
Read contents of a file.
import { invoke } from '@tauri-apps/api/core'
const content = await invoke('read_file', {
path: '/path/to/file'
})Parameters:
path(string): File path
Returns: string
write_file
Write content to a file.
await invoke('write_file', {
path: '/path/to/file',
content: 'File content'
})Parameters:
path(string): File pathcontent(string): Content to write
Returns: void
delete_file
Delete a file.
await invoke('delete_file', {
path: '/path/to/file'
})Parameters:
path(string): File path
Returns: void
AI Commands
ai_chat
Send chat messages to AI.
const response = await invoke('ai_chat', {
messages: [
{ role: 'user', content: 'Hello' }
],
provider: 'openai'
})Parameters:
messages(Message[]): Chat messagesprovider(string): AI provider nameoptions(object, optional): Additional options
Returns: string (AI response)
ai_stream
Stream AI response.
import { listen } from '@tauri-apps/api/event'
const unlisten = await listen('ai-stream-chunk', (event) => {
console.log('Chunk:', event.payload)
})
await invoke('ai_stream', {
messages: messages
})Parameters:
messages(Message[]): Chat messagesprovider(string): AI provider name
Returns: void (chunks sent via events)
Code Navigation
go_to_definition
Jump to symbol definition.
const location = await invoke('go_to_definition', {
file: '/path/to/file.ts',
line: 10,
column: 5
})Parameters:
file(string): File pathline(number): Line number (1-indexed)column(number): Column number (1-indexed)
Returns: Location object
find_references
Find all symbol references.
const references = await invoke('find_references', {
symbol: 'myFunction',
file: '/path/to/file.ts'
})Parameters:
symbol(string): Symbol namefile(string): File to search in
Returns: Reference[]
Symbol Indexing
index_project
Index all files in project.
const count = await invoke('index_project', {
root: '/path/to/project'
})Parameters:
root(string): Project root path
Returns: number (symbols indexed)
get_symbols
Get symbols in a file.
const symbols = await invoke('get_symbols', {
file: '/path/to/file.ts'
})Parameters:
file(string): File path
Returns: Symbol[]
Events
AI Events
ai-stream-chunk
Emitted during AI streaming.
import { listen } from '@tauri-apps/api/event'
await listen('ai-stream-chunk', (event) => {
const chunk = event.payload as string
// Append to response
})Payload: string (response chunk)
ai-stream-complete
Emitted when streaming completes.
await listen('ai-stream-complete', () => {
console.log('Streaming complete')
})Payload: none
File Events
file-changed
Emitted when a file changes.
await listen('file-changed', (event) => {
const change = event.payload as FileChangeEvent
console.log('File changed:', change.path)
})Payload: FileChangeEvent
path(string): Changed file pathtype(string): Change type (created, modified, deleted)
file-saved
Emitted when a file is saved.
await listen('file-saved', (event) => {
const path = event.payload as string
console.log('File saved:', path)
})Payload: string (file path)
Project Events
project-indexed
Emitted when project indexing completes.
await listen('project-indexed', (event) => {
const stats = event.payload as IndexStats
console.log('Indexed:', stats.count, 'symbols')
})Payload: IndexStats
count(number): Total symbols indexedduration(number): Indexing time in ms
Types
Message
interface Message {
role: 'user' | 'assistant' | 'system'
content: string
}Location
interface Location {
file: string
line: number
column: number
}Symbol
interface Symbol {
name: string
kind: SymbolKind
file: string
range: Range
children?: Symbol[]
}
type SymbolKind =
| 'function'
| 'class'
| 'variable'
| 'interface'
| 'type'Range
interface Range {
start: Position
end: Position
}
interface Position {
line: number
column: number
}Error Handling
Error Types
try {
await invoke('read_file', { path: '/nonexistent' })
} catch (error) {
// Error is a string
console.error('Error:', error)
}Common Errors
| Error | Cause | Solution |
|---|---|---|
| "File not found" | Path doesn't exist | Check file path |
| "Permission denied" | Insufficient permissions | Check file permissions |
| "AI provider error" | Invalid API key | Check API key configuration |
| "Index timeout" | Large project | Increase timeout or reduce scope |
Next Steps
- Frontend Guide - Using commands in React
- Backend Guide - Implementing commands
- Testing Guide - Testing Tauri commands