Preparing your workspace...

assistant-chat.tsx2.5k
utils.ts850
button.tsx720
Quick Actions
codmirDevelopers
MarketplaceMy Apps
Go to codmirSign In
Back to AI Docs

Client SDK

React hooks and a client library for integrating AI features into your application. The SDK handles streaming, state management, and error handling.

Installation

The AI client is included in the web app. Import from the library:

// Hooks
import { useAIChat } from '@/hooks/use-ai-chat'
import { useAITask } from '@/hooks/use-ai-task'

// Direct client
import { getAIClient, AIClient } from '@/lib/ai/client'

useAIChat

Hook for streaming chat with AI. Handles message state, streaming, and session management.

Options

OptionTypeDescription
projectIdstringEnable knowledge-aware responses
provider'openai' | 'anthropic'AI provider (default: openai)
modelstringModel ID (e.g., gpt-5)
systemPromptstringCustom system prompt
temperaturenumberResponse randomness (0-2)
onChunk(chunk) => voidCalled on each stream chunk
onComplete(content, sessionId) => voidCalled when stream completes
onError(error) => voidCalled on error

Return Values

const {
  messages,           // Message[] - conversation history
  isStreaming,        // boolean - is currently streaming
  sessionId,          // string | null - current session ID
  error,              // Error | null - last error
  sendMessage,        // (content: string) => Promise<void>
  stopStream,         // () => void - abort current stream
  clearMessages,      // () => void - clear conversation
  setInitialMessages, // (messages: Message[]) => void
  addSystemMessage,   // (content: string) => void
} = useAIChat(options)

useAITask

Hook for dispatching and tracking AI tasks like project analysis and knowledge generation.

Options

OptionTypeDescription
pollIntervalnumberStatus poll interval (ms, default: 3000)
autoPollbooleanAuto-start polling (default: true)
onStatusChange(status) => voidCalled on status change
onComplete(status) => voidCalled on task completion
onError(error, status?) => voidCalled on error

Return Values

const {
  task,                  // TaskStatus | null
  isPolling,             // boolean
  error,                 // Error | null
  dispatch,              // (request: TaskRequest) => Promise<TaskStatus>
  analyzeProject,        // (projectId, repoUrl?, branch?) => Promise<TaskStatus>
  generateKnowledgeBase, // (projectId, repoUrl?, branch?) => Promise<TaskStatus>
  startPolling,          // (taskId: string) => void
  stopPolling,           // () => void
  refreshStatus,         // () => Promise<TaskStatus | null>
} = useAITask(options)

AIClient Class

For non-React environments or custom implementations, use the client directly.

import { getAIClient, AIClient } from '@/lib/ai/client'

// Use singleton
const client = getAIClient()

// Or create custom instance
const customClient = new AIClient({
  baseUrl: 'https://testing.codmir.com',
  apiKey: 'your-api-key',
  timeout: 900000, // 15 minutes
})

// Methods
await client.chat(request)           // ChatResponse
client.streamChat(request)           // AsyncGenerator<StreamChunk>
await client.complete(request)       // { text, model }
await client.searchKnowledge(projectId, query, options)
await client.getProjectContext(projectId, query)
await client.dispatchTask(request)   // TaskStatus
await client.getTaskStatus(taskId)   // TaskStatus
await client.healthCheck()           // { status, service }

TypeScript Types

interface Message {
  id: string
  role: 'user' | 'assistant' | 'system'
  content: string
  createdAt: Date
  isStreaming?: boolean
}

interface ChatRequest {
  sessionId?: string
  messages: ChatMessage[]
  provider?: 'openai' | 'anthropic'
  model?: string
  temperature?: number
  maxTokens?: number
  systemPrompt?: string
  projectId?: string
}

interface TaskRequest {
  type: 'analyze-project' | 'generate-knowledge-base'
  projectId: string
  repoUrl?: string
  branch?: string
  config?: Record<string, unknown>
}

interface TaskStatus {
  id: string
  projectId: string
  type: string
  status: 'pending' | 'queued' | 'running' | 'completed' | 'failed'
  result?: Record<string, unknown>
  error?: string
  createdAt: string
  startedAt?: string
  completedAt?: string
}
Tasks APIArchitecture

Documentation

  • Getting Started
  • API Reference
  • SDK & CLI
  • Webhooks
  • Guides

Marketplace

  • Browse Apps
  • Featured Apps
  • Official Apps
  • Submit Your App

Resources

  • Community
  • Discord
  • GitHub
  • Blog

Company

  • About codmir
  • Careers
  • Status
  • Contact
codmirDevelopers
TermsPrivacyAPI TermsCodmirâ„¢ 2026. All rights reserved.