mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 01:40:13 -04:00
626eb30e77
* update onboarding * update model and fix part issue * action orientated assistant * fix tool * lock * remove unused filter * fix tests * fix again * update package * update container * fix tests * refactor(ai assistant): break out message markdown and profile picture * wip * refactor(ai assistant): break up message component * refactor: break ai assistant message down into multiple files * refactor: simplify ReportBlock state * fix: styling of draggable report block header When the drag handle is showing, it overlaps with the block header. Decrease the opacity of the header so the handle can be seen and the two can be distinguished. * fix: minor tweaks to tool ui * refactor: simplify DisplayBlockRenderer state * fix: remove double deploy button in edge function block When the confirm footer is shown, the deploy button on the top right should be hidden (not just disabled) to avoid confusion. * refactor, test: message sanitization by opt-in level Refactor the message sanitization to have more type safety and be more testable. Add tests to ensure: - Message sanitization always runs on generate-v4 - Message sanitization correctly works by opt-in level * Fix conflicts in pnpm lock * Couple of nits and refactors * Revert casing for report block snippet * adjust sanitised prompt * Fix tests --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
26 lines
973 B
TypeScript
26 lines
973 B
TypeScript
import type { UIMessage } from 'ai'
|
|
|
|
/**
|
|
* Prepares messages for API transmission by cleaning and limiting history
|
|
*/
|
|
export function prepareMessagesForAPI(messages: UIMessage[]): UIMessage[] {
|
|
// [Joshen] Specifically limiting the chat history that get's sent to reduce the
|
|
// size of the context that goes into the model. This should always be an odd number
|
|
// as much as possible so that the first message is always the user's
|
|
const MAX_CHAT_HISTORY = 7
|
|
|
|
const slicedMessages = messages.slice(-MAX_CHAT_HISTORY)
|
|
|
|
// Filter out results from messages before sending to the model
|
|
const cleanedMessages = slicedMessages.map((_message) => {
|
|
const message = _message as UIMessage & { results?: unknown }
|
|
const cleanedMessage = { ...message } as UIMessage & { results?: unknown }
|
|
if (message.role === 'assistant' && message.results) {
|
|
delete cleanedMessage.results
|
|
}
|
|
return cleanedMessage as UIMessage
|
|
})
|
|
|
|
return cleanedMessages
|
|
}
|