Skip to content

Commit

Permalink
Merge pull request #265 from memser-spaceport/feat/husky-sidepanel
Browse files Browse the repository at this point in the history
feat/husky-sidepanel: Added support for code block and shift enter fo…
  • Loading branch information
Thangaraj-Ideas2it authored Oct 7, 2024
2 parents 394b220 + ceb18a2 commit 550eb11
Show file tree
Hide file tree
Showing 13 changed files with 828 additions and 57 deletions.
12 changes: 6 additions & 6 deletions analytics/husky.analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const useHuskyAnalytics = () => {
captureEvent(events.husky_action_card_clicked, {...action})
}

function trackSharedBlog(blogId: string, mode: string) {
captureEvent(events.husky_open_shared_blog, {blogId, mode });
function trackSharedBlog(blogId: string, mode: string, question: string) {
captureEvent(events.husky_open_shared_blog, {blogId, mode, question });
}

function trackFollowupQuestionClick(mode: string, question: string, blogId?: string | null) {
Expand All @@ -75,12 +75,12 @@ export const useHuskyAnalytics = () => {
captureEvent(events.husky_user_feedback_clicked, { question, answer });
}

function trackFeedbackStatus( status: string) {
captureEvent(events.husky_user_feedback_status, { status });
function trackFeedbackStatus( status: string, rating: string, question: string) {
captureEvent(events.husky_user_feedback_status, { feedbackStatus: status, rating, question });
}

function trackAiResponse(status: string, mode: string) {
captureEvent(events.husky_ai_response, { status, mode, });
function trackAiResponse(status: string, mode: string, isBlog: boolean, question: string) {
captureEvent(events.husky_ai_response, { huskyResponse: status, mode, isBlog, question });
}

function trackRegenerate() {
Expand Down
36 changes: 18 additions & 18 deletions components/core/husky/husky-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose

const onPromptClicked = async (question: string) => {
try {
const { authToken } = await getUserCredentials();
const { authToken, userInfo } = await getUserCredentials();
if (!authToken) {
return;
}
Expand All @@ -116,19 +116,19 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose
setAnswerLoadingStatus(true);
setActiveTab(DEFAULT_TAB_ITEMS[0].key);
setChats([]);
trackAiResponse('initiated', 'prompt');
const result = await getHuskyResponse(authToken, question, selectedSource, chatUid, null, null, mode === 'blog'); // Fixed function name
trackAiResponse('initiated', 'prompt', mode === 'blog', question);
const result = await getHuskyResponse(userInfo, authToken, question, selectedSource, chatUid, null, null, mode === 'blog'); // Fixed function name
setAskingQuestion('');
setAnswerLoadingStatus(false);
if (result.isError) {
trackAiResponse('error', 'prompt');
trackAiResponse('error', 'prompt', mode === 'blog', question);
setChats((prevChats) => [...prevChats, { question, answer: '', isError: true }]);
return;
}
trackAiResponse('success', 'prompt');
trackAiResponse('success', 'prompt', mode === 'blog', question);
setChats(result.data ? [{ ...result.data, isError: false }] : []);
} catch (error) {
trackAiResponse('error', 'prompt');
trackAiResponse('error', 'prompt', mode === 'blog', question);
}
};

Expand All @@ -149,7 +149,7 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose

const onFollowupClicked = async (question: string) => {
try {
const { authToken } = await getUserCredentials();
const { authToken, userInfo } = await getUserCredentials();
if (!authToken) {
return;
}
Expand All @@ -158,23 +158,23 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose
return;
}
trackFollowupQuestionClick(mode, question, blogId);
trackAiResponse('initiated', 'followup');
trackAiResponse('initiated', 'followup', mode === 'blog', question);
const chatUid = checkAndSetPromptId();
setAskingQuestion(question);
setAnswerLoadingStatus(true);

const result = await getHuskyResponse(authToken, question, selectedSource, chatUid, mode === 'blog' && chats.length === 1 ? chats[0].question : null, mode === 'blog' && chats.length === 1 ? chats[0].answer : null, mode === 'blog'); // Fixed function name
const result = await getHuskyResponse(userInfo, authToken, question, selectedSource, chatUid, mode === 'blog' && chats.length === 1 ? chats[0].question : null, mode === 'blog' && chats.length === 1 ? chats[0].answer : null, mode === 'blog'); // Fixed function name
setAskingQuestion('');
setAnswerLoadingStatus(false);
if (result.isError) {
trackAiResponse('error', 'followup');
trackAiResponse('error', 'followup', mode === 'blog', question);
setChats((prevChats) => [...prevChats, { question, answer: '', isError: true }]);
return;
}
trackAiResponse('success', 'followup');
trackAiResponse('success', 'followup', mode === 'blog', question);
setChats((prevChats) => result.data ? [...prevChats, { ...result.data, isError: false }] : prevChats);
} catch (error) {
trackAiResponse('error', 'followup');
trackAiResponse('error', 'followup', mode === 'blog', question);
}
};

Expand All @@ -199,7 +199,7 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose

const onHuskyInput = async (query: string) => {
try {
const { authToken } = await getUserCredentials();
const { authToken, userInfo } = await getUserCredentials();
if (!authToken) {
return;
}
Expand All @@ -216,19 +216,19 @@ function HuskyAi({ mode = 'chat', initialChats = [], isLoggedIn, blogId, onClose
trackUserPrompt(query);
setAskingQuestion(query);
setAnswerLoadingStatus(true);
trackAiResponse('initiated', 'user-input');
const result = await getHuskyResponse(authToken, query, selectedSource, chatUid);
trackAiResponse('initiated', 'user-input', mode === 'blog', query);
const result = await getHuskyResponse(userInfo, authToken, query, selectedSource, chatUid);
setAskingQuestion('');
setAnswerLoadingStatus(false);
if (result.isError) {
trackAiResponse('error', 'user-input');
trackAiResponse('error', 'user-input', mode === 'blog', query);
setChats((prevChats) => [...prevChats, { question: query, answer: '', isError: true }]);
return;
}
trackAiResponse('success', 'user-input');
trackAiResponse('success', 'user-input', mode === 'blog', query);
setChats((prevChats) => result.data ? [...prevChats, { ...result.data, isError: false }] : prevChats);
} catch (error) {
trackAiResponse('error', 'user-input');
trackAiResponse('error', 'user-input', mode === 'blog', query);
}
};

Expand Down
16 changes: 11 additions & 5 deletions components/core/husky/husky-chat-answer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Markdown from 'markdown-to-jsx';
import { useRef, useState } from 'react';

import CopyText from '../copy-text';
import HuskyCodeBlock from './husky-code-block';

interface HuskyChatAnswerProps {
mode: 'blog' | 'chat';
Expand Down Expand Up @@ -29,22 +28,24 @@ function HuskyChatAnswer({ mode, answer, isLastIndex, question, onCopyAnswer, on
<div className="chat__ans">
{mode !== 'blog' && (
<h3 className="chat__ans__title">
<img width={16} height={16} src="/icons/chat-orange.svg" />
<img alt="Answer" width={16} height={16} src="/icons/chat-orange.svg" />
<span>Answer</span>
</h3>
)}
<div className={`chat__ans__text ${mode === 'blog' ? 'chat__ans__text--blog' : ''}`}>
<Markdown
style={{ width: '100%' }}
options={{
overrides: {
a: { component: anchorWrapper },
p: { props: { style: { marginBottom: '6px', lineHeight: '20px', fontSize: '14px' } } },
p: { props: { style: { marginBottom: '6px', lineHeight: '20px', fontSize: '14px', maxWidth: '100%' } } },
h1: { props: { style: { marginTop: '14px', marginBottom: '14px', fontSize: '22px' } } },
h2: { props: { style: { marginTop: '12px', marginBottom: '12px', fontSize: '20px' } } },
h3: { props: { style: { marginTop: '10px', marginBottom: '10px', fontSize: '18px' } } },
h4: { props: { style: { marginTop: '8px', marginBottom: '8px', fontSize: '16px' } } },
ol: { props: { style: { marginLeft: '16px' } } },
ul: { props: { style: { marginLeft: '16px' } } },
code: { component: HuskyCodeBlock },
},
}}
>
Expand Down Expand Up @@ -95,6 +96,11 @@ function HuskyChatAnswer({ mode, answer, isLastIndex, question, onCopyAnswer, on
gap: 8px;
padding: 14px;
border-radius: 8px;
max-width: 100%;
}
.chat__ans__text div:first-child {
max-width: 100%;
}
.chat__ans__text--blog {
Expand Down Expand Up @@ -138,4 +144,4 @@ function HuskyChatAnswer({ mode, answer, isLastIndex, question, onCopyAnswer, on
);
}

export default HuskyChatAnswer;
export default HuskyChatAnswer;
Loading

0 comments on commit 550eb11

Please sign in to comment.