build(ui): expand application shell and implement administrative dashboard pages

This commit significantly expands the application's routing, navigation, and administrative capabilities. It introduces several new functional modules and refines the core layout for a more professional, dashboard-oriented experience.

- **Routing & Navigation**:
  - Added routes for `wallboard`, `call-center`, `call-center/calls`, and `chat-questions`.
  - Updated `SidebarComponent` to include all new navigation items.
  - Enhanced `LayoutComponent` with dynamic navigation based on user roles (admin vs. user).
- **New Administrative Pages**:
  - `WallboardPage`: Implements a real-time KPI dashboard with call activity trends and outcome distributions.
  - `CallCenterPage`: Provides a symbolic interface for managing call center connectivity and synchronization.
  - `CallCenterCallsPage`: Implements a call history retrieval interface with filtering capabilities.
  - `ChatQuestionsPage`: Adds a module for reviewing user questions from web and mobile channels.
- **Core Infrastructure & Refinement**:
  - Updated `AppConfig` to include an `APP_INITIALIZER` for validating user identity via `AuthService` on startup.
  - Refined `HomeComponent` layout to a "Claude-style" continuous chat column.
  - Implemented global themed scrollbars and integrated the 'Lahze' font family.
  - Added `proxy.conf.json` and updated `angular.json` to support local backend development.
- **Documentation**:
  - Added comprehensive API handoff guides for frontend-backend connection and MVP API catalog.
This commit is contained in:
Peyman Honarjoo
2026-10-10 00:20:00 +03:30
parent 0b5a882ecb
commit ff7fcbc4bb
71 changed files with 9148 additions and 780 deletions
@@ -1,9 +1,13 @@
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { firstValueFrom, Observable } from 'rxjs';
import { VOICE_STREAM_CONFIG } from './voice-stream.types';
import { firstValueFrom, race, throwError, Observable } from 'rxjs';
import { delay } from 'rxjs/operators';
import { VOICE_STREAM_CONFIG, VoiceSessionStatus } from './voice-stream.types';
/** Error envelope from the catalog: { error: { code, message, request_id, retryable, details } }. */
/** The voice helper's HTTP deadline: a client timeout never means the server rolled back. */
const REQUEST_DEADLINE_MS = 5000;
/** Error envelope from the contract: { error: { code, message, request_id, retryable, details } }. */
export class VoiceApiError extends Error {
constructor(
readonly status: number,
@@ -24,14 +28,26 @@ export interface MeResponse {
}
export interface ConfigurationResponse {
capabilities: { text: boolean; voice: boolean; captions: boolean };
revision: number;
assistant_name: string;
instruction: string;
capabilities: {
text: boolean;
voice: boolean;
captions: boolean;
supported_upload_types?: string[];
max_upload_bytes?: number;
max_pdf_pages?: number;
};
}
export interface ConversationResponse {
id: string;
mode: 'voice';
title: string;
title?: string;
status: string;
access_epoch?: number;
created_at?: string;
}
export interface VoiceSessionResponse {
@@ -43,10 +59,15 @@ export interface VoiceSessionResponse {
poll_url: string;
}
/** V02: status + safe diagnostics for a reserved/connected session. */
export interface VoiceSessionPollResponse extends VoiceSessionStatus {
recent_tool_results?: unknown[];
}
/**
* Thin client for the endpoints the live voice call needs (A03, F01, C01, V01, V04).
* Uses HttpClient so the app's existing interceptors (401 → login redirect, etc.) still apply.
* Auth is the HttpOnly `rag_session` cookie; state-changing calls also need `X-CSRF-Token`.
* Thin client for the endpoints the live voice call needs (A03, F01, C01, V01, V02, V03, V04).
* Auth is the HttpOnly `rag_session` cookie (same-origin proxy); state-changing calls also need
* `X-CSRF-Token`. C01/V01 are idempotent through their JSON `client_request_id`, never headers.
*/
@Injectable({ providedIn: 'root' })
export class VoiceApiService {
@@ -55,50 +76,78 @@ export class VoiceApiService {
/** A03: identity + a fresh CSRF token. 401 AUTH_REQUIRED when not logged in. */
me(): Promise<MeResponse> {
return this.send(this.http.get<MeResponse>(this.url('/me'), { withCredentials: true }));
return this.send(this.http.get<MeResponse>(this.url('/me'), this.readOptions()));
}
/** F01: capabilities (the UI must check `voice` before offering a call). */
configuration(): Promise<ConfigurationResponse> {
return this.send(
this.http.get<ConfigurationResponse>(this.url('/configuration'), { withCredentials: true }),
);
return this.send(this.http.get<ConfigurationResponse>(this.url('/configuration'), this.readOptions()));
}
/** C01: only `mode: "voice"` exists in the MVP. */
createConversation(csrf: string, title: string): Promise<ConversationResponse> {
/** C01: only `mode: "voice"` exists in the MVP. `clientRequestId` makes replays return the same conversation. */
createConversation(csrf: string, title: string, clientRequestId: string): Promise<ConversationResponse> {
return this.send(
this.http.post<ConversationResponse>(
this.url('/conversations'),
{ client_request_id: crypto.randomUUID(), mode: 'voice', title },
this.options(csrf),
{ client_request_id: clientRequestId, mode: 'voice', title },
this.writeOptions(csrf),
),
);
}
/** V01: reserves a live session; connect the WebSocket to the returned `stream_path`. */
createVoiceSession(csrf: string, conversationId: string): Promise<VoiceSessionResponse> {
createVoiceSession(
csrf: string,
conversationId: string,
clientRequestId: string,
): Promise<VoiceSessionResponse> {
return this.send(
this.http.post<VoiceSessionResponse>(
this.url('/voice/sessions'),
{ conversation_id: conversationId, client_request_id: crypto.randomUUID() },
this.options(csrf),
{ conversation_id: conversationId, client_request_id: clientRequestId },
this.writeOptions(csrf),
),
);
}
/** V04: closes the session (idempotent from the UI's point of view). */
/** V02: status + safe diagnostics (no secrets). */
pollVoiceSession(csrf: string, sessionId: string): Promise<VoiceSessionPollResponse> {
return this.send(
this.http.get<VoiceSessionPollResponse>(
this.url(`/voice/sessions/${encodeURIComponent(sessionId)}`),
this.readOptions(),
),
);
}
/**
* V03: reconcile a reservation by its C01/V01 `client_request_id` — used after an
* ambiguous (timeout / network) reserve, or after a reload. Never opens a new provider
* connection: `null` means the attempt was never reserved.
*/
getVoiceSessionByRequest(csrf: string, clientRequestId: string): Promise<VoiceSessionResponse | null> {
return this.send(
this.http
.get<VoiceSessionResponse>(
this.url(`/voice/sessions/by-request/${encodeURIComponent(clientRequestId)}`),
this.readOptions(),
)
.pipe(this.mapNotFoundToNull()),
);
}
/** V04: closes the session explicitly (no body). */
async closeVoiceSession(csrf: string, sessionId: string): Promise<void> {
await this.send(
this.http.post<unknown>(
this.url(`/voice/sessions/${encodeURIComponent(sessionId)}/close`),
{},
this.options(csrf),
this.writeOptions(csrf),
),
);
}
/** `wss://…` URL for a V01 `stream_path`. */
/** `wss://…` URL for a V01 `stream_path` (same origin as the UI). */
streamUrl(streamPath: string): string {
const base = this.config.apiOrigin || window.location.origin;
const url = new URL(streamPath, base);
@@ -112,22 +161,56 @@ export class VoiceApiService {
return `${this.config.apiOrigin}${this.config.apiBase}${path}`;
}
private options(csrf: string) {
private readOptions() {
return { withCredentials: true, headers: new HttpHeaders({ 'X-Request-ID': crypto.randomUUID() }) };
}
private writeOptions(csrf: string) {
return {
withCredentials: true,
headers: new HttpHeaders({ 'X-CSRF-Token': csrf, 'X-Request-ID': crypto.randomUUID() }),
headers: new HttpHeaders({
'X-CSRF-Token': csrf,
'X-Request-ID': crypto.randomUUID(),
}),
};
}
private mapNotFoundToNull<T>() {
return (source: Observable<T>): Observable<T | null> =>
new Observable<T | null>((observer) => {
const sub = source.subscribe({
next: (value) => observer.next(value),
error: (err: unknown) => {
if (err instanceof HttpErrorResponse && err.status === 404) observer.next(null);
else observer.error(err);
observer.complete();
},
complete: () => observer.complete(),
});
return () => sub.unsubscribe();
});
}
private async send<T>(request: Observable<T>): Promise<T> {
try {
return await firstValueFrom(request);
return await firstValueFrom(this.withDeadline(request));
} catch (err) {
throw this.toApiError(err);
}
}
/** A short deadline keeps the UI responsive; the caller reconciles the uncertain outcome. */
private withDeadline<T>(request: Observable<T>): Observable<T> {
return race(
request,
throwError(() => new VoiceApiError(0, 'TIMEOUT', 'request-deadline')).pipe(
delay(REQUEST_DEADLINE_MS),
),
);
}
private toApiError(err: unknown): VoiceApiError {
if (err instanceof VoiceApiError) return err; // deadline / already-normalized error
if (err instanceof HttpErrorResponse) {
const envelope = (err.error as { error?: Record<string, unknown> } | null)?.error;
return new VoiceApiError(
@@ -140,4 +223,4 @@ export class VoiceApiService {
}
return new VoiceApiError(0, 'UNKNOWN', err instanceof Error ? err.message : 'unknown error');
}
}
}