Skip to content

API Reference

Complete reference for Tauri commands and events.

Commands

File Operations

read_file

Read contents of a file.

typescript
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.

typescript
await invoke('write_file', { 
  path: '/path/to/file',
  content: 'File content'
})

Parameters:

  • path (string): File path
  • content (string): Content to write

Returns: void

delete_file

Delete a file.

typescript
await invoke('delete_file', { 
  path: '/path/to/file' 
})

Parameters:

  • path (string): File path

Returns: void

AI Commands

ai_chat

Send chat messages to AI.

typescript
const response = await invoke('ai_chat', { 
  messages: [
    { role: 'user', content: 'Hello' }
  ],
  provider: 'openai'
})

Parameters:

  • messages (Message[]): Chat messages
  • provider (string): AI provider name
  • options (object, optional): Additional options

Returns: string (AI response)

ai_stream

Stream AI response.

typescript
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 messages
  • provider (string): AI provider name

Returns: void (chunks sent via events)

Code Navigation

go_to_definition

Jump to symbol definition.

typescript
const location = await invoke('go_to_definition', {
  file: '/path/to/file.ts',
  line: 10,
  column: 5
})

Parameters:

  • file (string): File path
  • line (number): Line number (1-indexed)
  • column (number): Column number (1-indexed)

Returns: Location object

find_references

Find all symbol references.

typescript
const references = await invoke('find_references', {
  symbol: 'myFunction',
  file: '/path/to/file.ts'
})

Parameters:

  • symbol (string): Symbol name
  • file (string): File to search in

Returns: Reference[]

Symbol Indexing

index_project

Index all files in project.

typescript
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.

typescript
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.

typescript
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.

typescript
await listen('ai-stream-complete', () => {
  console.log('Streaming complete')
})

Payload: none

File Events

file-changed

Emitted when a file changes.

typescript
await listen('file-changed', (event) => {
  const change = event.payload as FileChangeEvent
  console.log('File changed:', change.path)
})

Payload: FileChangeEvent

  • path (string): Changed file path
  • type (string): Change type (created, modified, deleted)

file-saved

Emitted when a file is saved.

typescript
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.

typescript
await listen('project-indexed', (event) => {
  const stats = event.payload as IndexStats
  console.log('Indexed:', stats.count, 'symbols')
})

Payload: IndexStats

  • count (number): Total symbols indexed
  • duration (number): Indexing time in ms

Types

Message

typescript
interface Message {
  role: 'user' | 'assistant' | 'system'
  content: string
}

Location

typescript
interface Location {
  file: string
  line: number
  column: number
}

Symbol

typescript
interface Symbol {
  name: string
  kind: SymbolKind
  file: string
  range: Range
  children?: Symbol[]
}

type SymbolKind = 
  | 'function' 
  | 'class' 
  | 'variable' 
  | 'interface' 
  | 'type'

Range

typescript
interface Range {
  start: Position
  end: Position
}

interface Position {
  line: number
  column: number
}

Error Handling

Error Types

typescript
try {
  await invoke('read_file', { path: '/nonexistent' })
} catch (error) {
  // Error is a string
  console.error('Error:', error)
}

Common Errors

ErrorCauseSolution
"File not found"Path doesn't existCheck file path
"Permission denied"Insufficient permissionsCheck file permissions
"AI provider error"Invalid API keyCheck API key configuration
"Index timeout"Large projectIncrease timeout or reduce scope

Next Steps

Released under the MIT License.