Skip to content

Commit ce27790

Browse files
committed
Added AI fixing of errors
1 parent 07e76bd commit ce27790

File tree

1 file changed

+53
-6
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query

1 file changed

+53
-6
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query/route.tsx

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,21 @@ export default function Page() {
341341
const [prettyFormatting, setPrettyFormatting] = useState(true);
342342
const [resultsView, setResultsView] = useState<"table" | "graph">("table");
343343
const [chartConfig, setChartConfig] = useState<ChartConfiguration>(defaultChartConfig);
344+
const [helpTab, setHelpTab] = useState<string>("ai");
345+
const [errorFixPrompt, setErrorFixPrompt] = useState<string | undefined>();
346+
347+
const handleTryFixError = useCallback(
348+
(errorMessage: string) => {
349+
// Switch to AI tab and trigger an error fix prompt
350+
setHelpTab("ai");
351+
// Clear any previous prompt first to ensure re-trigger
352+
setErrorFixPrompt(undefined);
353+
setTimeout(() => {
354+
setErrorFixPrompt(`Fix this query error: ${errorMessage}`);
355+
}, 0);
356+
},
357+
[]
358+
);
344359

345360
const isLoading = navigation.state === "submitting" || navigation.state === "loading";
346361

@@ -430,9 +445,19 @@ export default function Page() {
430445
<span>Executing query...</span>
431446
</div>
432447
) : results?.error ? (
433-
<pre className="whitespace-pre-wrap p-4 text-sm text-red-400">
434-
{results.error}
435-
</pre>
448+
<div className="p-4">
449+
<pre className="whitespace-pre-wrap text-sm text-red-400">
450+
{results.error}
451+
</pre>
452+
<Button
453+
variant="tertiary/small"
454+
className="mt-3"
455+
LeadingIcon={AISparkleIcon}
456+
onClick={() => handleTryFixError(results.error!)}
457+
>
458+
Try fix error
459+
</Button>
460+
</div>
436461
) : results?.rows && results?.columns ? (
437462
<TSQLResultsTable
438463
rows={results.rows}
@@ -493,6 +518,9 @@ export default function Page() {
493518
editorRef.current?.setQuery(formatted);
494519
}}
495520
getCurrentQuery={() => editorRef.current?.getQuery() ?? ""}
521+
activeTab={helpTab}
522+
onTabChange={setHelpTab}
523+
errorFixPrompt={errorFixPrompt}
496524
/>
497525
</ResizablePanel>
498526
</ResizablePanelGroup>
@@ -613,14 +641,24 @@ function QueryHelpSidebar({
613641
onTryExample,
614642
onQueryGenerated,
615643
getCurrentQuery,
644+
activeTab,
645+
onTabChange,
646+
errorFixPrompt,
616647
}: {
617648
onTryExample: (query: string, scope: QueryScope) => void;
618649
onQueryGenerated: (query: string) => void;
619650
getCurrentQuery: () => string;
651+
activeTab: string;
652+
onTabChange: (tab: string) => void;
653+
errorFixPrompt?: string;
620654
}) {
621655
return (
622656
<div className="grid h-full max-h-full grid-rows-[auto_1fr] overflow-hidden bg-background-bright">
623-
<ClientTabs defaultValue="ai" className="flex min-h-0 flex-col overflow-hidden pt-1">
657+
<ClientTabs
658+
value={activeTab}
659+
onValueChange={onTabChange}
660+
className="flex min-h-0 flex-col overflow-hidden pt-1"
661+
>
624662
<ClientTabsList variant="underline" className="mx-3 shrink-0">
625663
<ClientTabsTrigger value="ai" variant="underline" layoutId="query-help-tabs">
626664
<div className="flex items-center gap-0.5">
@@ -641,7 +679,11 @@ function QueryHelpSidebar({
641679
value="ai"
642680
className="min-h-0 flex-1 overflow-y-auto p-3 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600"
643681
>
644-
<AITabContent onQueryGenerated={onQueryGenerated} getCurrentQuery={getCurrentQuery} />
682+
<AITabContent
683+
onQueryGenerated={onQueryGenerated}
684+
getCurrentQuery={getCurrentQuery}
685+
errorFixPrompt={errorFixPrompt}
686+
/>
645687
</ClientTabsContent>
646688
<ClientTabsContent
647689
value="guide"
@@ -669,12 +711,17 @@ function QueryHelpSidebar({
669711
function AITabContent({
670712
onQueryGenerated,
671713
getCurrentQuery,
714+
errorFixPrompt,
672715
}: {
673716
onQueryGenerated: (query: string) => void;
674717
getCurrentQuery: () => string;
718+
errorFixPrompt?: string;
675719
}) {
676720
const [autoSubmitPrompt, setAutoSubmitPrompt] = useState<string | undefined>();
677721

722+
// Combine internal autoSubmitPrompt with external errorFixPrompt
723+
const effectiveAutoSubmitPrompt = errorFixPrompt ?? autoSubmitPrompt;
724+
678725
const examplePrompts = [
679726
"Show me failed runs by hour for the past 7 days",
680727
"Count of runs by status by hour for the past 48h",
@@ -687,7 +734,7 @@ function AITabContent({
687734
<div className="space-y-2">
688735
<AIQueryInput
689736
onQueryGenerated={onQueryGenerated}
690-
autoSubmitPrompt={autoSubmitPrompt}
737+
autoSubmitPrompt={effectiveAutoSubmitPrompt}
691738
getCurrentQuery={getCurrentQuery}
692739
/>
693740

0 commit comments

Comments
 (0)