Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

431 B
Raw Blame
import type { ToolUIPart, UIMessage } from 'ai'

import { sanitizeContractPart } from './registry'
import type { AiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi'

export function sanitizeMessagePart(
  part: UIMessage['parts'][number],
  optInLevel: AiOptInLevel
): UIMessage['parts'][number] {
  if (part.type.startsWith('tool-')) {
    return sanitizeContractPart(part as ToolUIPart, optInLevel) ?? part
  }

  return part
}