chore(config): update speaches config and ignore sveltekit dashboard
- Simplified .env.example to use localhost SPEACHES_URL - Removed unused prod_url from SpeachesSettings config - Added dashboard node_modules and build dirs to .gitignore - Streamlines local development setup
This commit is contained in:
50
dashboard/src/lib/api.ts
Normal file
50
dashboard/src/lib/api.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { CallSummary, DeviceStatus, GatewayEvent, GatewayStatus, HealthStatus } from './types';
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(path);
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export async function fetchGatewayStatus(): Promise<GatewayStatus> {
|
||||
return get<GatewayStatus>('/');
|
||||
}
|
||||
|
||||
export async function fetchHealth(): Promise<HealthStatus> {
|
||||
return get<HealthStatus>('/health');
|
||||
}
|
||||
|
||||
export async function fetchActiveCalls(): Promise<CallSummary[]> {
|
||||
return get<CallSummary[]>('/api/calls/active');
|
||||
}
|
||||
|
||||
export async function fetchDevices(): Promise<DeviceStatus[]> {
|
||||
return get<DeviceStatus[]>('/api/devices');
|
||||
}
|
||||
|
||||
export async function hangupCall(callId: string): Promise<void> {
|
||||
const res = await fetch(`/api/calls/${callId}/hangup`, { method: 'POST' });
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
||||
export function connectEventStream(
|
||||
onEvent: (e: GatewayEvent) => void,
|
||||
onClose: () => void,
|
||||
): () => void {
|
||||
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const ws = new WebSocket(`${proto}//${location.host}/ws/events`);
|
||||
|
||||
ws.onmessage = (msg) => {
|
||||
try {
|
||||
const event = JSON.parse(msg.data as string) as GatewayEvent;
|
||||
onEvent(event);
|
||||
} catch {
|
||||
// malformed frame — ignore
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = () => onClose();
|
||||
ws.onerror = () => onClose();
|
||||
|
||||
return () => ws.close();
|
||||
}
|
||||
74
dashboard/src/lib/types.ts
Normal file
74
dashboard/src/lib/types.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
export interface GatewayStatus {
|
||||
name: string;
|
||||
version: string;
|
||||
status: string;
|
||||
uptime: number;
|
||||
active_calls: number;
|
||||
trunk: {
|
||||
registered: boolean;
|
||||
host?: string;
|
||||
mock?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface HealthStatus {
|
||||
status: 'healthy' | 'degraded';
|
||||
gateway: string;
|
||||
sip_engine: string;
|
||||
sip_trunk: {
|
||||
registered: boolean;
|
||||
host?: string;
|
||||
mock?: boolean;
|
||||
reason?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DeviceStatus {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
is_online: boolean;
|
||||
last_seen: string;
|
||||
can_receive_call: boolean;
|
||||
}
|
||||
|
||||
export type CallStatus =
|
||||
| 'initiating'
|
||||
| 'ringing'
|
||||
| 'connected'
|
||||
| 'navigating_ivr'
|
||||
| 'on_hold'
|
||||
| 'human_detected'
|
||||
| 'transferring'
|
||||
| 'bridged'
|
||||
| 'completed'
|
||||
| 'failed'
|
||||
| 'cancelled';
|
||||
|
||||
export type AudioType =
|
||||
| 'silence'
|
||||
| 'music'
|
||||
| 'ivr_prompt'
|
||||
| 'live_human'
|
||||
| 'ringing'
|
||||
| 'dtmf'
|
||||
| 'unknown';
|
||||
|
||||
export interface CallSummary {
|
||||
call_id: string;
|
||||
remote_number: string;
|
||||
status: CallStatus;
|
||||
mode: string;
|
||||
duration: number;
|
||||
hold_time: number;
|
||||
audio_type: AudioType;
|
||||
intent?: string;
|
||||
}
|
||||
|
||||
export interface GatewayEvent {
|
||||
type: string;
|
||||
call_id?: string;
|
||||
timestamp: string;
|
||||
data: Record<string, unknown>;
|
||||
message: string;
|
||||
}
|
||||
Reference in New Issue
Block a user