mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* fix session last active * Feature/sst (#81) * Use CSS field-sizing for textarea auto-height and abort STT recording on clear * Fix invalid date display in git commits * Use Unix timestamps for git log dates
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import axios from 'axios'
|
|
import { API_BASE_URL } from '@/config'
|
|
|
|
export interface STTModelsResponse {
|
|
models: string[]
|
|
cached: boolean
|
|
}
|
|
|
|
export interface STTStatusResponse {
|
|
enabled: boolean
|
|
configured: boolean
|
|
provider: 'external' | 'builtin'
|
|
model: string
|
|
}
|
|
|
|
export interface STTTranscribeResponse {
|
|
text: string
|
|
}
|
|
|
|
export interface STTErrorResponse {
|
|
error: string
|
|
details?: string
|
|
}
|
|
|
|
export const sttApi = {
|
|
getModels: async (userId = 'default', forceRefresh = false): Promise<STTModelsResponse> => {
|
|
const { data } = await axios.get(`${API_BASE_URL}/api/stt/models`, {
|
|
params: { userId, ...(forceRefresh && { refresh: 'true' }) },
|
|
})
|
|
return data
|
|
},
|
|
|
|
getStatus: async (userId = 'default'): Promise<STTStatusResponse> => {
|
|
const { data } = await axios.get(`${API_BASE_URL}/api/stt/status`, {
|
|
params: { userId },
|
|
})
|
|
return data
|
|
},
|
|
|
|
transcribe: async (
|
|
audioBlob: Blob,
|
|
userId = 'default',
|
|
signal?: AbortSignal
|
|
): Promise<STTTranscribeResponse> => {
|
|
const formData = new FormData()
|
|
|
|
const extension = audioBlob.type.includes('webm') ? 'webm' :
|
|
audioBlob.type.includes('ogg') ? 'ogg' :
|
|
audioBlob.type.includes('mp4') ? 'm4a' : 'webm'
|
|
formData.append('audio', audioBlob, `recording.${extension}`)
|
|
|
|
const { data } = await axios.post<STTTranscribeResponse>(
|
|
`${API_BASE_URL}/api/stt/transcribe`,
|
|
formData,
|
|
{
|
|
params: { userId },
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
signal,
|
|
}
|
|
)
|
|
return data
|
|
},
|
|
}
|