mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 18:08:16 +00:00
feat(onboarding/phase-1): admin-editable telephony, ai, and setup-state config
Phase 1 of hospital onboarding & self-service plan
(docs/superpowers/plans/2026-04-06-hospital-onboarding-self-service.md).
Backend foundations to support the upcoming staff-portal Settings hub and
6-step setup wizard. No frontend in this phase.
New config services (mirroring ThemeService / WidgetConfigService):
- SetupStateService — tracks completion of 6 wizard steps; isWizardRequired()
drives the post-login redirect
- TelephonyConfigService — Ozonetel + Exotel + SIP, replaces 8 env vars,
seeds from env on first boot, masks secrets on GET,
'***masked***' sentinel on PUT means "keep existing"
- AiConfigService — provider, model, temperature, system prompt addendum;
API keys remain in env
New endpoints under /api/config:
- GET /api/config/setup-state returns state + wizardRequired flag
- PUT /api/config/setup-state/steps/:step mark step complete/incomplete
- POST /api/config/setup-state/dismiss dismiss wizard
- POST /api/config/setup-state/reset
- GET /api/config/telephony masked
- PUT /api/config/telephony
- POST /api/config/telephony/reset
- GET /api/config/ai
- PUT /api/config/ai
- POST /api/config/ai/reset
ConfigThemeModule is now @Global() so the new sidecar config services are
injectable from AuthModule, OzonetelAgentModule, MaintModule without creating
a circular dependency (ConfigThemeModule already imports AuthModule for
SessionService).
Migrated 11 env-var read sites to use the new services:
- ozonetel-agent.service: exotel API + ozonetel did/sipId via read-through getters
- ozonetel-agent.controller: defaultAgentId/Password/SipId via getters
- kookoo-ivr.controller: sipId/callerId via getters
- auth.controller: OZONETEL_AGENT_PASSWORD (login + logout)
- agent-config.service: sipDomain/wsPort/campaignName via getters
- maint.controller: forceReady + unlockAgent
- ai-provider: createAiModel and isAiConfigured refactored to pure factories
taking AiProviderOpts; no more ConfigService dependency
- widget-chat.service, recordings.service, ai-enrichment.service,
ai-chat.controller, ai-insight.consumer, call-assist.service: each builds
the AI model from AiConfigService.getConfig() + ConfigService API keys
Hot-reload guarantee: every consumer reads via a getter or builds per-call,
so admin updates take effect without sidecar restart. WidgetChatService
specifically rebuilds the model on each streamReply().
Bug fix bundled: dropped widget.json.hospitalName field (the original
duplicate that started this whole thread). WidgetConfigService now reads
brand.hospitalName from ThemeService at the 2 generateKey call sites.
Single source of truth for hospital name is workspace branding.
First-boot env seeding: TelephonyConfigService and AiConfigService both
copy their respective env vars into a fresh data/*.json on onModuleInit if
the file doesn't exist. Existing deployments auto-migrate without manual
intervention.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,53 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { ThemeController } from './theme.controller';
|
||||
import { ThemeService } from './theme.service';
|
||||
import { WidgetKeysService } from './widget-keys.service';
|
||||
import { WidgetConfigService } from './widget-config.service';
|
||||
import { WidgetConfigController } from './widget-config.controller';
|
||||
import { SetupStateService } from './setup-state.service';
|
||||
import { SetupStateController } from './setup-state.controller';
|
||||
import { TelephonyConfigService } from './telephony-config.service';
|
||||
import { TelephonyConfigController } from './telephony-config.controller';
|
||||
import { AiConfigService } from './ai-config.service';
|
||||
import { AiConfigController } from './ai-config.controller';
|
||||
|
||||
// Central config module — owns everything that lives in data/*.json and is
|
||||
// editable from the admin portal. Theme today, widget config now, rules later.
|
||||
// Central config module — owns everything in data/*.json that's editable
|
||||
// from the admin portal. Today: theme, widget, setup-state, telephony, ai.
|
||||
//
|
||||
// Marked @Global() so the 3 new sidecar config services (setup-state, telephony,
|
||||
// ai) are injectable from any module without explicit import wiring. Without this,
|
||||
// AuthModule + OzonetelAgentModule + MaintModule would all need to import
|
||||
// ConfigThemeModule, which would create a circular dependency with AuthModule
|
||||
// (ConfigThemeModule already imports AuthModule for SessionService).
|
||||
//
|
||||
// AuthModule is imported because WidgetKeysService depends on SessionService
|
||||
// (Redis-backed cache for site key storage).
|
||||
// (Redis-backed cache for widget site key storage).
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [AuthModule],
|
||||
controllers: [ThemeController, WidgetConfigController],
|
||||
providers: [ThemeService, WidgetKeysService, WidgetConfigService],
|
||||
exports: [ThemeService, WidgetKeysService, WidgetConfigService],
|
||||
controllers: [
|
||||
ThemeController,
|
||||
WidgetConfigController,
|
||||
SetupStateController,
|
||||
TelephonyConfigController,
|
||||
AiConfigController,
|
||||
],
|
||||
providers: [
|
||||
ThemeService,
|
||||
WidgetKeysService,
|
||||
WidgetConfigService,
|
||||
SetupStateService,
|
||||
TelephonyConfigService,
|
||||
AiConfigService,
|
||||
],
|
||||
exports: [
|
||||
ThemeService,
|
||||
WidgetKeysService,
|
||||
WidgetConfigService,
|
||||
SetupStateService,
|
||||
TelephonyConfigService,
|
||||
AiConfigService,
|
||||
],
|
||||
})
|
||||
export class ConfigThemeModule {}
|
||||
|
||||
Reference in New Issue
Block a user