const INTERNAL_MESSAGE_META_PATTERNS = [
  /^Agent\s*[:：]/i,
  /^权限\s*[:：]/,
  /^Run\s*[:：]/i,
  /^工具\s*[:：]/,
  /^能力\s*[:：]/,
  /^Capability\s*[:：]/i,
  /(?:^|[_\s-])user[_\s-]?agent(?:$|[_\s-])/i,
  /\bdraft[_\s-]?write\b/i
]

export function isInternalMessageMeta(item) {
  const normalized = String(item || '').trim()
  return !normalized || INTERNAL_MESSAGE_META_PATTERNS.some((pattern) => pattern.test(normalized))
}

export function filterVisibleMessageMeta(meta = []) {
  return (Array.isArray(meta) ? meta : [])
    .map((item) => String(item || '').trim())
    .filter((item) => item && !isInternalMessageMeta(item))
}
