Skip to content

Commit

Permalink
(feat): remove app insights
Browse files Browse the repository at this point in the history
  • Loading branch information
samyakkkk committed Aug 10, 2024
1 parent 3624fcc commit a319492
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 151 deletions.
2 changes: 0 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
"type": "module",
"dependencies": {
"@lottiefiles/svelte-lottie-player": "^0.3.1",
"@microsoft/applicationinsights-web": "^3.3.1",
"@tailwindcss/typography": "^0.5.13",
"dotenv": "^16.4.5",
"highlight.js": "^11.10.0",
"isomorphic-dompurify": "^2.14.0",
"showdown": "^2.1.0",
Expand Down
30 changes: 7 additions & 23 deletions web/src/lib/components/CreateAgentDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import { goto } from "$app/navigation";
import { toastStore } from "$lib/stores/ToastStores";
import { ToastType } from "$lib/types/Toast";
import appInsights from "$lib/utils/appInsights"; // Import the appInsights instance
import IconClose from "~icons/carbon/close";
import IconClose from "~icons/carbon/close";
import CarbonSearch from "~icons/carbon/search";
import CarbonGithub from "~icons/carbon/logo-github";
Expand All @@ -27,14 +26,6 @@
const onCreateAgent = () => {
if (validateGithubURL(value)) {
// Track custom event for form submission
appInsights.trackEvent({
name: "CreateAgentSubmitted",
properties: {
githubUrl: value,
},
});
goto(`${base}/agent?github=${value}`);
} else {
toastStore.set({
Expand All @@ -43,13 +34,6 @@
});
}
};
$: if (showModal) {
// Track custom event for dialog opened
appInsights.trackEvent({
name: "CreateAgentDialogOpened",
});
}
</script>

{#if showModal}
Expand All @@ -64,11 +48,11 @@
>
<div class="absolute right-0 top-0 mr-2 mt-2">
<button
class="flex items-center px-2.5 py-1 text-sm text-white"
on:click={onClose}
>
<IconClose class="mr-1.5 text-xl" />
</button>
class="flex items-center px-2.5 py-1 text-sm text-white"
on:click={onClose}
>
<IconClose class="mr-1.5 text-xl" />
</button>
</div>
<h1 class="text-xl font-bold text-white">Create Agent with Github</h1>
<div
Expand All @@ -95,4 +79,4 @@
</button>
</dialog>
</div>
{/if}
{/if}
37 changes: 2 additions & 35 deletions web/src/lib/components/chat/ChatIntroduction.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import IconVisualStudio from "../icons/IconVisualStudio.svelte";
import { toastStore } from "$lib/stores/ToastStores";
import appInsights from "$lib/utils/appInsights"; // Import the appInsights instance
import Icon from "@iconify/svelte";
import { ToastType } from "$lib/types/Toast";
Expand Down Expand Up @@ -49,56 +48,26 @@
message: _response.message,
type: ToastType.ERROR,
});
appInsights.trackException({
error: new Error(_response.message),
}); // Track exception
return;
}
toastStore.set({
message: "Notification sent successfully",
type: ToastType.SUCCESS,
});
// Track custom event for notification sent
appInsights.trackEvent({
name: "NotificationSent",
properties: {
agentId,
emailValue,
},
});
} catch (error) {
console.log("error", error);
toastStore.set({
message: "Ops! Something went wrong",
type: ToastType.ERROR,
});
appInsights.trackException({ error: new Error(`${error}`) }); // Track exception
}
};
const onQuestionnaire = (questionnaire: Questionnaire) => {
questionnaireStore.set(questionnaire);
}
// Track custom event for questionnaire selected
appInsights.trackEvent({
name: "QuestionnaireSelected",
properties: {
agentId,
questionnaireId: questionnaire.id,
questionnaireMessage: questionnaire.message,
},
});
};
const trackLinkClick = () => {
appInsights.trackEvent({
name: "VSCodeLinkClicked",
properties: {
agentId,
},
});
};
</script>

<div class="my-auto grid gap-4 lg:grid-cols-2">
Expand Down Expand Up @@ -127,7 +96,6 @@
href="https://marketplace.visualstudio.com/items?itemName=WelltestedAI.fluttergpt"
target="_blank"
class="flex items-center justify-center w-full md:w-auto h-12 px-6 font-medium text-white transition-colors duration-150 ease-in-out bg-blue-800 rounded-md hover:bg-blue-700 space-x-2 shadow-lg"
on:click={trackLinkClick}
>
<IconVisualStudio />
<div class="text-sm text-white">VSCode</div>
Expand Down Expand Up @@ -177,8 +145,7 @@
{#each questionnaires as questionnaire}
<button
class={`relative rounded-xl border ${questionnaire.id === "generate-summary" ? "bg-[#497BEF] text-gray-300 border-[#497BEF] hover:bg-[#287CEB] hover:border-[#287CEB]" : "bg-gray-50 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700 text-gray-600 hover:bg-gray-100"} p-3 max-xl:text-sm xl:p-3.5`}
on:click={() => onQuestionnaire(questionnaire)}
>
on:click={() => onQuestionnaire(questionnaire)}>
{questionnaire.message}
</button>
{/each}
Expand Down
10 changes: 1 addition & 9 deletions web/src/lib/components/chat/ChatMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import showdown from "showdown";
import hljs from "highlight.js";
import DOMPurify from "isomorphic-dompurify";
import appInsights from "$lib/utils/appInsights";
import { writable } from "svelte/store";
import Icon from "@iconify/svelte";
import IconVisualStudio from "../icons/IconVisualStudio.svelte";
Expand Down Expand Up @@ -180,13 +180,6 @@
},
];
};
const trackLinkClick = () => {
appInsights.trackEvent({
name: 'VSCodeLinkClicked',
});
}
</script>

{#each messages as message, index}
Expand Down Expand Up @@ -273,7 +266,6 @@
href="https://marketplace.visualstudio.com/items?itemName=WelltestedAI.fluttergpt"
target="_blank"
class="flex items-center justify-center w-full md:w-auto h-12 px-6 font-medium text-white transition-colors duration-150 ease-in-out bg-blue-800 rounded-md hover:bg-blue-700 space-x-2 shadow-lg"
on:click={trackLinkClick}
>
<IconVisualStudio />
<div class="text-sm text-white">VSCode</div>
Expand Down
55 changes: 19 additions & 36 deletions web/src/lib/components/chat/ChatWindow.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import appInsights from "$lib/utils/appInsights";
import { questionnaireStore } from "$lib/stores/QuestionnaireStores";
import type { Message } from "$lib/types/Message";
Expand Down Expand Up @@ -36,37 +35,34 @@
LottiePlayer = module.LottiePlayer;
questionnaireStore.subscribe((questionnaire: Questionnaire) => {
switch (questionnaire?.id) {
case "generate-summary":
message = `Please give me a complete summary about ${agentDisplayName}`;
handleSubmit();
break;
case "ask-about":
message =
"Help me understand (x) feature in detail with helpful links to read more about it";
message = "Help me understand (x) feature in detail with helpful links to read more about it";
break;
case "search-code":
message =
"Where can I find the code that does (y). Please help me with links to it";
message = "Where can I find the code that does (y). Please help me with links to it";
break;
case "get-help":
message =
"Help me resolve the (z) problem I'm facing. Here is some helpful code: (code)";
message = "Help me resolve the (z) problem I'm facing. Here is some helpful code: (code)";
break;
}
});
})
});
onDestroy(() => {
message = "";
questionnaireStore.set({ id: "", message: "" });
questionnaireStore.set({id: "", message: ""});
});
const onHome = () => {
message = "";
goto("/");
appInsights.trackEvent({ name: "NavigateHome" });
};
goto('/');
}
const handleSubmit = async () => {
if (messageLoading || loading) {
Expand All @@ -76,6 +72,7 @@
messages = [...messages, { role: "user", text: message }];
const agentData = {
agent_name: agentName,
agent_version: agentVersion,
Expand All @@ -97,25 +94,15 @@
},
},
);
const modelResponse = await response.json();
console.log("model response", modelResponse);
console.log('model response', modelResponse);
messages = [
...messages,
{
role: "model",
text: modelResponse.response,
references: modelResponse.references,
},
{ role: "model", text: modelResponse.response, references: modelResponse.references },
];
agentReferences = modelResponse?.references;
appInsights.trackEvent({
name: "MessageSent",
properties: {
agentName,
agentVersion,
},
});
agentReferences = modelResponse?.references
} catch (error) {
console.log("error", error);
}
Expand All @@ -135,20 +122,16 @@
<div class="flex h-max flex-col gap-6 pb-40 2xl:gap-7">
{#if messages.length > 0}
{#if !loading}
<ChatMessage
{messages}
{agentLogo}
{agentDisplayName}
/>
<ChatMessage {messages} {agentLogo} {agentDisplayName} />
{#if messageLoading}
{#if LottiePlayer}
<div class="flex-col w-full h-48 px-2 py-3">
<div
class="flex-col w-full h-48 px-2 py-3"
>
<div
class="inline-flex flex-row items-end px-2"
>
<span id="workspace-loader-text"
>Preparing results</span
>
<span id="workspace-loader-text">Preparing results</span>
<div class="typing-loader mx-2"></div>
</div>
</div>
Expand Down
26 changes: 13 additions & 13 deletions web/src/lib/utils/appInsights.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
// import { ApplicationInsights } from '@microsoft/applicationinsights-web';

const instrumentationKey = import.meta.env.VITE_INSTRUMENTATION_KEY;
// const instrumentationKey = import.meta.env.VITE_INSTRUMENTATION_KEY;

if (!instrumentationKey) {
console.log('instrumentation key not found');
}
// if (!instrumentationKey) {
// console.log('instrumentation key not found');
// }

const appInsights = new ApplicationInsights({
config: {
instrumentationKey: instrumentationKey
}
});
// const appInsights = new ApplicationInsights({
// config: {
// instrumentationKey: instrumentationKey
// }
// });

appInsights.loadAppInsights();
appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
// appInsights.loadAppInsights();
// appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview

export default appInsights;
// export default appInsights;
Loading

0 comments on commit a319492

Please sign in to comment.