Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/components/Chat/ChatWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { sendChatMessage } from '../../utils/chatApi';
import { buildSystemPrompt } from '../../utils/buildSystemPrompt';
import { ChatMessage } from './ChatMessage';

const PENDO_AGENT_ID = 'D-Z_qL7HECTnCyQd8chcm2FByP8';

interface Message {
role: 'user' | 'assistant';
content: string;
Expand All @@ -21,6 +23,7 @@ export function ChatWidget() {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState('');
const messagesEndRef = useRef<HTMLDivElement>(null);
const conversationIdRef = useRef(crypto.randomUUID());

const { objectives, teams, individuals, selectedQuarter } = useOKR();
const { currentUser, currentOrganization } = useAuth();
Expand Down Expand Up @@ -65,6 +68,16 @@ export function ChatWidget() {
setError('');
setIsLoading(true);

const promptMessageId = crypto.randomUUID();

pendo.trackAgent("prompt", {
agentId: PENDO_AGENT_ID,
conversationId: conversationIdRef.current,
messageId: promptMessageId,
content: trimmed,
suggestedPrompt: false,
});

try {
const systemPrompt = buildSystemPrompt({
objectives,
Expand All @@ -83,6 +96,14 @@ export function ChatWidget() {

const response = await sendChatMessage(history, apiKey);
setMessages((prev) => [...prev, { role: 'assistant', content: response }]);

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);
Expand Down
1 change: 1 addition & 0 deletions src/types/pendo.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare var pendo: {
track: (eventName: string, properties?: Record<string, string | number | boolean>) => void;
trackAgent: (eventType: string, metadata: object) => void;
};