Skip to content

The open alternative to Salesforce, designed for AI.

364 B
Raw Blame
import { isNonEmptyString } from '@sniptt/guards';
import { type ExtendedUIMessagePart } from 'twenty-shared/ai';

export const findLastMessageText = (
  parts: ExtendedUIMessagePart[],
): string | null =>
  parts
    .flatMap((part) =>
      part.type === 'text' && isNonEmptyString(part.text.trim())
        ? [part.text]
        : [],
    )
    .pop() ?? null;