mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
* Add two more sizes to the Panel component. * Add alias for the older openai-api library. The new one is added under the openai name. * Add API routes * Add components for the new AI RLS panel. * Bunch of changes to the AI Policy Editor. * Add a button for opening the new Policy Editor. * Add a feature flag for the new editor. * Add a confirmation modal when closing the panel. * Fix leftover data when closing the panel. * Make the copy button work. * Add the next/swc packages to package-lock.json. * Merge master * Scaffold debug sql in rls editor * Small improvements to policy chat * Hook up debug to ai assistant panel * Improve debug UX * Add debug request badge * Some styling fix * Small styling fix * Another small styling fix * Shift create new policy ai button + fix error stylign with code editor height * Add tooltips to apply changes and copy code from assistant message * Hide assistant button is not platform * Small lint * Add default error handlers to all AI RQ mutations * Small fix * Remove IS PLATFORM check for rls assistant * Add placeholder to RLS code editor * Fix diff + rls code editor * Add placeholder message after sending prompt * Small style * RLSCodeEditor hit tab if empty to populate placeholder text * Light mode nudeges * Update logic for when confirmation close modal should show * Set render overview ruler as false for rls diff editor * improve chat UX to make it smoother (thank you alaister for your help 🙏) * Dynamically do keepPreviousData * Gracefully handle errors for add prompt * Use animated ai icon while message is loading * using Sheet component * Address commernts * Bit more improvements --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { isResponseOk, post } from 'lib/common/fetch'
|
|
import { BASE_PATH } from 'lib/constants'
|
|
import { ResponseError } from 'types'
|
|
|
|
export type SqlTitleGenerateResponse = {
|
|
title: string
|
|
description: string
|
|
}
|
|
|
|
export type SqlTitleGenerateVariables = {
|
|
sql: string
|
|
}
|
|
|
|
export async function generateSqlTitle({ sql }: SqlTitleGenerateVariables) {
|
|
const response = await post<SqlTitleGenerateResponse>(BASE_PATH + '/api/ai/sql/title', { sql })
|
|
|
|
if (!isResponseOk(response)) {
|
|
throw response.error
|
|
}
|
|
|
|
return response
|
|
}
|
|
|
|
type SqlTitleGenerateData = Awaited<ReturnType<typeof generateSqlTitle>>
|
|
|
|
export const useSqlTitleGenerateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<SqlTitleGenerateData, ResponseError, SqlTitleGenerateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<SqlTitleGenerateData, ResponseError, SqlTitleGenerateVariables>(
|
|
(vars) => generateSqlTitle(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to generate title: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|