fix ai + chart + events

This commit is contained in:
Emily
2024-10-01 14:25:56 +02:00
parent a08624b69b
commit dad8c521ee
6 changed files with 33 additions and 10 deletions

View File

@@ -123,8 +123,14 @@ function externalTooltipHandler(context: { chart: any, tooltip: TooltipModel<'li
return; return;
} }
const { left: positionX, top: positionY } = chart.canvas.getBoundingClientRect(); const { left: positionX, top: positionY } = chart.canvas.getBoundingClientRect();
const xSwap = tooltip.caretX > (window.innerWidth * 0.5) ? -450 : -100;
tooltipEl.style.opacity = '1'; tooltipEl.style.opacity = '1';
tooltipEl.style.left = positionX + tooltip.caretX + 'px';
tooltipEl.style.left = positionX + (tooltip.caretX + xSwap) + 'px';
tooltipEl.style.top = positionY + tooltip.caretY + 'px'; tooltipEl.style.top = positionY + tooltip.caretY + 'px';
tooltipEl.style.padding = tooltip.options.padding + 'px ' + tooltip.options.padding + 'px'; tooltipEl.style.padding = tooltip.options.padding + 'px ' + tooltip.options.padding + 'px';

View File

@@ -36,8 +36,20 @@ const eventsData = await useFetch(`/api/data/count`, { method: 'POST', headers,
<div class="w-full h-full overflow-y-auto pb-20 p-6 gap-6 flex flex-col"> <div class="w-full h-full overflow-y-auto pb-20 p-6 gap-6 flex flex-col">
<LyxUiCard class="w-full"> <LyxUiCard class="w-full flex justify-between items-center">
Total events: {{ eventsData.data.value?.[0].total || '???' }} <div class="flex flex-col gap-1">
<div>
Total events: {{ eventsData.data.value?.[0]?.total || '0' }}
</div>
<div v-if="(eventsData.data.value?.[0]?.total || 0) === 0">
Waiting for your first event...
</div>
</div>
<div>
<LyxUiButton type="secondary" to="https://docs.litlyx.com/custom-events">
Go to docs
</LyxUiButton>
</div>
</LyxUiCard> </LyxUiCard>
<div class="flex gap-6 flex-col xl:flex-row h-full"> <div class="flex gap-6 flex-col xl:flex-row h-full">

View File

@@ -2,7 +2,7 @@ import { EventModel } from "@schema/metrics/EventSchema";
import { AdvancedTimelineAggregationOptions, executeAdvancedTimelineAggregation, executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService"; import { AdvancedTimelineAggregationOptions, executeAdvancedTimelineAggregation, executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
import { Types } from "mongoose"; import { Types } from "mongoose";
import { AIPlugin, AIPlugin_TTool } from "../Plugin"; import { AIPlugin, AIPlugin_TTool } from "../Plugin";
import dayjs from 'dayjs';
const getEventsCountTool: AIPlugin_TTool<'getEventsCount'> = { const getEventsCountTool: AIPlugin_TTool<'getEventsCount'> = {
type: 'function', type: 'function',
@@ -66,7 +66,9 @@ export class AiEvents extends AIPlugin<['getEventsCount', 'getEventsTimeline']>
const query: AdvancedTimelineAggregationOptions & { customMatch: Record<string, any> } = { const query: AdvancedTimelineAggregationOptions & { customMatch: Record<string, any> } = {
projectId: new Types.ObjectId(data.project_id) as any, projectId: new Types.ObjectId(data.project_id) as any,
model: EventModel, model: EventModel,
from: data.from, to: data.to, slice: 'day', from: dayjs(data.from).startOf('day').toISOString(),
to: dayjs(data.to).startOf('day').toISOString(),
slice: 'day',
customMatch: {} customMatch: {}
} }
if (data.metadata) query.customMatch.metadata = data.metadata; if (data.metadata) query.customMatch.metadata = data.metadata;

View File

@@ -2,7 +2,7 @@ import { VisitModel } from "@schema/metrics/VisitSchema";
import { AdvancedTimelineAggregationOptions, executeAdvancedTimelineAggregation, executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService"; import { AdvancedTimelineAggregationOptions, executeAdvancedTimelineAggregation, executeTimelineAggregation, fillAndMergeTimelineAggregationV2 } from "~/server/services/TimelineService";
import { Types } from "mongoose"; import { Types } from "mongoose";
import { AIPlugin, AIPlugin_TTool } from "../Plugin"; import { AIPlugin, AIPlugin_TTool } from "../Plugin";
import dayjs from 'dayjs';
const getVisitsCountsTool: AIPlugin_TTool<'getVisitsCount'> = { const getVisitsCountsTool: AIPlugin_TTool<'getVisitsCount'> = {
type: 'function', type: 'function',
@@ -63,10 +63,13 @@ export class AiVisits extends AIPlugin<['getVisitsCount', 'getVisitsTimeline']>
}, },
'getVisitsTimeline': { 'getVisitsTimeline': {
handler: async (data: { project_id: string, from: string, to: string, website?: string, page?: string }) => { handler: async (data: { project_id: string, from: string, to: string, website?: string, page?: string }) => {
const query: AdvancedTimelineAggregationOptions & { customMatch: Record<string, any> } = { const query: AdvancedTimelineAggregationOptions & { customMatch: Record<string, any> } = {
projectId: new Types.ObjectId(data.project_id) as any, projectId: new Types.ObjectId(data.project_id) as any,
model: VisitModel, model: VisitModel,
from: data.from, to: data.to, slice: 'day', from: dayjs(data.from).startOf('day').toISOString(),
to: dayjs(data.to).startOf('day').toISOString(),
slice: 'day',
customMatch: {} customMatch: {}
} }

View File

@@ -140,10 +140,10 @@ async function onPaymentSuccess(event: Event.InvoicePaidEvent) {
setTimeout(() => { setTimeout(() => {
if (PLAN.ID == 0) return; if (PLAN.ID == 0) return;
EmailService.sendPurchaseEmail(user.email, project.name); EmailService.sendPurchaseEmail(user.email, project.name);
}, 1); }, 1);
return { ok: true }; return { ok: true };

View File

@@ -77,7 +77,7 @@ export async function sendMessageOnChat(text: string, pid: string, initial_chat_
} else { } else {
const roleMessage: OpenAI.Chat.Completions.ChatCompletionMessageParam = { const roleMessage: OpenAI.Chat.Completions.ChatCompletionMessageParam = {
role: 'system', role: 'system',
content: + "Today is " + new Date().toISOString() content: "Today ISO date: " + new Date().toISOString()
} }
messages.push(roleMessage); messages.push(roleMessage);
await addMessageToChat(roleMessage, chat_id); await addMessageToChat(roleMessage, chat_id);