From e2965ebdd2698d096e2500985bee6705448f38f4 Mon Sep 17 00:00:00 2001 From: Novus Bot Date: Sun, 26 Apr 2026 11:42:27 -0400 Subject: [PATCH] Instrument Pendo Track Agent --- src/components/Chat/ChatWidget.tsx | 25 +++++++++++++++++++++++++ src/global.d.ts | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/components/Chat/ChatWidget.tsx b/src/components/Chat/ChatWidget.tsx index d219cb6..8c201a8 100644 --- a/src/components/Chat/ChatWidget.tsx +++ b/src/components/Chat/ChatWidget.tsx @@ -12,6 +12,8 @@ interface Message { const API_KEY_STORAGE = 'groq-api-key'; +const PENDO_AGENT_ID = '175tdkEo-JuHMRNosvR28MCawKc'; + export function ChatWidget() { const [isOpen, setIsOpen] = useState(false); const [messages, setMessages] = useState([]); @@ -21,6 +23,7 @@ export function ChatWidget() { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const messagesEndRef = useRef(null); + const conversationIdRef = useRef(crypto.randomUUID()); const { objectives, teams, individuals, selectedQuarter } = useOKR(); const { currentUser, currentOrganization } = useAuth(); @@ -53,6 +56,7 @@ export function ChatWidget() { localStorage.removeItem(API_KEY_STORAGE); setApiKey(''); setMessages([]); + conversationIdRef.current = crypto.randomUUID(); }; const handleSend = async () => { @@ -60,11 +64,22 @@ export function ChatWidget() { if (!trimmed || isLoading) return; const userMessage: Message = { role: 'user', content: trimmed }; + const promptMessageId = crypto.randomUUID(); setMessages((prev) => [...prev, userMessage]); setInput(''); setError(''); setIsLoading(true); + if (typeof pendo !== 'undefined') { + pendo.trackAgent('prompt', { + agentId: PENDO_AGENT_ID, + conversationId: conversationIdRef.current, + messageId: promptMessageId, + content: trimmed, + suggestedPrompt: false, + }); + } + try { const systemPrompt = buildSystemPrompt({ objectives, @@ -83,6 +98,16 @@ export function ChatWidget() { const response = await sendChatMessage(history, apiKey); setMessages((prev) => [...prev, { role: 'assistant', content: response }]); + + if (typeof pendo !== 'undefined') { + pendo.trackAgent('agent_response', { + agentId: PENDO_AGENT_ID, + conversationId: conversationIdRef.current, + messageId: crypto.randomUUID(), + content: response, + modelUsed: 'llama-3.3-70b-versatile', + }); + } } catch (err) { const msg = err instanceof Error ? err.message : 'Something went wrong.'; setError(msg); diff --git a/src/global.d.ts b/src/global.d.ts index 873aa01..4df8d51 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1 +1,4 @@ -declare var pendo: any; +declare var pendo: { + trackAgent: (eventType: string, metadata: object) => void; + [key: string]: any; +};