Files
accounted/components/agent/feedback-client.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

36 lines
1.2 KiB
TypeScript

/**
* Send one thumbs vote on an assistant answer.
*
* Kept out of the component so it is testable without a React harness (this
* repo's unit project is node-only), and so the failure contract is stated in
* one place: this resolves false rather than throwing, because a vote that
* cannot be sent must never interrupt reading the answer it was about.
*/
export type FeedbackSentiment = 'positive' | 'negative'
export async function sendFeedback(args: {
conversationId: string
sentiment: FeedbackSentiment
messageIndex?: number
fetchImpl?: typeof fetch
}): Promise<boolean> {
const { conversationId, sentiment, messageIndex, fetchImpl = fetch } = args
try {
const res = await fetchImpl('/api/agent/feedback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
conversation_id: conversationId,
sentiment,
...(messageIndex === undefined ? {} : { message_index: messageIndex }),
}),
})
return res.ok
} catch {
// Offline, or the request was cut off by a navigation. Reported as a
// failed vote so the button can go back to unpressed rather than claiming
// a report that never arrived.
return false
}
}