mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
## Summary * Query blocks embedded inside an active assistant conversation (`AssistantQueryCell`) reused the same "Debug with Assistant" handler as standalone query blocks (Explorer Query tab, notebook cells), which always opens a brand-new chat and navigates away. * Clicking Debug on a block that's already part of the open conversation silently abandoned it for an unrelated new chat, which read as the button doing nothing. * Added an optional `onDebug` override threaded through `QueryEditor` → `QueryResultRenderer` → `QueryResultError`; `AssistantQueryCell` now uses it to write the debug prompt into the currently active chat's composer (`ai-assistant-state`'s new `setInitialInput`) instead of creating a new chat. Standalone query blocks keep the existing "open a new chat" behavior since no `onDebug` override is passed there. * `ExplorerChatTab` now wires `composerContext` into `AssistantChat` (it wasn't before), so the pre-filled prompt actually reaches the visible textarea on the Explorer chat route. Fixes [FE-4319](https://linear.app/supabase/issue/FE-4319/debug-with-ai-assistant-does-seemingly-nothing-if-query-is-already). ## Test plan - [X] `pnpm vitest run` on `QueryResultError.test.tsx` / `QueryResultError.selfhosted.test.tsx` / `ExplorerChatTab.test.tsx` / `AssistantQueryCell.utils.test.ts` — all pass, including new test asserting `onDebug` is called instead of `createChat`. - [X] `pnpm exec eslint` on touched files — clean (only pre-existing unrelated warnings). - [X] Manual check: run a query inside an assistant chat that errors, click "Debug with Assistant" on that block, confirm the debug prompt appears in the current chat's composer rather than opening a new chat. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a “Debug with Assistant” workflow that sends SQL error details to the AI Assistant as its initial input. * Preserved the existing behavior of opening a new debug chat when the Assistant panel is unavailable. * **Tests** * Added coverage confirming that debugging invokes the Assistant callback without creating an additional chat. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { type SqlSnippetSource } from '../../SQLEditor/querySource'
|
|
import { type QueryResult } from '../types'
|
|
import { QueryResultChart } from './QueryResultChart'
|
|
import { QueryResultError } from './QueryResultError'
|
|
import { DataGridResults } from '@/components/ui/DataGridResults'
|
|
import { type ChartConfig } from '@/data/content/notebooks/notebook-schema'
|
|
|
|
interface QueryResultRendererProps {
|
|
result?: QueryResult
|
|
view?: 'table' | 'chart'
|
|
chart?: ChartConfig
|
|
/** The query that produced `result`, used to build the "Debug with Assistant" prompt on error. */
|
|
sql?: string
|
|
source?: SqlSnippetSource
|
|
onDebug?: (prompt: string) => void
|
|
}
|
|
|
|
export const QueryResultRenderer = ({
|
|
result,
|
|
view,
|
|
chart,
|
|
sql,
|
|
source,
|
|
onDebug,
|
|
}: QueryResultRendererProps) => {
|
|
const { rows, error, autoLimit } = result ?? {}
|
|
|
|
if (!result) {
|
|
return <p className="text-xs text-foreground-lighter py-8">Run the query to see results</p>
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<QueryResultError
|
|
error={error}
|
|
autoLimit={autoLimit}
|
|
sql={sql}
|
|
source={source}
|
|
onDebug={onDebug}
|
|
/>
|
|
)
|
|
}
|
|
|
|
if ((rows ?? []).length === 0) {
|
|
return <p className="text-xs text-foreground-lighter py-8">Success. No rows returned</p>
|
|
}
|
|
|
|
if (rows && rows.length > 0) {
|
|
if (view === 'table') return <DataGridResults rows={rows} />
|
|
if (view === 'chart') return <QueryResultChart chart={chart} result={result} />
|
|
}
|
|
|
|
return null
|
|
}
|