Skip to content

Commit 993aedf

Browse files
committed
biome format
1 parent de46e18 commit 993aedf

File tree

560 files changed

+84185
-84185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

560 files changed

+84185
-84185
lines changed

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

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,70 @@ import { validateSQL } from '../utils/sql-validator';
55
import type { StreamingUpdate } from '../utils/stream-utils';
66

77
export interface ChartHandlerContext {
8-
user: any;
9-
website: any;
10-
debugInfo: Record<string, unknown>;
11-
startTime: number;
12-
aiTime: number;
8+
user: any;
9+
website: any;
10+
debugInfo: Record<string, unknown>;
11+
startTime: number;
12+
aiTime: number;
1313
}
1414

1515
export async function* handleChartResponse(
16-
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
17-
context: ChartHandlerContext
16+
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
17+
context: ChartHandlerContext
1818
): AsyncGenerator<StreamingUpdate> {
19-
if (!parsedAiJson.sql) {
20-
yield {
21-
type: 'error',
22-
content: 'AI did not provide a query for the chart.',
23-
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
24-
};
25-
return;
26-
}
19+
if (!parsedAiJson.sql) {
20+
yield {
21+
type: 'error',
22+
content: 'AI did not provide a query for the chart.',
23+
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
24+
};
25+
return;
26+
}
2727

28-
if (!validateSQL(parsedAiJson.sql)) {
29-
yield {
30-
type: 'error',
31-
content: 'Generated query failed security validation.',
32-
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
33-
};
34-
return;
35-
}
28+
if (!validateSQL(parsedAiJson.sql)) {
29+
yield {
30+
type: 'error',
31+
content: 'Generated query failed security validation.',
32+
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
33+
};
34+
return;
35+
}
3636

37-
try {
38-
const queryResult = await executeQuery(parsedAiJson.sql);
39-
const totalTime = Date.now() - context.startTime;
37+
try {
38+
const queryResult = await executeQuery(parsedAiJson.sql);
39+
const totalTime = Date.now() - context.startTime;
4040

41-
if (context.user.role === 'ADMIN') {
42-
context.debugInfo.processing = {
43-
aiTime: context.aiTime,
44-
queryTime: Date.now() - context.startTime - context.aiTime,
45-
totalTime,
46-
};
47-
}
41+
if (context.user.role === 'ADMIN') {
42+
context.debugInfo.processing = {
43+
aiTime: context.aiTime,
44+
queryTime: Date.now() - context.startTime - context.aiTime,
45+
totalTime,
46+
};
47+
}
4848

49-
yield {
50-
type: 'complete',
51-
content:
52-
queryResult.data.length > 0
53-
? `Found ${queryResult.data.length} data points. Displaying as a ${parsedAiJson.chart_type?.replace(/_/g, ' ') || 'chart'}.`
54-
: 'No data found for your query.',
55-
data: {
56-
hasVisualization: queryResult.data.length > 0,
57-
chartType: parsedAiJson.chart_type,
58-
data: queryResult.data,
59-
responseType: 'chart',
60-
},
61-
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
62-
};
63-
} catch (queryError: unknown) {
64-
console.error('❌ SQL execution error', {
65-
error: queryError instanceof Error ? queryError.message : 'Unknown error',
66-
sql: parsedAiJson.sql,
67-
});
68-
yield {
69-
type: 'error',
70-
content: 'Database query failed. The data might not be available.',
71-
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
72-
};
73-
}
49+
yield {
50+
type: 'complete',
51+
content:
52+
queryResult.data.length > 0
53+
? `Found ${queryResult.data.length} data points. Displaying as a ${parsedAiJson.chart_type?.replace(/_/g, ' ') || 'chart'}.`
54+
: 'No data found for your query.',
55+
data: {
56+
hasVisualization: queryResult.data.length > 0,
57+
chartType: parsedAiJson.chart_type,
58+
data: queryResult.data,
59+
responseType: 'chart',
60+
},
61+
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
62+
};
63+
} catch (queryError: unknown) {
64+
console.error('❌ SQL execution error', {
65+
error: queryError instanceof Error ? queryError.message : 'Unknown error',
66+
sql: parsedAiJson.sql,
67+
});
68+
yield {
69+
type: 'error',
70+
content: 'Database query failed. The data might not be available.',
71+
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
72+
};
73+
}
7474
}

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

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,85 +5,85 @@ import { validateSQL } from '../utils/sql-validator';
55
import type { StreamingUpdate } from '../utils/stream-utils';
66

77
export interface MetricHandlerContext {
8-
user: any;
9-
website: any;
10-
debugInfo: Record<string, unknown>;
8+
user: any;
9+
website: any;
10+
debugInfo: Record<string, unknown>;
1111
}
1212

1313
export async function* handleMetricResponse(
14-
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
15-
context: MetricHandlerContext
14+
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
15+
context: MetricHandlerContext
1616
): AsyncGenerator<StreamingUpdate> {
17-
if (parsedAiJson.sql) {
18-
if (!validateSQL(parsedAiJson.sql)) {
19-
yield {
20-
type: 'error',
21-
content: 'Generated query failed security validation.',
22-
debugInfo:
23-
context.user.role === 'ADMIN' ? context.debugInfo : undefined,
24-
};
25-
return;
26-
}
17+
if (parsedAiJson.sql) {
18+
if (!validateSQL(parsedAiJson.sql)) {
19+
yield {
20+
type: 'error',
21+
content: 'Generated query failed security validation.',
22+
debugInfo:
23+
context.user.role === 'ADMIN' ? context.debugInfo : undefined,
24+
};
25+
return;
26+
}
2727

28-
try {
29-
const queryResult = await executeQuery(parsedAiJson.sql);
30-
const metricValue = extractMetricValue(
31-
queryResult.data,
32-
parsedAiJson.metric_value
33-
);
34-
yield* sendMetricResponse(parsedAiJson, metricValue, context);
35-
} catch (queryError: unknown) {
36-
console.error('❌ Metric SQL execution error', {
37-
error:
38-
queryError instanceof Error ? queryError.message : 'Unknown error',
39-
sql: parsedAiJson.sql,
40-
});
41-
yield* sendMetricResponse(
42-
parsedAiJson,
43-
parsedAiJson.metric_value,
44-
context
45-
);
46-
}
47-
} else {
48-
yield* sendMetricResponse(parsedAiJson, parsedAiJson.metric_value, context);
49-
}
28+
try {
29+
const queryResult = await executeQuery(parsedAiJson.sql);
30+
const metricValue = extractMetricValue(
31+
queryResult.data,
32+
parsedAiJson.metric_value
33+
);
34+
yield* sendMetricResponse(parsedAiJson, metricValue, context);
35+
} catch (queryError: unknown) {
36+
console.error('❌ Metric SQL execution error', {
37+
error:
38+
queryError instanceof Error ? queryError.message : 'Unknown error',
39+
sql: parsedAiJson.sql,
40+
});
41+
yield* sendMetricResponse(
42+
parsedAiJson,
43+
parsedAiJson.metric_value,
44+
context
45+
);
46+
}
47+
} else {
48+
yield* sendMetricResponse(parsedAiJson, parsedAiJson.metric_value, context);
49+
}
5050
}
5151

5252
function extractMetricValue(
53-
queryData: unknown[],
54-
defaultValue: unknown
53+
queryData: unknown[],
54+
defaultValue: unknown
5555
): unknown {
56-
if (!(queryData.length && queryData[0])) return defaultValue;
56+
if (!(queryData.length && queryData[0])) return defaultValue;
5757

58-
const firstRow = queryData[0] as Record<string, unknown>;
59-
const valueKey =
60-
Object.keys(firstRow).find((key) => typeof firstRow[key] === 'number') ||
61-
Object.keys(firstRow)[0];
58+
const firstRow = queryData[0] as Record<string, unknown>;
59+
const valueKey =
60+
Object.keys(firstRow).find((key) => typeof firstRow[key] === 'number') ||
61+
Object.keys(firstRow)[0];
6262

63-
return valueKey ? firstRow[valueKey] : defaultValue;
63+
return valueKey ? firstRow[valueKey] : defaultValue;
6464
}
6565

6666
async function* sendMetricResponse(
67-
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
68-
metricValue: unknown,
69-
context: MetricHandlerContext
67+
parsedAiJson: z.infer<typeof AIResponseJsonSchema>,
68+
metricValue: unknown,
69+
context: MetricHandlerContext
7070
): AsyncGenerator<StreamingUpdate> {
71-
const formattedValue =
72-
typeof metricValue === 'number'
73-
? metricValue.toLocaleString()
74-
: metricValue;
71+
const formattedValue =
72+
typeof metricValue === 'number'
73+
? metricValue.toLocaleString()
74+
: metricValue;
7575

76-
yield {
77-
type: 'complete',
78-
content:
79-
parsedAiJson.text_response ||
80-
`${parsedAiJson.metric_label || 'Result'}: ${formattedValue}`,
81-
data: {
82-
hasVisualization: false,
83-
responseType: 'metric',
84-
metricValue,
85-
metricLabel: parsedAiJson.metric_label,
86-
},
87-
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
88-
};
76+
yield {
77+
type: 'complete',
78+
content:
79+
parsedAiJson.text_response ||
80+
`${parsedAiJson.metric_label || 'Result'}: ${formattedValue}`,
81+
data: {
82+
hasVisualization: false,
83+
responseType: 'metric',
84+
metricValue,
85+
metricLabel: parsedAiJson.metric_label,
86+
},
87+
debugInfo: context.user.role === 'ADMIN' ? context.debugInfo : undefined,
88+
};
8989
}

apps/api/src/agent/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export { handleMetricResponse } from './handlers/metric-handler';
55
export type { AssistantContext, AssistantRequest } from './processor';
66
export { processAssistantRequest } from './processor';
77
export {
8-
AIPlanSchema,
9-
AIResponseJsonSchema,
10-
comprehensiveUnifiedPrompt,
8+
AIPlanSchema,
9+
AIResponseJsonSchema,
10+
comprehensiveUnifiedPrompt,
1111
} from './prompts/agent';
1212
export { getAICompletion } from './utils/ai-client';
1313
export { executeQuery } from './utils/query-executor';
1414
export { parseAIResponse } from './utils/response-parser';
1515
export { validateSQL } from './utils/sql-validator';
1616
export type { StreamingUpdate } from './utils/stream-utils';
1717
export {
18-
createStreamingResponse,
19-
generateThinkingSteps,
18+
createStreamingResponse,
19+
generateThinkingSteps,
2020
} from './utils/stream-utils';

0 commit comments

Comments
 (0)