2026-05-02 03:18:47 +02:00
|
|
|
/**
|
|
|
|
|
* Stream API Client
|
|
|
|
|
*
|
|
|
|
|
* API functions for transcription and extraction operations.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import api from "./client";
|
|
|
|
|
import { isMockMode } from "@/lib/mock-data";
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Types
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
export interface StreamChunkRequest {
|
|
|
|
|
channel_name: string;
|
|
|
|
|
audio_data: string; // Base64 encoded
|
|
|
|
|
chunk_index: number;
|
|
|
|
|
is_final?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StreamChunkResponse {
|
|
|
|
|
status: string;
|
|
|
|
|
chunk_index: number;
|
|
|
|
|
queued: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StreamCompleteRequest {
|
|
|
|
|
channel_name: string;
|
|
|
|
|
session_id?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StreamCompleteResponse {
|
|
|
|
|
status: string;
|
|
|
|
|
channel_name: string;
|
|
|
|
|
total_chunks: number;
|
|
|
|
|
transcription_id?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ExtractionRequest {
|
|
|
|
|
content: string;
|
|
|
|
|
extraction_type: "tasks" | "decisions" | "action_items" | "summary";
|
|
|
|
|
context?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ExtractionResponse {
|
|
|
|
|
extraction_type: string;
|
|
|
|
|
results: Record<string, unknown>[];
|
|
|
|
|
confidence: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TranscriptionStats {
|
|
|
|
|
total_transcriptions: number;
|
|
|
|
|
active_channels: number;
|
|
|
|
|
chunks_processed: number;
|
|
|
|
|
avg_processing_time_ms: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ChannelPermissions {
|
|
|
|
|
channel_name: string;
|
|
|
|
|
can_transcribe: boolean;
|
|
|
|
|
can_extract: boolean;
|
|
|
|
|
rate_limit?: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// API Client
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
|
|
export const streamApi = {
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// TRANSCRIPTION ENDPOINTS
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Submit an audio chunk for transcription
|
|
|
|
|
*/
|
2026-06-29 05:38:21 +02:00
|
|
|
submitChunk: async (
|
|
|
|
|
request: StreamChunkRequest,
|
|
|
|
|
): Promise<StreamChunkResponse> => {
|
2026-05-02 03:18:47 +02:00
|
|
|
if (isMockMode()) {
|
|
|
|
|
return {
|
|
|
|
|
status: "queued",
|
|
|
|
|
chunk_index: request.chunk_index,
|
|
|
|
|
queued: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-06-29 05:38:21 +02:00
|
|
|
const { data } = await api.post<StreamChunkResponse>(
|
|
|
|
|
"/stream/chunk",
|
|
|
|
|
request,
|
|
|
|
|
);
|
2026-05-02 03:18:47 +02:00
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Complete a transcription session
|
|
|
|
|
*/
|
2026-06-29 05:38:21 +02:00
|
|
|
complete: async (
|
|
|
|
|
request: StreamCompleteRequest,
|
|
|
|
|
): Promise<StreamCompleteResponse> => {
|
2026-05-02 03:18:47 +02:00
|
|
|
if (isMockMode()) {
|
|
|
|
|
return {
|
|
|
|
|
status: "completed",
|
|
|
|
|
channel_name: request.channel_name,
|
|
|
|
|
total_chunks: 10,
|
|
|
|
|
transcription_id: `trans-${Date.now()}`,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-06-29 05:38:21 +02:00
|
|
|
const { data } = await api.post<StreamCompleteResponse>(
|
|
|
|
|
"/stream/complete",
|
|
|
|
|
request,
|
|
|
|
|
);
|
2026-05-02 03:18:47 +02:00
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// EXTRACTION ENDPOINTS
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract structured information from content
|
|
|
|
|
*/
|
|
|
|
|
extract: async (request: ExtractionRequest): Promise<ExtractionResponse> => {
|
|
|
|
|
if (isMockMode()) {
|
|
|
|
|
return {
|
|
|
|
|
extraction_type: request.extraction_type,
|
|
|
|
|
results: [],
|
|
|
|
|
confidence: 0.85,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-06-29 05:38:21 +02:00
|
|
|
const { data } = await api.post<ExtractionResponse>(
|
|
|
|
|
"/stream/extract",
|
|
|
|
|
request,
|
|
|
|
|
);
|
2026-05-02 03:18:47 +02:00
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// STATS & PERMISSIONS
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get transcription statistics
|
|
|
|
|
*/
|
|
|
|
|
getStats: async (): Promise<TranscriptionStats> => {
|
|
|
|
|
if (isMockMode()) {
|
|
|
|
|
return {
|
|
|
|
|
total_transcriptions: 100,
|
|
|
|
|
active_channels: 5,
|
|
|
|
|
chunks_processed: 1500,
|
|
|
|
|
avg_processing_time_ms: 250,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const { data } = await api.get<TranscriptionStats>("/stream/stats");
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all channel permissions
|
|
|
|
|
*/
|
|
|
|
|
getPermissions: async (): Promise<ChannelPermissions[]> => {
|
|
|
|
|
if (isMockMode()) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const { data } = await api.get<ChannelPermissions[]>("/stream/permissions");
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get permissions for a specific channel
|
|
|
|
|
*/
|
2026-06-29 05:38:21 +02:00
|
|
|
getChannelPermissions: async (
|
|
|
|
|
channelName: string,
|
|
|
|
|
): Promise<ChannelPermissions> => {
|
2026-05-02 03:18:47 +02:00
|
|
|
if (isMockMode()) {
|
|
|
|
|
return {
|
|
|
|
|
channel_name: channelName,
|
|
|
|
|
can_transcribe: true,
|
|
|
|
|
can_extract: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-06-29 05:38:21 +02:00
|
|
|
const { data } = await api.get<ChannelPermissions>(
|
|
|
|
|
`/stream/permissions/channel/${channelName}`,
|
|
|
|
|
);
|
2026-05-02 03:18:47 +02:00
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
};
|