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>
This commit is contained in:
2026-04-18 05:29:56 +05:30
parent 77b3e917db
commit 8c8b1e78b0
2 changed files with 16 additions and 0 deletions

View File

@@ -78,6 +78,13 @@ export class CallerContextService {
return ctx; return ctx;
} }
async invalidateCache(leadId: string): Promise<void> {
if (!leadId) return;
const cacheKey = `${CACHE_KEY_PREFIX}${leadId}`;
await this.session.deleteCache(cacheKey).catch(() => {});
this.logger.log(`[CALLER-CTX] Cache invalidated for ${leadId}`);
}
// Fire-and-forget pre-warm — called from caller resolution // Fire-and-forget pre-warm — called from caller resolution
// so the cache is hot when the AI stream fires seconds later. // so the cache is hot when the AI stream fires seconds later.
prewarm(leadId: string, patientId: string, auth: string): void { prewarm(leadId: string, patientId: string, auth: string): void {

View File

@@ -33,4 +33,13 @@ export class CallerResolutionController {
return result; 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' };
}
} }