// 处理标签内容的辅助函数
export const processTagContent = (answerCache, tagName, cachedMessage) => {
  // 检查是否包含完整的开始标签
  const startTag = `<${tagName}>`
  const endTag = `</${tagName}>`

  // 如果正在处理该标签
  if (cachedMessage.respondingType === tagName) {
    // 检查是否包含结束标签
    if (answerCache.includes(endTag)) {
      // 提取结束标签前的内容
      const content = answerCache.split(endTag)[0]
      cachedMessage[tagName] += content
      cachedMessage.respondingType = ''
      cachedMessage[`${tagName}Finished`] = true
      return answerCache.split(endTag)[1] || ''
    } else {
      // 继续累积内容
      cachedMessage[tagName] += answerCache
      return ''
    }
  }

  // 检查是否包含开始标签
  if (answerCache.includes(startTag)) {
    cachedMessage.respondingType = tagName
    const tagContent = answerCache.split(startTag)[1] || ''

    // 检查开始标签后是否立即包含结束标签
    if (tagContent.includes(endTag)) {
      const content = tagContent.split(endTag)[0]
      cachedMessage[tagName] = content
      cachedMessage.respondingType = ''
      return answerCache.split(endTag)[1] || ''
    } else {
      // 只有开始标签，累积内容
      cachedMessage[tagName] = tagContent
      return ''
    }
  }

  return answerCache
}
