Skip to content

Commit 0d1675a

Browse files
fixes
1 parent 2352d3f commit 0d1675a

File tree

5 files changed

+55
-73
lines changed

5 files changed

+55
-73
lines changed

apps/dashboard/src/@/api/analytics.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ const cached_getAiUsage = unstable_cache(
236236
},
237237
);
238238

239-
export function getAiUsage(
240-
params: AnalyticsQueryParams,
241-
authToken: string,
242-
) {
239+
export function getAiUsage(params: AnalyticsQueryParams, authToken: string) {
243240
return cached_getAiUsage(normalizedParams(params), authToken);
244241
}
245242

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/ai/analytics/chart/AiTokenUsageChartCard.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
55
import { DocLink } from "@/components/blocks/DocLink";
66
import { ExportToCSVButton } from "@/components/blocks/ExportToCSVButton";
77
import type { ChartConfig } from "@/components/ui/chart";
8-
import { ReactIcon } from "@/icons/brand-icons/ReactIcon";
9-
import { TypeScriptIcon } from "@/icons/brand-icons/TypeScriptIcon";
8+
import { NebulaIcon } from "@/icons/NebulaIcon";
109
import type { AIUsageStats } from "@/types/analytics";
1110

12-
type ChartData = {
11+
type ChartData = Record<string, number> & {
1312
time: string; // human readable date
1413
tokens: number;
1514
};
@@ -30,10 +29,15 @@ export function AiTokenUsageChartCardUI(props: {
3029
},
3130
};
3231

33-
const _chartData: ChartData[] = aiUsageStats.map((stat) => ({
34-
time: stat.date,
35-
tokens: stat.totalPromptTokens + stat.totalCompletionTokens,
36-
}));
32+
const _chartData: ChartData[] = aiUsageStats
33+
.filter((stat) => stat.totalPromptTokens + stat.totalCompletionTokens > 0)
34+
.map(
35+
(stat) =>
36+
({
37+
time: stat.date,
38+
tokens: stat.totalPromptTokens + stat.totalCompletionTokens,
39+
}) as ChartData,
40+
);
3741

3842
return {
3943
chartConfig: _chartConfig,
@@ -88,7 +92,7 @@ export function AiTokenUsageChartCardUI(props: {
8892
}
8993
return undefined;
9094
}}
91-
variant="default"
95+
variant="stacked"
9296
/>
9397
);
9498
}
@@ -97,20 +101,16 @@ function AiTokenUsageEmptyChartState() {
97101
return (
98102
<div className="flex flex-col items-center justify-center px-4">
99103
<span className="mb-6 text-center text-lg">
100-
Start using AI to interact with any EVM chain
104+
Integrate thirdweb AI to interact with any EVM chain using natural
105+
language
101106
</span>
102107
<div className="flex max-w-md flex-wrap items-center justify-center gap-x-6 gap-y-4">
103108
<DocLink
104-
icon={TypeScriptIcon}
105-
label="TypeScript"
106-
link="https://portal.thirdweb.com/ai/chat"
107-
/>
108-
<DocLink
109-
icon={ReactIcon}
110-
label="React"
109+
icon={NebulaIcon}
110+
label="Get Started"
111111
link="https://portal.thirdweb.com/ai/chat"
112112
/>
113113
</div>
114114
</div>
115115
);
116-
}
116+
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/ai/analytics/chart/Summary.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActivityIcon, MessageSquareIcon, CoinsIcon } from "lucide-react";
1+
import { ActivityIcon, MessageSquareIcon } from "lucide-react";
22
import { Suspense } from "react";
33
import { getAiUsage } from "@/api/analytics";
44
import type { Range } from "@/components/analytics/date-range-selector";
@@ -9,10 +9,6 @@ function AiSummaryInner(props: {
99
stats: AIUsageStats[] | undefined;
1010
isPending: boolean;
1111
}) {
12-
const totalRequests = props.stats?.reduce((acc, curr) => {
13-
return acc + curr.totalRequests;
14-
}, 0);
15-
1612
const totalSessions = props.stats?.reduce((acc, curr) => {
1713
return acc + curr.totalSessions;
1814
}, 0);
@@ -22,21 +18,15 @@ function AiSummaryInner(props: {
2218
}, 0);
2319

2420
return (
25-
<div className="grid grid-cols-3 gap-4">
21+
<div className="grid grid-cols-2 gap-4">
2622
<StatCard
2723
icon={ActivityIcon}
2824
isPending={props.isPending}
29-
label="Requests"
30-
value={totalRequests || 0}
31-
/>
32-
<StatCard
33-
icon={MessageSquareIcon}
34-
isPending={props.isPending}
3525
label="Sessions"
3626
value={totalSessions || 0}
3727
/>
3828
<StatCard
39-
icon={CoinsIcon}
29+
icon={MessageSquareIcon}
4030
isPending={props.isPending}
4131
label="Tokens"
4232
value={totalTokens || 0}
@@ -66,10 +56,7 @@ async function AsyncAiSummary(props: {
6656
const aggregatedStats = await aggregatedStatsPromise.catch(() => null);
6757

6858
return (
69-
<AiSummaryInner
70-
stats={aggregatedStats || undefined}
71-
isPending={false}
72-
/>
59+
<AiSummaryInner stats={aggregatedStats || undefined} isPending={false} />
7360
);
7461
}
7562

@@ -80,9 +67,7 @@ export function AiSummary(props: {
8067
range: Range;
8168
}) {
8269
return (
83-
<Suspense
84-
fallback={<AiSummaryInner stats={undefined} isPending={true} />}
85-
>
70+
<Suspense fallback={<AiSummaryInner stats={undefined} isPending={true} />}>
8671
<AsyncAiSummary
8772
projectId={props.projectId}
8873
teamId={props.teamId}
@@ -91,4 +76,4 @@ export function AiSummary(props: {
9176
/>
9277
</Suspense>
9378
);
94-
}
79+
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/ai/analytics/chart/index.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ type AiAnalyticsProps = {
1414
isPending: boolean;
1515
};
1616

17-
function AiAnalyticsUI({
18-
stats,
19-
isPending,
20-
}: AiAnalyticsProps) {
17+
function AiAnalyticsUI({ stats, isPending }: AiAnalyticsProps) {
2118
return (
2219
<AiTokenUsageChartCardUI
2320
title="Token Usage"
@@ -28,18 +25,13 @@ function AiAnalyticsUI({
2825
);
2926
}
3027

31-
type AsyncAiAnalyticsProps = Omit<
32-
AiAnalyticsProps,
33-
"stats" | "isPending"
34-
> & {
28+
type AsyncAiAnalyticsProps = Omit<AiAnalyticsProps, "stats" | "isPending"> & {
3529
teamId: string;
3630
projectId: string;
3731
authToken: string;
3832
};
3933

40-
async function AsyncAiAnalytics(
41-
props: AsyncAiAnalyticsProps,
42-
) {
34+
async function AsyncAiAnalytics(props: AsyncAiAnalyticsProps) {
4335
const range = props.range ?? getLastNDaysRange("last-30");
4436

4537
const stats = await getAiUsage(
@@ -57,24 +49,17 @@ async function AsyncAiAnalytics(
5749
});
5850

5951
return (
60-
<AiAnalyticsUI
61-
{...props}
62-
isPending={false}
63-
range={range}
64-
stats={stats}
65-
/>
52+
<AiAnalyticsUI {...props} isPending={false} range={range} stats={stats} />
6653
);
6754
}
6855

6956
export function AiAnalytics(props: AsyncAiAnalyticsProps) {
7057
return (
7158
<ResponsiveSuspense
7259
searchParamsUsed={["from", "to", "interval"]}
73-
fallback={
74-
<AiAnalyticsUI {...props} isPending={true} stats={[]} />
75-
}
60+
fallback={<AiAnalyticsUI {...props} isPending={true} stats={[]} />}
7661
>
7762
<AsyncAiAnalytics {...props} />
7863
</ResponsiveSuspense>
7964
);
80-
}
65+
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/ai/page.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,45 @@ export default async function Page(props: {
4545
teamId: project.teamId,
4646
});
4747

48-
const { range, interval, defaultRange } = getFiltersFromSearchParams({
49-
defaultRange: "last-30" as DurationId,
48+
const defaultRange = "last-30" as DurationId;
49+
const { range, interval } = getFiltersFromSearchParams({
50+
defaultRange,
5051
from: searchParams.from,
5152
interval: searchParams.interval,
5253
to: searchParams.to,
5354
});
5455

5556
return (
56-
<ResponsiveSearchParamsProvider>
57+
<ResponsiveSearchParamsProvider value={searchParams}>
5758
<ProjectPage
58-
project={project}
5959
header={{
60+
client,
6061
title: "AI",
61-
description:
62-
"Interact with any EVM chain with natural language",
63-
docsLink: "https://portal.thirdweb.com/ai/chat",
62+
description: "Interact with any EVM chain with natural language",
63+
actions: {
64+
primary: {
65+
label: "Documentation",
66+
href: "https://portal.thirdweb.com/ai/chat",
67+
external: true,
68+
},
69+
secondary: {
70+
label: "API Reference",
71+
href: "https://api.thirdweb.com/reference#tag/ai/post/ai/chat",
72+
external: true,
73+
},
74+
},
6475
links: [
76+
{
77+
href: "https://portal.thirdweb.com/ai/chat",
78+
type: "docs",
79+
},
6580
{
6681
href: "https://api.thirdweb.com/reference#tag/ai/post/ai/chat",
67-
label: "API Reference",
82+
type: "api",
6883
},
6984
{
7085
href: "https://playground.thirdweb.com/ai/chat",
71-
label: "Playground",
86+
type: "playground",
7287
},
7388
],
7489
}}
@@ -93,4 +108,4 @@ export default async function Page(props: {
93108
</ProjectPage>
94109
</ResponsiveSearchParamsProvider>
95110
);
96-
}
111+
}

0 commit comments

Comments
 (0)