Skip to content

Commit e1efac7

Browse files
committed
databunny
1 parent 8efe17c commit e1efac7

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

apps/api/src/agent/handlers/chart-handler.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import { executeQuery } from '../utils/query-executor';
44
import { validateSQL } from '../utils/sql-validator';
55
import type { StreamingUpdate } from '../utils/stream-utils';
66

7+
const getRandomMessage = (messages: string[]) =>
8+
messages[Math.floor(Math.random() * messages.length)];
9+
10+
const queryFailedMessages = [
11+
'I ran into an issue getting that data. The information might not be available right now.',
12+
'Something went wrong while fetching your analytics data. Try asking again in a moment?',
13+
"I couldn't retrieve that data - there might be a temporary issue. Want to try a different question?",
14+
];
15+
16+
const noDataMessages = [
17+
"I couldn't find any data for that query. Try asking about a different time period or metric?",
18+
'No data showed up for that request. Maybe try a different date range or ask about something else?',
19+
'That search came up empty! Want to try asking about a different metric or time frame?',
20+
];
21+
722
export interface ChartHandlerContext {
823
user: any;
924
website: any;
@@ -51,7 +66,7 @@ export async function* handleChartResponse(
5166
content:
5267
queryResult.data.length > 0
5368
? `Found ${queryResult.data.length} data points. Displaying as a ${parsedAiJson.chart_type?.replace(/_/g, ' ') || 'chart'}.`
54-
: 'No data found for your query.',
69+
: getRandomMessage(noDataMessages),
5570
data: {
5671
hasVisualization: queryResult.data.length > 0,
5772
chartType: parsedAiJson.chart_type,
@@ -67,7 +82,7 @@ export async function* handleChartResponse(
6782
});
6883
yield {
6984
type: 'error',
70-
content: 'Database query failed. The data might not be available.',
85+
content: getRandomMessage(queryFailedMessages),
7186
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
7287
};
7388
}

apps/api/src/agent/processor.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ import { parseAIResponse } from './utils/response-parser';
88
import type { StreamingUpdate } from './utils/stream-utils';
99
import { generateThinkingSteps } from './utils/stream-utils';
1010

11+
// Simple message variation helpers
12+
const getRandomMessage = (messages: string[]) =>
13+
messages[Math.floor(Math.random() * messages.length)];
14+
15+
const parseErrorMessages = [
16+
"I'm having trouble understanding that request. Could you try asking in a different way?",
17+
'Something went wrong while I was processing your question. Mind rephrasing it?',
18+
"I didn't quite catch that - could you ask me again, maybe with different words?",
19+
];
20+
21+
const unexpectedErrorMessages = [
22+
'Oops! Something unexpected happened. Mind trying that again?',
23+
'I hit a snag there! Could you give that another shot?',
24+
'Something went a bit wonky on my end. Try asking me again?',
25+
];
26+
1127
export interface AssistantRequest {
1228
message: string;
1329
website_id: string;
@@ -72,7 +88,7 @@ export async function* processAssistantRequest(
7288
if (!parsedResponse.success) {
7389
yield {
7490
type: 'error',
75-
content: 'AI response parsing failed. Please try rephrasing.',
91+
content: getRandomMessage(parseErrorMessages),
7692
debugInfo:
7793
context.user.role === 'ADMIN'
7894
? {
@@ -89,7 +105,7 @@ export async function* processAssistantRequest(
89105
if (!aiJson) {
90106
yield {
91107
type: 'error',
92-
content: 'AI response data is missing.',
108+
content: getRandomMessage(parseErrorMessages),
93109
debugInfo:
94110
context.user.role === 'ADMIN' ? context.debugInfo : undefined,
95111
};
@@ -157,7 +173,7 @@ export async function* processAssistantRequest(
157173

158174
yield {
159175
type: 'error',
160-
content: 'An unexpected error occurred.',
176+
content: getRandomMessage(unexpectedErrorMessages),
161177
debugInfo:
162178
context.user.role === 'ADMIN' ? { error: errorMessage } : undefined,
163179
};

apps/dashboard/app/(main)/websites/[id]/assistant/components/chat-section.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ export default function ChatSection() {
214214
<Sparkle className="h-8 w-8 text-primary" />
215215
</div>
216216
<h3 className="mb-2 font-semibold text-lg">
217-
Welcome to Nova
217+
Welcome to Databunny
218218
</h3>
219219
<p className="mx-auto max-w-md text-muted-foreground text-sm">
220-
I'm Nova, your AI analytics partner. I can help you
221-
understand your website data through charts, metrics, and
222-
insights. Just ask me anything!
220+
I'm Databunny, your data analyst. I can help you understand
221+
your website data through charts, metrics, and insights.
222+
Just ask me anything!
223223
</p>
224224
</div>
225225

apps/dashboard/app/(main)/websites/[id]/assistant/lib/chat-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface ChatDBSchema extends DBSchema {
3131

3232
class ChatDatabase {
3333
private dbPromise: Promise<IDBPDatabase<ChatDBSchema>>;
34-
private readonly DB_NAME = 'databuddy-assistant';
34+
private readonly DB_NAME = 'databuddy-databunny';
3535
private readonly DB_VERSION = 1;
3636

3737
constructor() {

0 commit comments

Comments
 (0)