The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(studio): clarify assistant tool terminal states (#49364)
Saxon Fletcheree6961beb057
diff --git a/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.test.tsx b/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.test.tsxindex 9eac304587a..974128aa71a 100644--- a/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.test.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.test.tsx@@ -5,48 +5,84 @@ import { MessageProvider } from './Message.Context'import { MessagePartQueryLogs } from './MessagePartQueryLogs'import { customRender as render } from '@/tests/lib/custom-render'-vi.mock('./AssistantQueryCell', () => ({- AssistantQueryCell: ({- sql,- initialResult,+vi.mock('@/components/interfaces/Explorer/QueryEditor', () => ({+ QueryEditor: ({+ query,+ result,}: {- sql: string- initialResult?: { error?: Error }+ query: { uncheckedSql: string }+ result?: { error?: { message?: string } }}) => (- <div>- <span>{sql}</span>- <span>{initialResult?.error?.message}</span>+ <div data-testid="query-editor">+ <span>{query.uncheckedSql}</span>+ <span>{result?.error?.message}</span></div>),}))+vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))+vi.mock('@/state/role-impersonation-state', () => ({+ useLocalRoleImpersonationState: () => ({}),+}))type QueryLogsToolPart = Parameters<typeof MessagePartQueryLogs>[0]['toolPart']+const messageInfo = {+ id: 'message-1',+ isLoading: false,+ state: 'idle' as const,+}++const messageActions = {+ onDelete: vi.fn(),+ onEdit: vi.fn(),+ onBranch: vi.fn(),+ onCancelEdit: vi.fn(),+}++function renderPart(toolPart: Parameters<typeof MessagePartQueryLogs>[0]['toolPart']) {+ return render(+ <MessageProvider messageInfo={messageInfo} messageActions={messageActions}>+ <MessagePartQueryLogs toolPart={toolPart} />+ </MessageProvider>+ )+}+describe('MessagePartQueryLogs', () => {it('renders an output error using raw input when submitted input is unavailable', () => {- const toolPart = {+ renderPart({toolCallId: 'query-logs-1',state: 'output-error',input: undefined,rawInput: { sql: 'select count(*) from edge_logs' },errorText: 'Log query timed out',- } as QueryLogsToolPart-- render(- <MessageProvider- messageInfo={{ id: 'message-1', isLoading: false, state: 'idle' }}- messageActions={{- onDelete: vi.fn(),- onEdit: vi.fn(),- onBranch: vi.fn(),- onCancelEdit: vi.fn(),- }}- >- <MessagePartQueryLogs toolPart={toolPart} />- </MessageProvider>- )+ } as QueryLogsToolPart)expect(screen.getByText('select count(*) from edge_logs')).toBeInTheDocument()expect(screen.getByText('Log query timed out')).toBeInTheDocument()})++ it('uses logs-specific copy for a rendered tool error', () => {+ renderPart({+ toolCallId: 'logs-1',+ state: 'output-error',+ input: { sql: 'select event_message from edge_logs' },+ output: undefined,+ errorText: 'Analytics request failed',+ })++ expect(screen.getByText('Failed to query logs')).toBeInTheDocument()+ expect(screen.queryByText('Failed to execute SQL')).not.toBeInTheDocument()+ })++ it('shows an explicit failure when errored input cannot be parsed', () => {+ renderPart({+ toolCallId: 'logs-2',+ state: 'output-error',+ input: { invalid: true },+ output: undefined,+ errorText: 'Analytics request failed',+ })++ expect(screen.getByText('Failed to query logs.')).toBeInTheDocument()+ })})diff --git a/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.tsx b/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.tsxindex 006dfbcc9d2..c3c1c3d81b7 100644--- a/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/MessagePartQueryLogs.tsx@@ -15,6 +15,10 @@ type QueryLogsToolPart = Pick<'toolCallId' | 'state' | 'input' | 'output' | 'errorText'> & { rawInput?: unknown }+function QueryLogsFailure() {+ return <div className="text-xs text-danger">Failed to query logs.</div>+}+export function MessagePartQueryLogs({ toolPart }: { toolPart: QueryLogsToolPart }) {const { id } = useMessageInfoContext()const { toolCallId, state, input: submittedInput, rawInput, output } = toolPart@@ -31,13 +35,13 @@ export function MessagePartQueryLogs({ toolPart }: { toolPart: QueryLogsToolPartif (state !== 'output-available' && state !== 'output-error') return nullconst parsedInput = parseQueryLogsInput(submittedInput ?? rawInput)- if (!parsedInput.success) return null+ if (!parsedInput.success) return <QueryLogsFailure />const result =state === 'output-error'? { rows: [], error: { message: toolPart.errorText ?? 'Failed to query logs' } }: toQueryLogsResult(output)- if (!result) return null+ if (!result) return <QueryLogsFailure />return (<div className="w-auto overflow-x-hidden my-4 space-y-2">diff --git a/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.test.tsx b/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.test.tsxindex 5a14c8fb112..78682c3dcfa 100644--- a/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.test.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.test.tsx@@ -1,4 +1,4 @@-import { screen, waitFor } from '@testing-library/react'+import { screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { HttpResponse } from 'msw'import { describe, expect, it, vi } from 'vitest'@@ -255,40 +255,12 @@ describe('NotebookProposalRenderer', () => {)})- it('shows the notebook action after an automatic update succeeds', () => {- render(- <NotebookProposalRenderer- mode="update"- state="output-available"- input={{- id: NOTEBOOK_ID,- expected_updated_at: '2024-01-01T00:00:00.000Z',- operations: [{ _tag: 'delete_cell', cell_id: 'cell-1' }],- }}- output={{ id: NOTEBOOK_ID, name: 'Signup funnel' }}- />- )-- expect(screen.getByRole('link', { name: 'Open notebook' })).toHaveAttribute(- 'href',- `/project/default/explorer/notebook/${NOTEBOOK_ID}`- )- })-- it('does not show the "can\'t be applied" warning for a completed update whose target cell no longer exists', async () => {- mockContentItem(- mockNotebookRow({- content: {- schema_version: 1,- cells: [{ _tag: 'markdown_cell', _id: 'cell-2', text: 'world' }],- },- })- )-+ it('renders a stable update summary after success instead of diffing against live content', () => {render(<NotebookProposalRenderermode="update"state="output-available"+ confirmState="success"input={{id: NOTEBOOK_ID,expected_updated_at: '2024-01-01T00:00:00.000Z',@@ -298,16 +270,16 @@ describe('NotebookProposalRenderer', () => {/>)- await waitFor(() => expect(screen.queryByText('Loading notebook...')).not.toBeInTheDocument())+ expect(screen.getByText('Notebook updated: Signup funnel')).toBeInTheDocument()expect(screen.queryByText("This update can't be applied as written")).not.toBeInTheDocument()- expect(screen.getByRole('link', { name: 'Open notebook' })).toBeInTheDocument()+ expect(screen.queryByRole('toolbar', { name: 'Notebook toolbar' })).not.toBeInTheDocument()expect(screen.getByRole('link', { name: 'Open notebook' })).toHaveAttribute('href',`/project/default/explorer/notebook/${NOTEBOOK_ID}`)})- it('shows the notebook action inside the Confirm footer for a manually approved completed update', async () => {+ it('shows the notebook action after a manually approved completed update', async () => {mockContentItem(mockNotebookRow({content: {@@ -339,7 +311,7 @@ describe('NotebookProposalRenderer', () => {expect(screen.queryByText("This update can't be applied as written")).not.toBeInTheDocument()})- it('renders the snapshot-derived diff for a completed delete_cell update, without fetching the notebook', () => {+ it('renders the stable summary instead of a snapshot-derived delete diff after completion', () => {render(<NotebookProposalRenderermode="update"@@ -363,14 +335,15 @@ describe('NotebookProposalRenderer', () => {/>)- expect(screen.getByText('−1')).toBeInTheDocument()+ expect(screen.getByText('Notebook updated: Signup funnel')).toBeInTheDocument()+ expect(screen.queryByText('−1')).not.toBeInTheDocument()expect(screen.getByRole('link', { name: 'Open notebook' })).toHaveAttribute('href',`/project/default/explorer/notebook/${NOTEBOOK_ID}`)})- it('renders a single added cell for a completed insert_cell update, not a phantom duplicate', () => {+ it('renders the stable summary instead of a snapshot-derived insert diff after completion', () => {render(<NotebookProposalRenderermode="update"@@ -397,8 +370,9 @@ describe('NotebookProposalRenderer', () => {/>)- expect(screen.getByText('+1')).toBeInTheDocument()- expect(screen.getAllByRole('button', { name: 'Added Markdown cell' })).toHaveLength(1)+ expect(screen.getByText('Notebook updated: Signup funnel')).toBeInTheDocument()+ expect(screen.queryByText('+1')).not.toBeInTheDocument()+ expect(screen.queryByRole('button', { name: 'Added Markdown cell' })).not.toBeInTheDocument()})it('falls back to the compact completed body when previous_content is absent', () => {@@ -474,9 +448,7 @@ describe('NotebookProposalRenderer', () => {expect(screen.queryByText('−1')).not.toBeInTheDocument()})- it('derives the diff against live content for a denied update', async () => {- mockContentItem(mockNotebookRow())-+ it('renders a stable summary for a denied update without diffing against live content', () => {render(<NotebookProposalRenderermode="update"@@ -491,12 +463,12 @@ describe('NotebookProposalRenderer', () => {/>)- expect(await screen.findByText('−1')).toBeInTheDocument()+ expect(screen.getByText('Skipped notebook update')).toBeInTheDocument()+ expect(screen.queryByText('−1')).not.toBeInTheDocument()+ expect(screen.queryByRole('toolbar', { name: 'Notebook toolbar' })).not.toBeInTheDocument()})- it('derives the diff against live content for an errored update', async () => {- mockContentItem(mockNotebookRow())-+ it('renders a stable summary for an errored update without diffing against live content', () => {render(<NotebookProposalRenderermode="update"@@ -511,7 +483,9 @@ describe('NotebookProposalRenderer', () => {/>)- expect(await screen.findByText('−1')).toBeInTheDocument()+ expect(screen.getByText('Failed to update notebook')).toBeInTheDocument()+ expect(screen.queryByText('−1')).not.toBeInTheDocument()+ expect(screen.queryByRole('toolbar', { name: 'Notebook toolbar' })).not.toBeInTheDocument()})it('keeps the create preview and marks it failed when the tool errors', () => {diff --git a/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.tsx b/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.tsxindex 6da17157fa7..48d3a47615d 100644--- a/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/NotebookProposalRenderer.tsx@@ -98,6 +98,14 @@ const NOTEBOOK_ACTION_NOUN: Record<NotebookProposalMode, string> = {export const NotebookProposalRenderer = (props: NotebookProposalRendererProps) => {const { ref } = useParams()const { mode, state, input, output, confirmState, onApprove, onDeny, denyWithReason } = props++ if (+ mode === 'update' &&+ (state === 'output-available' || state === 'output-error' || state === 'output-denied')+ ) {+ return <UpdateNotebookTerminalSummary state={state} output={output} />+ }+const parsedOutput = notebookToolOutputSchema.safeParse(output)// A deleted notebook no longer exists to open, so this action only applies to create/update.const canOpenNotebook = mode !== 'delete' && state === 'output-available'@@ -149,6 +157,35 @@ export const NotebookProposalRenderer = (props: NotebookProposalRendererProps) =)}+function UpdateNotebookTerminalSummary({+ state,+ output,+}: Pick<NotebookProposalRendererProps, 'state' | 'output'>) {+ const { ref } = useParams()+ const parsedOutput = notebookToolOutputSchema.safeParse(output)+ const label =+ state === 'output-available'+ ? parsedOutput.success+ ? `Notebook updated: ${parsedOutput.data.name}`+ : 'Notebook updated'+ : state === 'output-error'+ ? 'Failed to update notebook'+ : 'Skipped notebook update'++ return (+ <div className="flex items-center justify-between gap-2 my-2 mx-4 px-3 py-1.5 text-sm border rounded-md bg-surface-75">+ <span className="text-foreground-light truncate">{label}</span>+ {state === 'output-available' && parsedOutput.success && ref && (+ <Button asChild variant="default" size="tiny">+ <Link href={`/project/${ref}/explorer/notebook/${parsedOutput.data.id}`}>+ Open notebook+ </Link>+ </Button>+ )}+ </div>+ )+}+interface NotebookConfirmProps {mode: NotebookProposalModeconfirmState?: ConfirmFooterApprovalState