mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
- CallerContextService: added invalidateCache(leadId) method - CallerResolutionController: POST /api/caller/invalidate-context endpoint — frontend calls after appointment mutations to bust stale AI context cache Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { Controller, Post, Body, Headers, HttpException, HttpStatus, Logger } from '@nestjs/common';
|
|
import { CallerResolutionService } from './caller-resolution.service';
|
|
import { CallerContextService } from './caller-context.service';
|
|
|
|
@Controller('api/caller')
|
|
export class CallerResolutionController {
|
|
private readonly logger = new Logger(CallerResolutionController.name);
|
|
|
|
constructor(
|
|
private readonly resolution: CallerResolutionService,
|
|
private readonly callerContext: CallerContextService,
|
|
) {}
|
|
|
|
@Post('resolve')
|
|
async resolve(
|
|
@Body('phone') phone: string,
|
|
@Headers('authorization') auth: string,
|
|
) {
|
|
if (!phone) {
|
|
throw new HttpException('phone is required', HttpStatus.BAD_REQUEST);
|
|
}
|
|
if (!auth) {
|
|
throw new HttpException('Authorization header required', HttpStatus.UNAUTHORIZED);
|
|
}
|
|
|
|
this.logger.log(`[RESOLVE] Resolving caller: ${phone}`);
|
|
const result = await this.resolution.resolve(phone, auth);
|
|
|
|
// Pre-warm caller context cache so the AI chat has it ready
|
|
if (result.leadId) {
|
|
this.callerContext.prewarm(result.leadId, result.patientId, auth);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
@Post('invalidate-context')
|
|
async invalidateContext(@Body('leadId') leadId: string) {
|
|
if (!leadId) {
|
|
throw new HttpException('leadId is required', HttpStatus.BAD_REQUEST);
|
|
}
|
|
await this.callerContext.invalidateCache(leadId);
|
|
return { status: 'ok' };
|
|
}
|
|
}
|