Files
helix-engage-server/src/caller/caller-resolution.controller.ts
saridsa2 8c8b1e78b0 feat: caller context cache invalidation endpoint
- 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>
2026-04-18 05:29:56 +05:30

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' };
}
}