mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? This adds a component showing a list of AI curated related threads to the detail thread view. ## What is the current behavior? This is not available. ## What is the new behavior? A new component on the thread view. ## Additional context Add any other context or screenshots. --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
'use server'
|
|
|
|
import { createContributeServerClient } from '~/lib/supabaseContribute.server'
|
|
import type {
|
|
SimilarThreadFeedbackSubmission,
|
|
SimilarThreadFeedbackResult,
|
|
} from '~/types/contribute'
|
|
|
|
const CONTRIBUTE_FEEDBACK_FN = 'contribute-feedback'
|
|
|
|
export async function submitSimilarThreadFeedback(
|
|
submission: SimilarThreadFeedbackSubmission
|
|
): Promise<SimilarThreadFeedbackResult> {
|
|
const supabase = await createContributeServerClient()
|
|
|
|
const { data, error } = await supabase.functions.invoke<{ id: string }>(CONTRIBUTE_FEEDBACK_FN, {
|
|
body: {
|
|
action: 'create',
|
|
parent_thread_id: submission.parentThreadId,
|
|
similar_thread_key: submission.similarThreadKey ?? null,
|
|
reaction: submission.reaction,
|
|
},
|
|
})
|
|
|
|
if (error) {
|
|
console.error('[SimilarThreadFeedback] create error:', error)
|
|
return { success: false }
|
|
}
|
|
|
|
const id = data?.id
|
|
if (!id) {
|
|
console.error('[SimilarThreadFeedback] create: no id in response')
|
|
return { success: false }
|
|
}
|
|
|
|
return { success: true, id }
|
|
}
|
|
|
|
export async function updateSimilarThreadFeedback(
|
|
id: string,
|
|
reaction: 'positive' | 'negative',
|
|
feedback: string | null
|
|
): Promise<SimilarThreadFeedbackResult> {
|
|
const supabase = await createContributeServerClient()
|
|
|
|
const { data, error } = await supabase.functions.invoke<{ success: boolean }>(
|
|
CONTRIBUTE_FEEDBACK_FN,
|
|
{
|
|
body: {
|
|
action: 'update',
|
|
id,
|
|
reaction,
|
|
feedback: feedback ?? null,
|
|
},
|
|
}
|
|
)
|
|
|
|
if (error) {
|
|
console.error('[SimilarThreadFeedback] update error:', error)
|
|
return { success: false }
|
|
}
|
|
|
|
if (!data?.success) {
|
|
console.error('[SimilarThreadFeedback] update: unexpected response')
|
|
return { success: false }
|
|
}
|
|
|
|
return { success: true }
|
|
}
|