From fe2ab6010ebe14b507d85c2a44bf2c1681548304 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sun, 19 Apr 2026 00:53:05 -0700 Subject: [PATCH] fix(backend): remove stale TODO-008 comment, add telemetry to suggestions route --- backend/src/lib/telemetry-events.ts | 11 +---------- backend/src/modules/suggestions/routes.ts | 8 +++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/backend/src/lib/telemetry-events.ts b/backend/src/lib/telemetry-events.ts index ab07c45..0c779f3 100644 --- a/backend/src/lib/telemetry-events.ts +++ b/backend/src/lib/telemetry-events.ts @@ -2,16 +2,7 @@ * Telemetry event name constants for all agentic AI features. * * Centralised here so backend routes and web components can reference - * a single source of truth for event names (Phase 0.5). - * - * TODO-008: Wire trackEvent() calls into backend routes - * Priority: medium | Phase: B - * These constants are defined but not yet imported anywhere. Wire them in: - * - agent-actions/routes.ts: AGENT_INBOX_ACTION_APPROVED on approve, - * AGENT_INBOX_ACTION_REJECTED on reject, AGENT_INBOX_BATCH_APPROVED on batch - * - server.ts context-message route: AI_CONTEXT_ENRICHED when source='llm', - * AI_CONTEXT_FALLBACK_USED when source='keyword' or 'generic' - * - Use: import { bufferEvent } from './telemetry.js' then bufferEvent(EVENT_NAME, { ...metadata }) + * a single source of truth for event names. */ // ── MCP ─────────────────────────────────────────────────────── diff --git a/backend/src/modules/suggestions/routes.ts b/backend/src/modules/suggestions/routes.ts index 80ea9a2..0b3d69d 100644 --- a/backend/src/modules/suggestions/routes.ts +++ b/backend/src/modules/suggestions/routes.ts @@ -9,6 +9,8 @@ import { BadRequestError } from '@bytelyst/errors'; import { extractAuth } from '../../lib/auth.js'; import { isFeatureEnabled } from '../../lib/feature-flags.js'; import { PRODUCT_ID } from '../../lib/product-config.js'; +import { trackEvent } from '../../lib/telemetry.js'; +import { ROUTINE_SUGGEST_SHOWN } from '../../lib/telemetry-events.js'; import { generateSuggestions } from './engine.js'; import { GetSuggestionsSchema } from './types.js'; import * as timerRepo from '../timers/repository.js'; @@ -48,6 +50,10 @@ export async function suggestionRoutes(app: FastifyInstance) { offset: 0, }); - return generateSuggestions(completedTimers, routines, parsed.data.maxSuggestions); + const result = generateSuggestions(completedTimers, routines, parsed.data.maxSuggestions); + if (result.suggestions.length > 0) { + trackEvent(ROUTINE_SUGGEST_SHOWN, auth.sub, { count: result.suggestions.length, types: result.suggestions.map(s => s.type) }); + } + return result; }); }