Skip to content

Commit 5d50e0a

Browse files
authored
fix: dont show ai assistant if no anthropic api key exists (#1286)
<img width="1446" height="339" alt="image" src="https://github.com/user-attachments/assets/a0dbaff7-1238-4522-8d9b-56ce1501021a" />
1 parent 131a1c1 commit 5d50e0a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

packages/api/src/routers/api/me.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from 'express';
22

3-
import { USAGE_STATS_ENABLED } from '@/config';
3+
import { ANTHROPIC_API_KEY, USAGE_STATS_ENABLED } from '@/config';
44
import { getTeam } from '@/controllers/team';
55
import { Api404Error } from '@/utils/errors';
66

@@ -31,6 +31,7 @@ router.get('/', async (req, res, next) => {
3131
name,
3232
team,
3333
usageStatsEnabled: USAGE_STATS_ENABLED,
34+
aiAssistantEnabled: !!ANTHROPIC_API_KEY,
3435
});
3536
} catch (e) {
3637
next(e);

packages/app/src/DBChartPage.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import dynamic from 'next/dynamic';
33
import { parseAsJson, parseAsStringEnum, useQueryState } from 'nuqs';
44
import { useForm } from 'react-hook-form';
55
import { useHotkeys } from 'react-hotkeys-hook';
6-
import { SavedChartConfig } from '@hyperdx/common-utils/dist/types';
6+
import { SavedChartConfig, SourceKind } from '@hyperdx/common-utils/dist/types';
77
import {
8+
Alert,
89
Box,
910
Button,
1011
Collapse,
@@ -16,6 +17,7 @@ import {
1617
} from '@mantine/core';
1718
import { notifications } from '@mantine/notifications';
1819

20+
import api from '@/api';
1921
import { DEFAULT_CHART_CONFIG, Granularity } from '@/ChartUtils';
2022
import EditTimeChartForm from '@/components/DBEditTimeChartForm';
2123
import { InputControlled } from '@/components/InputControlled';
@@ -24,6 +26,7 @@ import { useChartAssistant } from '@/hooks/ai';
2426
import { withAppNav } from '@/layout';
2527
import { useSources } from '@/source';
2628
import { parseTimeQuery, useNewTimeQuery } from '@/timeQuery';
29+
import { useLocalStorage } from '@/utils';
2730

2831
// Autocomplete can focus on column/map keys
2932

@@ -36,12 +39,18 @@ function AIAssistant({
3639
setConfig,
3740
onTimeRangeSelect,
3841
submitRef,
42+
aiAssistantEnabled,
3943
}: {
4044
setConfig: (config: SavedChartConfig) => void;
4145
onTimeRangeSelect: (start: Date, end: Date) => void;
4246
submitRef: React.RefObject<(() => void) | undefined>;
47+
aiAssistantEnabled: boolean;
4348
}) {
4449
const [opened, setOpened] = useState(false);
50+
const [alertDismissed, setAlertDismissed] = useLocalStorage(
51+
'ai-assistant-alert-dismissed',
52+
false,
53+
);
4554
const { control, watch, setValue, handleSubmit } = useForm<{
4655
text: string;
4756
source: string;
@@ -105,6 +114,30 @@ function AIAssistant({
105114
},
106115
);
107116

117+
if (!aiAssistantEnabled && !alertDismissed) {
118+
return (
119+
<Box mb="sm">
120+
<Alert
121+
color="dark.3"
122+
icon={<i className="bi bi-info-circle" />}
123+
variant="outline"
124+
withCloseButton
125+
onClose={() => setAlertDismissed(true)}
126+
p="xxs"
127+
>
128+
<Text size="xs" c="dark.2" pt="2px">
129+
New AI Assistant available, enable with configuring the{' '}
130+
<code>ANTHROPIC_API_KEY</code> environment variable on the HyperDX
131+
server.
132+
</Text>
133+
</Alert>
134+
<Divider mt="sm" />
135+
</Box>
136+
);
137+
} else if (!aiAssistantEnabled) {
138+
return null;
139+
}
140+
108141
return (
109142
<Box mb="sm">
110143
<Group gap="md" align="center" mb="sm">
@@ -123,7 +156,7 @@ function AIAssistant({
123156
<Text size="xxs">AI Assistant [A]</Text>
124157
</Group>
125158
</Button>
126-
<Pill size="xs">Super Experimental</Pill>
159+
<Pill size="xs">Experimental</Pill>
127160
</Group>
128161
<Collapse in={opened}>
129162
{opened && (
@@ -135,6 +168,7 @@ function AIAssistant({
135168
control={control}
136169
name="source"
137170
data-testid="source-selector"
171+
allowedSourceKinds={[SourceKind.Log, SourceKind.Trace]}
138172
/>
139173
<Box style={{ flexGrow: 1, minWidth: 100 }}>
140174
<InputControlled
@@ -177,6 +211,7 @@ function DBChartExplorerPage() {
177211

178212
const submitRef = useRef<() => void>();
179213
const { data: sources } = useSources();
214+
const { data: me } = api.useMe();
180215

181216
const [chartConfig, setChartConfig] = useQueryState(
182217
'config',
@@ -192,6 +227,7 @@ function DBChartExplorerPage() {
192227
setConfig={setChartConfig}
193228
onTimeRangeSelect={onTimeRangeSelect}
194229
submitRef={submitRef}
230+
aiAssistantEnabled={me?.aiAssistantEnabled ?? false}
195231
/>
196232
<EditTimeChartForm
197233
data-testid="chart-explorer-form"

0 commit comments

Comments
 (0)