aiChat.vue 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  1. <template>
  2. <div class="ai-chat-container">
  3. <div class="message-quick-box">
  4. <div class="message-quick-box-item" :class="{ 'active': isQuickActions.includes('quick') }">
  5. <button type="button" class="coco-collapse-trigger" @click="toggleQuickActions('quick')">
  6. <span class="coco-collapse-icon soft-orange">
  7. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"
  8. stroke-linecap="round">
  9. <path d="M4 7h16"></path>
  10. <path d="M4 12h10"></path>
  11. <path d="M4 17h7"></path>
  12. </svg>
  13. </span>
  14. <span class="coco-collapse-copy">
  15. <span class="coco-collapse-title">{{ lang.ssAiChatQuickTitle }}</span>
  16. <span class="coco-collapse-subtitle" id="cocoQuickSectionHint">{{ lang.ssAiChatQuickSubtitle }}</span>
  17. </span>
  18. <span class="coco-collapse-chevron">
  19. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  20. <polyline points="6 9 12 15 18 9"></polyline>
  21. </svg>
  22. </span>
  23. </button>
  24. <div class="coco-collapse-body" v-if="isQuickActions.includes('quick')">
  25. <div class="coco-quick-tabs">
  26. <button type="button" class="coco-quick-tab" :class="{ 'active': cocoQuickTab === 'page' }"
  27. @click="setCocoQuickTab('page')">{{ lang.ssAiChatQuickTabPage }}</button>
  28. <button type="button" class="coco-quick-tab" :class="{ 'active': cocoQuickTab === 'course' }"
  29. @click="setCocoQuickTab('course')">{{ lang.ssAiChatQuickTabCourse }}</button>
  30. </div>
  31. <div class="coco-quick-list">
  32. <button type="button" class="coco-quick-action" v-if="cocoQuickTab === 'page'"
  33. @click="sendQuickAction(lang.ssAiChatQuickAction3)">
  34. <span class="coco-quick-action-copy">
  35. <span class="coco-quick-action-title">{{ lang.ssAiChatQuickGenChoicesTitle }}</span>
  36. <span class="coco-quick-action-desc">{{ lang.ssAiChatQuickGenChoicesDesc }}</span>
  37. </span>
  38. <span class="coco-quick-action-arrow">
  39. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
  40. stroke-linecap="round" stroke-linejoin="round">
  41. <path d="M5 12h14"></path>
  42. <path d="M13 5l7 7-7 7"></path>
  43. </svg>
  44. </span>
  45. </button>
  46. <button type="button" class="coco-quick-action" v-if="cocoQuickTab === 'page'"
  47. @click="sendQuickAction(lang.ssAiChatQuickAction4)">
  48. <span class="coco-quick-action-copy">
  49. <span class="coco-quick-action-title">{{ lang.ssAiChatQuickGenWebTitle }}</span>
  50. <span class="coco-quick-action-desc">{{ lang.ssAiChatQuickGenWebDesc }}</span>
  51. </span>
  52. <span class="coco-quick-action-arrow">
  53. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
  54. stroke-linecap="round" stroke-linejoin="round">
  55. <path d="M5 12h14"></path>
  56. <path d="M13 5l7 7-7 7"></path>
  57. </svg>
  58. </span>
  59. </button>
  60. <button type="button" class="coco-quick-action" v-if="cocoQuickTab === 'course'"
  61. @click="sendQuickAction(lang.ssAiChatQuickAction5)">
  62. <span class="coco-quick-action-copy">
  63. <span class="coco-quick-action-title">{{ lang.ssAiChatQuickRecommendToolsTitle }}</span>
  64. <span class="coco-quick-action-desc">{{ lang.ssAiChatQuickRecommendToolsDesc }}</span>
  65. </span>
  66. <span class="coco-quick-action-arrow">
  67. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
  68. stroke-linecap="round" stroke-linejoin="round">
  69. <path d="M5 12h14"></path>
  70. <path d="M13 5l7 7-7 7"></path>
  71. </svg>
  72. </span>
  73. </button>
  74. <button type="button" class="coco-quick-action" v-if="cocoQuickTab === 'course'" @click="sendQuickAction(lang.ssBatchInteractiveWeb)">
  75. <span class="coco-quick-action-copy">
  76. <span class="coco-quick-action-title">{{ lang.ssAiChatQuickBatchGenToolsTitle }}</span>
  77. <span class="coco-quick-action-desc">{{ lang.ssAiChatQuickBatchGenToolsDesc }}</span>
  78. </span>
  79. <span class="coco-quick-action-arrow">
  80. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  81. <path d="M5 12h14"></path>
  82. <path d="M13 5l7 7-7 7"></path>
  83. </svg>
  84. </span>
  85. </button>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. <!-- 聊天区域 -->
  91. <div class="chat-section" ref="chatSection">
  92. <!-- 消息列表 -->
  93. <div v-for="(message, index) in messages" :key="index" class="chat-message">
  94. <div class="message-content user-message chat" v-if="message.content">
  95. <div v-html="message.content"></div>
  96. <!-- 显示上传的文件 -->
  97. <div class="message-files" v-if="message.sourceFiles && message.sourceFiles.length > 0">
  98. <div v-for="(file, index) in message.sourceFiles" :key="index" class="message-file-item">
  99. <span>{{ file.title }}</span>
  100. </div>
  101. </div>
  102. </div>
  103. <div class="message-content ai-message chat" :class="{'loading-state': message.chatloading && message.jsonData?.gType === 'trigger_batch_tool'}" v-if="message.aiContent || message.chatloading">
  104. <div class="submenu-icon loading-icon" v-show="message.chatloading && message.jsonData?.gType === 'trigger_batch_tool'">
  105. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="spin">
  106. <circle cx="12" cy="12" r="10" stroke-dasharray="32" stroke-dashoffset="12"></circle>
  107. </svg>
  108. </div>
  109. <div v-if="message.aiContent" v-html="message.aiContent"></div>
  110. <svg v-else xmlns="http://www.w3.org/2000/svg" width="32" height="32"
  111. viewBox="0 0 24 24"><!-- Icon from SVG Spinners by Utkarsh Verma - https://github.com/n3r4zzurr0/svg-spinners/blob/main/LICENSE -->
  112. <circle cx="4" cy="12" r="3" fill="currentColor">
  113. <animate id="svgSpinners3DotsBounce0" attributeName="cy" begin="0;svgSpinners3DotsBounce1.end+0.25s"
  114. calcMode="spline" dur="0.6s" keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12" />
  115. </circle>
  116. <circle cx="12" cy="12" r="3" fill="currentColor">
  117. <animate attributeName="cy" begin="svgSpinners3DotsBounce0.begin+0.1s" calcMode="spline" dur="0.6s"
  118. keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12" />
  119. </circle>
  120. <circle cx="20" cy="12" r="3" fill="currentColor">
  121. <animate id="svgSpinners3DotsBounce1" attributeName="cy" begin="svgSpinners3DotsBounce0.begin+0.2s"
  122. calcMode="spline" dur="0.6s" keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12" />
  123. </circle>
  124. </svg>
  125. <button class="confirm-btn" :class="{ disabled: message.jsonData?.isGenerate }"
  126. v-if="message.jsonData?.gType !== 'chat' && message.jsonData?.gType !== 'generate_interactive_web' && message.jsonData?.gType !== 'trigger_tool_recommend' && message.jsonData?.gType !== 'trigger_batch_tool' && !message.chatloading && message.aiContent"
  127. @click="generate(message)">{{ message.gLoading ? lang.ssLoading : lang.ssConfirm }}</button>
  128. <button type="button" class="coco-interactive-web-card"
  129. v-if="message.jsonData?.gType === 'generate_interactive_web' && !message.chatloading" :class="{ 'loading-state': create_app_loading }" @click="!create_app_loading && handle_add_aiWeb()">
  130. <div class="submenu-icon loading-icon" v-show="create_app_loading">
  131. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="spin">
  132. <circle cx="12" cy="12" r="10" stroke-dasharray="32" stroke-dashoffset="12"></circle>
  133. </svg>
  134. </div>
  135. <div class="coco-interactive-web-card-head">
  136. <div class="coco-interactive-web-card-title">{{ lang.ssInteractiveWebTitle }}</div>
  137. <!-- <span class="coco-interactive-web-card-status">待确认</span> -->
  138. </div>
  139. <div class="coco-interactive-web-card-desc">{{ lang.ssInteractiveWebDesc }}</div>
  140. <div class="coco-interactive-web-card-foot">
  141. <span class="coco-interactive-web-card-action">{{ lang.ssOpenWorkspace }}</span>
  142. </div>
  143. </button>
  144. </div>
  145. </div>
  146. </div>
  147. <!-- 输入区域 -->
  148. <div class="input-section">
  149. <div class="input-wrapper">
  150. <div class="file-box" v-show="files.length">
  151. <div v-for="(file, index) in files" :key="index" class="file-item">
  152. <span class="file-name">{{ file.title }}</span>
  153. <button class="remove-file-btn" @click="removeFile(index)">
  154. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
  155. stroke-linejoin="round">
  156. <line x1="18" y1="6" x2="6" y2="18"></line>
  157. <line x1="6" y1="6" x2="18" y2="18"></line>
  158. </svg>
  159. </button>
  160. </div>
  161. </div>
  162. <textarea class="ai-input" :placeholder="lang.ssAiChatShortcut" v-model="inputText"
  163. @keyup.enter.exact="sendMessage" rows="5" />
  164. <div class="input-actions">
  165. <FileInput accept="*" @change="handleFileUpload">
  166. <button class="attach-btn">
  167. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  168. <path
  169. d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48">
  170. </path>
  171. </svg>
  172. </button>
  173. </FileInput>
  174. <button class="send-btn" @click="sendMessage" v-if="!chatLoading">
  175. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
  176. stroke-linejoin="round">
  177. <line x1="22" y1="2" x2="11" y2="13"></line>
  178. <polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
  179. </svg>
  180. </button>
  181. <button class="send-btn stop" @click="stopMessage" v-if="chatLoading">
  182. <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
  183. <rect width="32" height="32" rx="16" fill="black" fill-opacity="0.4"></rect>
  184. <path
  185. d="M11.3333 12.333C11.3333 11.7807 11.781 11.333 12.3333 11.333H19.6666C20.2189 11.333 20.6666 11.7807 20.6666 12.333V19.6663C20.6666 20.2186 20.2189 20.6663 19.6666 20.6663H12.3333C11.781 20.6663 11.3333 20.2186 11.3333 19.6663V12.333Z"
  186. fill="white" fill-opacity="0.9"></path>
  187. </svg>
  188. </button>
  189. </div>
  190. </div>
  191. <!-- 输入时的快捷操作弹出 -->
  192. <div class="quick-actions-popup" v-if="showQuickActions">
  193. <button v-for="(action, index) in quickActions" :key="index" class="quick-action-btn"
  194. @click="sendQuickAction(action)">{{ action }}</button>
  195. </div>
  196. </div>
  197. <!-- 初始状态 -->
  198. <div class="initial-state" v-if="false">
  199. <!-- 快捷操作 -->
  200. <div class="quick-actions">
  201. <button v-for="(action, index) in quickActions" :key="index" class="quick-action-btn"
  202. @click="sendQuickAction(action)">{{ action }}</button>
  203. </div>
  204. </div>
  205. <AiWeb :visible="showAiWebModal" :web-id="webId" @close="showAiWebModal = false" @add="addAiWeb" :is-loading="isLoading" />
  206. </div>
  207. </template>
  208. <script lang="ts" setup>
  209. import { ref, onMounted, useTemplateRef, nextTick, watch } from 'vue'
  210. import { chat_no_stream, chat_stream, getAgentModel, chat_no_stream2 } from '@/tools/aiChat'
  211. import { useSlidesStore, useMainStore } from '@/store'
  212. import { lang } from '@/main'
  213. import MarkdownIt from 'markdown-it'
  214. import { getWorkPageId } from '@/services/course'
  215. import FileInput from '@/components/FileInput2.vue'
  216. import axios from '@/services/config'
  217. import message from '@/utils/message'
  218. import AiWeb from './aiWeb.vue'
  219. interface ChatMessage {
  220. uid?: string
  221. role: 'ai' | 'user'
  222. content?: string
  223. aiContent?: string
  224. oldContent?: string
  225. loading?: boolean
  226. chatloading?: boolean
  227. gLoading?: boolean
  228. rawContent?: string
  229. timestamp?: Date
  230. like?: boolean
  231. unlike?: boolean
  232. isTyping?: boolean
  233. AI?: string
  234. isShowSynchronization?: boolean
  235. filename?: string
  236. is_mind_map?: boolean
  237. sourceFiles?: Array<{
  238. title: string
  239. id?: string
  240. url?: string
  241. }>
  242. jsonData?: {
  243. gType?: string
  244. isGenerate?: boolean
  245. headUrl?: string
  246. assistantName?: string
  247. files?: Array<{
  248. title: string
  249. id?: string
  250. url?: string
  251. }>
  252. sourceArray?: Array<{
  253. text?: string
  254. id?: string
  255. title?: string
  256. }>
  257. aiContent?: string
  258. }
  259. }
  260. const props = withDefaults(defineProps<{
  261. userid?: string | null
  262. userJson?: any
  263. courseTitle?: string | null
  264. }>(), {
  265. userid: null,
  266. userJson: null,
  267. courseTitle: null,
  268. })
  269. const inputText = ref('')
  270. const messages = ref<ChatMessage[]>([])
  271. const chatSection = useTemplateRef<HTMLElement>('chatSection')
  272. const chatLoading = ref(false)
  273. const showQuickActions = ref(false)
  274. const streamController = ref<{ abort: () => void } | null>(null)
  275. const noStreamController = ref<{ promise: Promise<string>; abort: () => void } | null>(null)
  276. const files = ref<Array<{ title: string; id?: string | null; url?: string; isProcessing?: boolean; cancel?: () => void }>>([])
  277. // 快捷操作短语数组
  278. const quickActions = [
  279. lang.ssAiChatQuickAction1,
  280. lang.ssAiChatQuickAction2,
  281. lang.ssAiChatQuickAction6,
  282. lang.ssAiChatQuickAction7,
  283. ]
  284. // 监听输入变化,当输入"/"时显示快捷操作
  285. watch(inputText, (newValue) => {
  286. // messages.value.length > 0 &&
  287. if (newValue === '/') {
  288. showQuickActions.value = true
  289. }
  290. else if (newValue !== '/') {
  291. showQuickActions.value = false
  292. }
  293. })
  294. const sendMessage = () => {
  295. if (chatLoading.value) {
  296. return
  297. }
  298. // 检查是否有文件正在处理中
  299. const hasProcessingFile = files.value.some(file => file.isProcessing)
  300. if (hasProcessingFile) {
  301. message.error(lang.ssAiChatWaitUpload)
  302. return
  303. }
  304. if (inputText.value.trim() || files.value.length > 0) {
  305. // 添加用户消息
  306. messages.value.push({
  307. role: 'user',
  308. content: inputText.value,
  309. })
  310. // 模拟AI回复
  311. // setTimeout(() => {
  312. // setTimeout(() => {
  313. // messages.value.at(-1).aiContent = '课程生成完成!为您创建了5个内容页面和3个互动工具。您可以查看底部课程大纲,或在中央区域开始编辑。',
  314. // messages.value.at(-1).jsonData = {
  315. // isChoice: true
  316. // }
  317. // }, 1000)
  318. // }, 500)
  319. prevChatResult()
  320. messages.value.at(-1).loading = true
  321. messages.value.at(-1).chatloading = true
  322. messages.value.at(-1).sourceFiles = files.value.filter(file => file.id !== null).map(file => ({
  323. title: file.title,
  324. id: file.id
  325. }))
  326. chatLoading.value = true
  327. sendAction(inputText.value)
  328. inputText.value = ''
  329. files.value = []
  330. }
  331. }
  332. const stopMessage = () => {
  333. if (streamController.value) {
  334. streamController.value.abort()
  335. streamController.value = null
  336. }
  337. if (noStreamController.value) {
  338. noStreamController.value.abort()
  339. noStreamController.value = null
  340. }
  341. chatLoading.value = false
  342. if (messages.value.length > 0) {
  343. messages.value.at(-1).chatloading = false
  344. messages.value.at(-1).loading = false
  345. }
  346. }
  347. // 处理文件上传
  348. const handleFileUpload = async (files2: File[]) => {
  349. const maxSize = 10 * 1024 * 1024 // 10MB
  350. const uploadPromises = []
  351. for (let i = 0; i < files2.length; i++) {
  352. const file = files2[i]
  353. if (file.size > maxSize) {
  354. message.error(lang.ssAiChatFileSizeLimit)
  355. continue
  356. }
  357. // 先添加文件到列表,显示解析中状态
  358. const fileIndex = files.value.length
  359. files.value.push({
  360. title: file.name + ' (' + lang.ssAiChatParsing + ')',
  361. id: null,
  362. isProcessing: true,
  363. cancel: null
  364. })
  365. // 创建取消控制器
  366. const controller = new AbortController()
  367. files.value[fileIndex].cancel = () => {
  368. controller.abort()
  369. files.value.splice(fileIndex, 1)
  370. }
  371. // 创建上传Promise并添加到数组
  372. const uploadPromise = uploadFile2(file, controller.signal).then(res => {
  373. if (!res) {
  374. files.value.splice(fileIndex, 1)
  375. return
  376. }
  377. // 上传成功,更新文件状态
  378. files.value[fileIndex] = {
  379. title: file.name,
  380. id: res.results.document_id,
  381. isProcessing: false
  382. }
  383. }).catch(error => {
  384. if (error.name !== 'AbortError') {
  385. console.error(lang.ssAiChatUploadFailed, error)
  386. files.value.splice(fileIndex, 1)
  387. }
  388. })
  389. uploadPromises.push(uploadPromise)
  390. }
  391. // 等待所有文件上传完成
  392. await Promise.allSettled(uploadPromises)
  393. }
  394. // 移除文件
  395. const removeFile = (index: number) => {
  396. const file = files.value[index]
  397. if (file && file.isProcessing && file.cancel) {
  398. file.cancel()
  399. }
  400. files.value.splice(index, 1)
  401. }
  402. const prevChatResult = () => {
  403. nextTick(() => {
  404. if (chatSection.value) {
  405. chatSection.value.scrollTop = chatSection.value.scrollHeight
  406. }
  407. })
  408. }
  409. const sendQuickAction = (action: string) => {
  410. inputText.value = action
  411. // sendMessage()
  412. }
  413. import { v4 as uuidv4 } from 'uuid'
  414. const session_name = ref('')
  415. const slidesStore = useSlidesStore()
  416. const mainStore = useMainStore()
  417. const gType = ref('chat')
  418. const sendAction = async (action: string) => {
  419. const md = new MarkdownIt()
  420. if (gType.value === 'chat' || gType.value === 'generate_interactive_web' || gType.value === 'trigger_tool_recommend' || gType.value === 'trigger_batch_tool') {
  421. const result = chat_no_stream(action, agentid1.value, props.userid || '', lang.lang)
  422. noStreamController.value = result
  423. console.log(result)
  424. const content = await result.promise
  425. if (!content) {
  426. stopMessage()
  427. return
  428. }
  429. console.log(content)
  430. // 渲染 Markdown 格式
  431. try {
  432. gType.value = JSON.parse(content).intent
  433. }
  434. catch (error) {
  435. gType.value = 'chat'
  436. }
  437. // generate_qa // generate_choice_question // generate_photo // generate_poll
  438. if (gType.value !== 'chat' && gType.value !== 'generate_interactive_web' && gType.value !== 'trigger_batch_tool') {
  439. messages.value.at(-1).jsonData = {
  440. gType: gType.value,
  441. isGenerate: false
  442. }
  443. }
  444. else if (gType.value === 'generate_interactive_web') {
  445. messages.value.at(-1).jsonData = {
  446. gType: gType.value,
  447. isGenerate: false
  448. }
  449. messages.value.at(-1).aiContent = lang.ssInteractiveWebWorkspaceDesc
  450. messages.value.at(-1).loading = false
  451. messages.value.at(-1).chatloading = false
  452. chatLoading.value = false
  453. return
  454. }
  455. else if (gType.value === 'trigger_batch_tool') {
  456. messages.value.at(-1).jsonData = {
  457. gType: gType.value,
  458. isGenerate: false
  459. }
  460. let isHave = 1
  461. for (let i = 0; i < slidesStore.slides.length; i++) {
  462. const slide = slidesStore.slides[i]
  463. if (slide.toolsArray && slide.toolsArray.length > 0) {
  464. const hasUnprocessed = slide.toolsArray.length
  465. if (hasUnprocessed) {
  466. isHave = 2
  467. break
  468. }
  469. }
  470. }
  471. if (isHave == 2) {
  472. messages.value.at(-1).aiContent = lang.ssBatchInteractiveWebDesc3
  473. messages.value.at(-1).loading = false
  474. chatLoading.value = false
  475. messages.value.at(-1).chatloading = false
  476. return
  477. }
  478. messages.value.at(-1).aiContent = lang.ssBatchInteractiveWebDesc
  479. // messages.value.at(-1).loading = false
  480. // messages.value.at(-1).chatloading = false
  481. // chatLoading.value = false
  482. // return
  483. }
  484. if (content.includes(lang.ssAiChatQuickGenWebTitle)) {
  485. gType.value = 'generate_interactive_web'
  486. messages.value.at(-1).jsonData = {
  487. gType: 'generate_interactive_web',
  488. isGenerate: false
  489. }
  490. messages.value.at(-1).aiContent = lang.ssInteractiveWebWorkspaceDesc
  491. messages.value.at(-1).loading = false
  492. chatLoading.value = false
  493. messages.value.at(-1).chatloading = false
  494. return
  495. }
  496. if (content.includes(lang.ssAiChatQuickAction5)) {
  497. gType.value = 'trigger_tool_recommend'
  498. messages.value.at(-1).jsonData = {
  499. gType: 'trigger_tool_recommend',
  500. isGenerate: false
  501. }
  502. }
  503. if (content.includes(lang.ssBatchInteractiveWeb)) {
  504. gType.value = 'trigger_batch_tool'
  505. messages.value.at(-1).jsonData = {
  506. gType: 'trigger_batch_tool',
  507. isGenerate: false
  508. }
  509. let isHave = 1
  510. for (let i = 0; i < slidesStore.slides.length; i++) {
  511. const slide = slidesStore.slides[i]
  512. if (slide.toolsArray && slide.toolsArray.length > 0) {
  513. const hasUnprocessed = slide.toolsArray.length
  514. if (hasUnprocessed) {
  515. isHave = 2
  516. break
  517. }
  518. }
  519. }
  520. if (isHave == 2) {
  521. messages.value.at(-1).aiContent = lang.ssBatchInteractiveWebDesc3
  522. messages.value.at(-1).loading = false
  523. chatLoading.value = false
  524. messages.value.at(-1).chatloading = false
  525. return
  526. }
  527. messages.value.at(-1).aiContent = lang.ssBatchInteractiveWebDesc
  528. // messages.value.at(-1).loading = false
  529. // chatLoading.value = false
  530. // messages.value.at(-1).chatloading = false
  531. // return
  532. }
  533. }
  534. else {
  535. messages.value.at(-1).jsonData = {
  536. gType: gType.value,
  537. isGenerate: false
  538. }
  539. }
  540. const getTypeLabel = (type?: number) => {
  541. const typeMap: Record<number, string> = {
  542. 45: lang.ssChoiceQ,
  543. 15: lang.ssQATest,
  544. 72: lang.ssAiApp,
  545. 73: lang.ssHPage,
  546. 81: lang.ssHPage,
  547. 74: lang.ssVideo,
  548. 75: lang.lang == 'cn' ? lang.ssBiliVideo : lang.ssYouTube,
  549. 76: lang.ssCreative,
  550. 77: lang.ssEnglishSpeakingTool,
  551. 78: lang.ssVote,
  552. 79: lang.ssPhoto,
  553. }
  554. return typeMap[type || 0] || lang.ssUnknown
  555. }
  556. // 提取所有页面中 type 为 'text' 的元素的纯文本内容
  557. const allTextContents = slidesStore.slides
  558. .map((slide: any, index: number) => {
  559. const elements = slide.elements.filter((element: any) => {
  560. if (element.type === 'text' || (element.type === 'shape' && element.text && element.text.content)) {
  561. return true
  562. }
  563. // 如果 element.type 包含 frame 且 tooltype 是对应的工具,输出 lang.ssInteract(对应工具)
  564. if (element.type === 'frame' && element.toolType) {
  565. const toolLabel = getTypeLabel(element.toolType)
  566. if (toolLabel !== lang.ssUnknown) {
  567. return true
  568. }
  569. }
  570. return false
  571. })
  572. const pageContents = elements.map((textElement: any) => {
  573. let content = ''
  574. if (textElement.type === 'shape') {
  575. // 创建一个临时元素来解析 HTML 并提取纯文本
  576. const tempElement = document.createElement('div')
  577. tempElement.innerHTML = textElement.text.content
  578. content = tempElement.textContent || tempElement.innerText || ''
  579. }
  580. else if (textElement.type === 'frame' && textElement.toolType) {
  581. // 如果是 frame 类型且有 toolType,输出交互工具标签
  582. content = lang.ssInteract + `(${getTypeLabel(textElement.toolType)})`
  583. }
  584. else {
  585. // 创建一个临时元素来解析 HTML 并提取纯文本
  586. const tempElement = document.createElement('div')
  587. tempElement.innerHTML = textElement.content
  588. content = tempElement.textContent || tempElement.innerText || ''
  589. }
  590. return content
  591. }).filter((content: string) => content.trim() !== '')
  592. const pageContent = pageContents.length > 0 ? pageContents.join(' ') : '无文本内容'
  593. return `第${index + 1}页的内容:${pageContent}`
  594. }) || []
  595. // 提取当前页面中 type 为 'text' 的元素的纯文本内容
  596. const textContents = slidesStore.currentSlide?.elements
  597. .filter((element: any) => element.type === 'text' || (element.type === 'shape' && element.text && element.text.content))
  598. .map((textElement: any) => {
  599. if (textElement.type === 'shape') {
  600. // 创建一个临时元素来解析 HTML 并提取纯文本
  601. const tempElement = document.createElement('div')
  602. tempElement.innerHTML = textElement.text.content
  603. return tempElement.textContent || tempElement.innerText || ''
  604. }
  605. // 创建一个临时元素来解析 HTML 并提取纯文本
  606. const tempElement = document.createElement('div')
  607. tempElement.innerHTML = textElement.content
  608. return tempElement.textContent || tempElement.innerText || ''
  609. })
  610. .filter(content => content.trim() !== '') || []
  611. console.log('allTextContents', allTextContents)
  612. console.log('textContents', textContents)
  613. let prompt = ''
  614. let agentid = agentid2.value
  615. if (gType.value === 'trigger_tool_recommend') {
  616. agentid = agentid3.value
  617. prompt = `
  618. #课程标题(course_title): ${props.courseTitle || ''}
  619. #当前页面内容(all_pages_content): ${allTextContents.length > 0 ? allTextContents.join('\n') : '无文本内容'}
  620. #query: ${action}
  621. `
  622. }
  623. else if (gType.value === 'trigger_batch_tool') {
  624. agentid = agentid4.value
  625. prompt = `
  626. #课程标题(course_title): ${props.courseTitle || ''}
  627. #当前页面内容(all_pages_content): ${allTextContents.length > 0 ? allTextContents.join('\n') : '无文本内容'}
  628. #query: ${action}
  629. `
  630. }
  631. else {
  632. prompt = `
  633. #课程标题(course_title): ${props.courseTitle || ''}
  634. #当前页面内容(current_page_content): ${textContents.length > 0 ? textContents.join('\n') : '无文本内容'}
  635. #query: ${action}
  636. `
  637. }
  638. if (gType.value === 'trigger_batch_tool') {
  639. const result = chat_no_stream(prompt, agentid, props.userid || '', lang.lang)
  640. streamController.value = result
  641. console.log(result)
  642. const content = await result.promise
  643. messages.value.at(-1).jsonData.aiContent = content
  644. console.log('event.data', content)
  645. generate(messages.value.at(-1))
  646. // chat_stream(prompt, agentid, props.userid || '', lang.lang, async (event) => {
  647. // if (event.type === 'message') {
  648. // messages.value.at(-1).jsonData.aiContent = md.render(event.data)
  649. // messages.value.at(-1).loading = false
  650. // }
  651. // else if (event.type === 'messageEnd') {
  652. // messages.value.at(-1).jsonData.aiContent = md.render(event.data)
  653. // console.log('event.data', event.data)
  654. // generate(messages.value.at(-1))
  655. // }
  656. // }, session_name.value, messages.value.at(-1).sourceFiles?.map(file => file.id).filter(Boolean)).then(controller => {
  657. // streamController.value = controller
  658. // }).catch(err => {
  659. // chatLoading.value = false
  660. // console.log('err', err)
  661. // stopMessage()
  662. // })
  663. return
  664. }
  665. chat_stream(prompt, agentid, props.userid || '', lang.lang, (event) => {
  666. if (event.type === 'message') {
  667. messages.value.at(-1).aiContent = md.render(event.data)
  668. messages.value.at(-1).loading = false
  669. prevChatResult()
  670. }
  671. else if (event.type === 'messageEnd') {
  672. messages.value.at(-1).aiContent = md.render(event.data)
  673. messages.value.at(-1).chatloading = false
  674. chatLoading.value = false
  675. prevChatResult()
  676. }
  677. }, session_name.value, messages.value.at(-1).sourceFiles?.map(file => file.id).filter(Boolean)).then(controller => {
  678. streamController.value = controller
  679. }).catch(err => {
  680. chatLoading.value = false
  681. console.log('err', err)
  682. stopMessage()
  683. })
  684. }
  685. import useCreateElement from '@/hooks/useCreateElement'
  686. import useSlideHandler from '@/hooks/useSlideHandler'
  687. const { createSlide } = useSlideHandler()
  688. const { createFrameElement } = useCreateElement()
  689. const setUrl = () => {
  690. let url = 'https://beta.pbl.cocorobo.cn'
  691. if (lang.lang === 'cn') {
  692. url = 'https://pbl.cocorobo.cn/'
  693. }
  694. else if (lang.lang === 'hk') {
  695. url = 'https://pbl.cocorobo.hk/'
  696. }
  697. else if (lang.lang === 'en') {
  698. url = 'https://pbl.cocorobo.com/'
  699. }
  700. return url
  701. }
  702. const generate = (message: ChatMessage) => {
  703. if (message.gLoading || message.jsonData?.isGenerate) {
  704. return
  705. }
  706. message.gLoading = true
  707. if (message.jsonData?.gType === 'generate_choice_question') {
  708. console.log(message.jsonData?.gType)
  709. const prompt = [
  710. {
  711. role: 'user',
  712. content: `这是用户输入的内容:“${message.aiContent}”,根据用户输入的内容,生成选择题的json。输出一个json格式的回复,格式如下:{"testCount":1,"testTitle":"","testJson":[{"id":"7de1fdb4-bec3-4324-8986-4623f838e3d7","type":"2","teststitle":"1+1?","checkList":["1","2","3"],"timuList":[],"answer":[1],"userAnswer":[],"explanation":"解析"}]}。`, // 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
  713. },
  714. ]
  715. chat_no_stream2(prompt, { type: 'json_object' }).then(async (res: any) => {
  716. console.log('选择题', JSON.parse(res))
  717. gType.value = 'chat'
  718. setPageId(45, res).then(res => {
  719. const baseUrl = setUrl()
  720. const url = `${baseUrl}/pbl-teacher-table/dist/workPage.html#/setWorkPage?id=${res}&type=${45}`
  721. createSlide()
  722. createFrameElement(url, 45)
  723. message.gLoading = false
  724. message.jsonData.isGenerate = true
  725. })
  726. })
  727. }
  728. else if (message.jsonData?.gType === 'generate_qa') {
  729. console.log(message.jsonData?.gType)
  730. const prompt = [
  731. {
  732. role: 'user',
  733. content: `这是用户输入的内容:“${message.aiContent}”,根据用户输入的内容,生成问答题的json。输出一个json格式的回复,格式如下:{"answerQ":"问题","answer":"","fileList":[],"imageList":[],"evaluationCriteria":"评价标准"}。`, // 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
  734. },
  735. ]
  736. chat_no_stream2(prompt, { type: 'json_object' }).then((res: any) => {
  737. console.log('问答题', JSON.parse(res))
  738. gType.value = 'chat'
  739. setPageId(15, res).then(res => {
  740. const baseUrl = setUrl()
  741. const url = `${baseUrl}/pbl-teacher-table/dist/workPage.html#/setWorkPage?id=${res}&type=${15}`
  742. createSlide()
  743. createFrameElement(url, 15)
  744. message.gLoading = false
  745. message.jsonData.isGenerate = true
  746. })
  747. })
  748. }
  749. else if (message.jsonData?.gType === 'generate_poll') {
  750. console.log(message.jsonData?.gType)
  751. const prompt = [
  752. {
  753. role: 'user',
  754. content: `这是用户输入的内容:“${message.aiContent}”,根据用户输入的内容,生成投票的json。输出一个json格式的回复,格式如下:{"testCount":1,"testTitle":"","testJson":[{"id":"7de1fdb4-bec3-4324-8986-4623f838e3d7","type":"2","teststitle":"1+1?","checkList":["1","2","3"],"timuList":[],"answer":[],"userAnswer":[]]}。`, // 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
  755. },
  756. ]
  757. chat_no_stream2(prompt, { type: 'json_object' }).then(async (res: any) => {
  758. console.log('投票', JSON.parse(res))
  759. gType.value = 'chat'
  760. setPageId(78, res).then(res => {
  761. const baseUrl = setUrl()
  762. const url = `${baseUrl}/pbl-teacher-table/dist/workPage.html#/setWorkPage?id=${res}&type=${78}`
  763. createSlide()
  764. createFrameElement(url, 78)
  765. message.gLoading = false
  766. message.jsonData.isGenerate = true
  767. })
  768. })
  769. }
  770. else if (message.jsonData?.gType === 'generate_photo') {
  771. console.log(message.jsonData?.gType)
  772. const prompt = [
  773. {
  774. role: 'user',
  775. content: `这是用户输入的内容:“${message.aiContent}”,根据用户输入的内容,生成拍照的json。输出一个json格式的回复,格式如下:{"answerQ":"问题","answer":"","fileList":[]}。`, // ,"imageList":[],"evaluationCriteria":"评价标准" 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
  776. },
  777. ]
  778. chat_no_stream2(prompt, { type: 'json_object' }).then((res: any) => {
  779. console.log('拍照', JSON.parse(res))
  780. gType.value = 'chat'
  781. setPageId(79, res).then(res => {
  782. const baseUrl = setUrl()
  783. const url = `${baseUrl}/pbl-teacher-table/dist/workPage.html#/setWorkPage?id=${res}&type=${79}`
  784. createSlide()
  785. createFrameElement(url, 79)
  786. message.gLoading = false
  787. message.jsonData.isGenerate = true
  788. })
  789. })
  790. }
  791. else if (message.jsonData?.gType === 'trigger_batch_tool') {
  792. console.log(message.jsonData?.gType)
  793. const prompt = [
  794. {
  795. role: 'user',
  796. content: `这是用户输入的内容:“${message.jsonData.aiContent}”,根据用户输入的内容,取出里面candidates的值。输出一个json格式的回复`, // ,"imageList":[],"evaluationCriteria":"评价标准" 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
  797. },
  798. ]
  799. chat_no_stream2(prompt, { type: 'json_object' }).then((res: any) => {
  800. console.log('批量生成工具', JSON.parse(res))
  801. gType.value = 'chat'
  802. messages.value.at(-1).chatloading = false
  803. messages.value.push({
  804. role: 'ai',
  805. aiContent: lang.ssBatchInteractiveWebDesc2,
  806. jsonData: {
  807. gType: 'trigger_batch_tool'
  808. }
  809. })
  810. chatLoading.value = false
  811. const array = JSON.parse(res).candidates
  812. for (let i = 0; i < array.length; i++) {
  813. const item = array[i]
  814. const pageIndex = item.page_index - 1
  815. if (pageIndex >= 0 && pageIndex < slidesStore.slides.length) {
  816. const slide = slidesStore.slides[pageIndex]
  817. slidesStore.updateSlide({ toolsArray: item.tools }, slide.id)
  818. }
  819. }
  820. const firstPageWithTools = slidesStore.slides.findIndex((slide: any) =>
  821. slide.toolsArray && slide.toolsArray.length > 0
  822. )
  823. if (firstPageWithTools !== -1) {
  824. slidesStore.updateSlideIndex(firstPageWithTools)
  825. mainStore.setChildPageState(true, slidesStore.slides[firstPageWithTools].toolsArray || [], firstPageWithTools || 0)
  826. }
  827. })
  828. }
  829. }
  830. const setPageId = async (tool: any, json: any) => {
  831. const res = await getWorkPageId({
  832. userid: props.userid || '',
  833. type: tool,
  834. json: json
  835. })
  836. return res[0][0].id
  837. }
  838. // 上传文件
  839. const uploadFile2 = async (file: File, signal?: AbortSignal): Promise<any> => {
  840. try {
  841. const uuid = uuidv4()
  842. const formData = new FormData()
  843. const timestamp = Date.now()
  844. const finalExtension = file.name.split('.').pop()?.toLowerCase() || ''
  845. const baseName = file.name.slice(0, -(finalExtension.length + 1))
  846. formData.append(
  847. 'file',
  848. new File([file], `${baseName}${timestamp}.${finalExtension}`)
  849. )
  850. formData.append('collection_ids', JSON.stringify([]))
  851. formData.append('id', uuid)
  852. formData.append('metadata', JSON.stringify({ title: file.name }))
  853. formData.append('ingestion_mode', 'fast')
  854. formData.append('run_with_orchestration', 'true')
  855. // 同步知识库
  856. const res = await axios.post(
  857. 'https://r2rserver.cocorobo.cn/v3/documents',
  858. formData,
  859. {
  860. headers: {
  861. 'Content-Type': 'multipart/form-data',
  862. },
  863. signal: signal
  864. }
  865. )
  866. console.log(res)
  867. return res
  868. }
  869. catch (error) {
  870. console.log('err', error)
  871. if (error.name === 'AbortError') {
  872. throw error
  873. }
  874. return ''
  875. }
  876. }
  877. const agentid1 = ref('cbb29b41-2a4a-4453-bf8d-357929ced4bd')// 判断意图
  878. const agentid2 = ref('f86aa63c-b7b7-4d03-9b37-b59f116d36f3')// 生成内容
  879. const agentid3 = ref('caaa43ab-41a5-466a-94bc-74e0c9265068')// 互动工具推荐
  880. const agentid4 = ref('b41bc650-9861-468c-a624-b52269dfff22')// 批量生成工具
  881. const isQuickActions = ref<string[]>([])
  882. const toggleQuickActions = (section: string) => {
  883. if (isQuickActions.value.includes(section)) {
  884. isQuickActions.value = isQuickActions.value.filter((item: string) => item !== section)
  885. }
  886. else {
  887. isQuickActions.value.push(section)
  888. }
  889. }
  890. const cocoQuickTab = ref('page')
  891. const setCocoQuickTab = (tab: string) => {
  892. cocoQuickTab.value = tab
  893. }
  894. // AI Web 相关状态
  895. const create_app_loading = ref(false)
  896. const webId = ref('')
  897. const showAiWebModal = ref(false)
  898. const isEdit = ref(false)
  899. import { storeToRefs } from 'pinia'
  900. import _ from 'lodash'
  901. const { currentSlide } = storeToRefs(slidesStore)
  902. const handle_add_aiWeb = _.throttle(async () => {
  903. create_app_loading.value = true
  904. try {
  905. const elements = currentSlide.value?.elements || []
  906. console.log(elements)
  907. const existingWebElement = elements.find((el: any) => el.toolType === 73 && el.webId && el.type === 'frame')
  908. if (existingWebElement && existingWebElement.webId) {
  909. webId.value = existingWebElement.webId
  910. create_app_loading.value = false
  911. showAiWebModal.value = true
  912. isEdit.value = true
  913. return
  914. }
  915. const res = await axios.post('https://appapi.cocorobo.cn/api/agents/ai_edit', {
  916. userid: props.userid || '',
  917. username: props.userJson.name || '',
  918. muti_name: lang.ssAddWebH5,
  919. description: lang.ssAddWebH5,
  920. headUrl: 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/default%2F%E9%BB%98%E8%AE%A4%E5%A4%B4%E5%83%8F51741770599274.svg',
  921. organizeid: props.userJson.organizeid || '',
  922. content: ''
  923. })
  924. console.log(res)
  925. webId.value = res.id || ''
  926. create_app_loading.value = false
  927. showAiWebModal.value = true
  928. }
  929. catch (error) {
  930. console.log(error)
  931. create_app_loading.value = false
  932. }
  933. }, 3000)
  934. const isLoading = ref(false)
  935. import useImport from '@/hooks/useImport'
  936. const { uploadFileToS3 } = useImport()
  937. const addAiWeb = async (code: string) => {
  938. if (!code) return
  939. const file = new File([code], 'index.html', { type: 'text/html' })
  940. isLoading.value = true
  941. const url = await uploadFileToS3(file)
  942. if (isEdit.value) {
  943. const elements = currentSlide.value?.elements || []
  944. const frameElement = elements.find((el: any) => el.type === 'frame' && (el.toolType === 73))
  945. if (frameElement) {
  946. slidesStore.updateElement({
  947. id: frameElement.id,
  948. props: { url: url }
  949. })
  950. }
  951. }
  952. else {
  953. createSlide()
  954. createFrameElement(url, 73, webId.value)
  955. }
  956. isLoading.value = false
  957. showAiWebModal.value = false
  958. webId.value = ''
  959. isEdit.value = false
  960. }
  961. onMounted(() => {
  962. session_name.value = uuidv4()
  963. getAgentModel(agentid1.value)
  964. getAgentModel(agentid2.value)
  965. getAgentModel(agentid3.value)
  966. getAgentModel(agentid4.value)
  967. })
  968. </script>
  969. <style lang="scss" scoped>
  970. .ai-chat-container {
  971. width: 100%;
  972. height: 100%;
  973. display: flex;
  974. flex-direction: column;
  975. padding: 16px;
  976. gap: 16px;
  977. }
  978. .input-section {
  979. display: flex;
  980. flex-direction: column;
  981. gap: 12px;
  982. position: relative;
  983. }
  984. .input-wrapper {
  985. position: relative;
  986. display: flex;
  987. flex-direction: column;
  988. background: #fafbfc;
  989. border: 1.5px solid #e5e7eb;
  990. border-radius: 8px;
  991. padding: 8px 12px;
  992. min-height: 120px;
  993. }
  994. .ai-input {
  995. flex: 1;
  996. border: none;
  997. background: transparent;
  998. font-size: 14px;
  999. color: #374151;
  1000. outline: none;
  1001. resize: none;
  1002. min-height: 80px;
  1003. &::placeholder {
  1004. color: #9CA3AF;
  1005. }
  1006. }
  1007. .input-actions {
  1008. display: flex;
  1009. // justify-content: space-between;
  1010. align-items: center;
  1011. margin-top: 8px;
  1012. }
  1013. .attach-btn {
  1014. width: 32px;
  1015. height: 32px;
  1016. background: none;
  1017. border: none;
  1018. cursor: pointer;
  1019. padding: 4px;
  1020. display: flex;
  1021. align-items: center;
  1022. justify-content: center;
  1023. transition: all 0.3s ease;
  1024. color: #6b7280;
  1025. svg {
  1026. width: 20px;
  1027. height: 20px;
  1028. }
  1029. &:hover {
  1030. background: #FFF4E5;
  1031. color: #F78B22;
  1032. border-radius: 4px;
  1033. }
  1034. input[type="file"] {
  1035. display: none;
  1036. }
  1037. }
  1038. .file-box {
  1039. margin-bottom: 8px;
  1040. min-height: 24px;
  1041. max-height: 70px;
  1042. overflow-y: auto;
  1043. .file-item {
  1044. display: flex;
  1045. align-items: center;
  1046. background: #f5f5f5;
  1047. padding: 4px 8px;
  1048. border-radius: 4px;
  1049. margin-bottom: 4px;
  1050. .file-name {
  1051. flex: 1;
  1052. font-size: 12px;
  1053. color: #374151;
  1054. overflow: hidden;
  1055. text-overflow: ellipsis;
  1056. white-space: nowrap;
  1057. }
  1058. .remove-file-btn {
  1059. background: none;
  1060. border: none;
  1061. cursor: pointer;
  1062. color: #9CA3AF;
  1063. font-size: 12px;
  1064. padding: 2px;
  1065. margin-left: 8px;
  1066. display: flex;
  1067. align-items: center;
  1068. justify-content: center;
  1069. svg {
  1070. width: 14px;
  1071. height: 14px;
  1072. }
  1073. &:hover {
  1074. color: #EF4444;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. .send-btn {
  1080. margin-left: auto;
  1081. width: 32px;
  1082. height: 32px;
  1083. border: none;
  1084. background: #FF9300;
  1085. color: #fff;
  1086. border-radius: 50%;
  1087. cursor: pointer;
  1088. display: flex;
  1089. align-items: center;
  1090. justify-content: center;
  1091. transition: all 0.3s ease;
  1092. svg {
  1093. width: 20px;
  1094. height: 20px;
  1095. }
  1096. &:hover {
  1097. background: #E68A00;
  1098. }
  1099. &.stop {
  1100. background: unset;
  1101. width: auto;
  1102. svg {
  1103. width: 32px;
  1104. height: 32px;
  1105. }
  1106. }
  1107. }
  1108. .quick-actions {
  1109. // display: flex;
  1110. // flex-direction: column;
  1111. // gap: 8px;
  1112. .quick-action-btn {
  1113. padding: 5px 10px;
  1114. border: 1px solid #f7c58f;
  1115. background: #FFF9F2;
  1116. color: #6b4a1f;
  1117. border-radius: 16px;
  1118. font-size: 12px;
  1119. cursor: pointer;
  1120. text-align: left;
  1121. display: block;
  1122. &:hover {
  1123. border-color: #F78B22;
  1124. background: #FFF4E5;
  1125. color: #111827;
  1126. }
  1127. +.quick-action-btn {
  1128. margin-top: 8px;
  1129. }
  1130. }
  1131. }
  1132. .chat-section {
  1133. // flex: 1;
  1134. height: calc(100% - 155px);
  1135. overflow-y: auto;
  1136. display: flex;
  1137. flex-direction: column;
  1138. // gap: 16px;
  1139. padding-right: 8px;
  1140. &::-webkit-scrollbar {
  1141. width: 6px;
  1142. }
  1143. &::-webkit-scrollbar-track {
  1144. background: #F3F4F6;
  1145. border-radius: 3px;
  1146. }
  1147. &::-webkit-scrollbar-thumb {
  1148. background: #D1D5DB;
  1149. border-radius: 3px;
  1150. &:hover {
  1151. background: #9CA3AF;
  1152. }
  1153. }
  1154. }
  1155. .chat-message {
  1156. max-width: 100%;
  1157. margin-bottom: 10px;
  1158. display: flex;
  1159. flex-direction: column;
  1160. .message-content {
  1161. display: flex;
  1162. flex-direction: column;
  1163. border-radius: 8px;
  1164. padding: 8px 10px;
  1165. font-size: 14px;
  1166. line-height: 1.5;
  1167. color: #374151;
  1168. width: fit-content;
  1169. position: relative;
  1170. +.message-content {
  1171. margin-top: 10px;
  1172. }
  1173. &.loading-state {
  1174. opacity: 0.7;
  1175. cursor: not-allowed;
  1176. pointer-events: none;
  1177. // .submenu-icon {
  1178. // animation: pulse 1s infinite;
  1179. // }
  1180. .spin {
  1181. animation: spin 1s linear infinite;
  1182. }
  1183. .submenu-icon {
  1184. position: absolute;
  1185. width: 100%;
  1186. height: 100%;
  1187. background: #00000026;
  1188. top: 0;
  1189. left: 0;
  1190. display: flex;
  1191. align-items: center;
  1192. justify-content: center;
  1193. svg {
  1194. height: 30px;
  1195. color: #fff;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. .message-content {
  1202. word-break: break-word;
  1203. &.ai-message {
  1204. align-self: flex-start;
  1205. background: #fafbfc;
  1206. border: 1.5px solid #e5e7eb;
  1207. border-bottom-left-radius: 2px;
  1208. &>svg {
  1209. width: 17px;
  1210. height: 17px;
  1211. }
  1212. }
  1213. }
  1214. .message-content {
  1215. &.user-message {
  1216. align-self: flex-end;
  1217. background: #FFF4E5;
  1218. border: 1.5px solid #F78B22;
  1219. border-bottom-right-radius: 2px;
  1220. }
  1221. }
  1222. .initial-state {
  1223. display: flex;
  1224. flex-direction: column;
  1225. justify-content: flex-start;
  1226. align-items: flex-start;
  1227. // padding: 24px;
  1228. gap: 16px;
  1229. }
  1230. .confirm-btn {
  1231. margin-top: 10px;
  1232. padding: 6px 15px;
  1233. background: #FF9300;
  1234. color: white;
  1235. border: none;
  1236. border-radius: 8px;
  1237. font-size: 14px;
  1238. cursor: pointer;
  1239. margin-left: auto;
  1240. transition: all 0.3s ease;
  1241. &:hover {
  1242. background: #E68A00;
  1243. }
  1244. &.disabled {
  1245. background: #9CA3AF;
  1246. cursor: not-allowed;
  1247. }
  1248. }
  1249. ul {
  1250. margin: 8px 0;
  1251. padding-left: 20px;
  1252. li {
  1253. margin: 4px 0;
  1254. }
  1255. }
  1256. .quick-actions-popup {
  1257. position: absolute;
  1258. bottom: 100%;
  1259. left: 0;
  1260. right: 0;
  1261. background: white;
  1262. border: 1px solid #E5E7EB;
  1263. border-radius: 8px;
  1264. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  1265. padding: 8px;
  1266. z-index: 100;
  1267. margin-bottom: 8px;
  1268. .quick-action-btn {
  1269. width: 100%;
  1270. text-align: left;
  1271. padding: 10px 12px;
  1272. background: white;
  1273. border: none;
  1274. border-radius: 6px;
  1275. font-size: 14px;
  1276. color: #374151;
  1277. cursor: pointer;
  1278. transition: all 0.2s ease;
  1279. &:hover {
  1280. background: #fff4e5;
  1281. }
  1282. }
  1283. }
  1284. .message-quick-box {
  1285. display: flex;
  1286. flex-direction: column;
  1287. flex-shrink: 0;
  1288. gap: 10px;
  1289. .message-quick-box-item {
  1290. box-shadow: rgba(17, 24, 39, 0.04) 0px 10px 30px;
  1291. border-width: 1px;
  1292. border-style: solid;
  1293. border-color: rgb(239, 229, 216);
  1294. border-image: initial;
  1295. border-radius: 18px;
  1296. background: rgba(255, 255, 255, 0.96);
  1297. overflow: hidden;
  1298. .coco-collapse-trigger {
  1299. width: 100%;
  1300. display: flex;
  1301. align-items: center;
  1302. cursor: pointer;
  1303. text-align: left;
  1304. gap: 12px;
  1305. border-width: initial;
  1306. border-style: none;
  1307. border-color: initial;
  1308. border-image: initial;
  1309. background: transparent;
  1310. padding: 12px 14px;
  1311. &:hover {
  1312. background: rgb(255, 251, 245);
  1313. }
  1314. }
  1315. .coco-collapse-icon.soft-orange {
  1316. color: rgb(154, 91, 17);
  1317. background: rgb(255, 240, 219);
  1318. }
  1319. .coco-collapse-icon {
  1320. width: 34px;
  1321. height: 34px;
  1322. display: flex;
  1323. align-items: center;
  1324. justify-content: center;
  1325. flex-shrink: 0;
  1326. border-radius: 12px;
  1327. }
  1328. .coco-collapse-copy {
  1329. min-width: 0px;
  1330. display: flex;
  1331. flex-direction: column;
  1332. flex: 1 1 0%;
  1333. gap: 2px;
  1334. .coco-collapse-title {
  1335. font-size: 14px;
  1336. font-weight: 700;
  1337. color: rgb(17, 24, 39);
  1338. }
  1339. .coco-collapse-subtitle {
  1340. font-size: 12px;
  1341. color: rgb(139, 115, 86);
  1342. line-height: 1.5;
  1343. }
  1344. }
  1345. .coco-collapse-chevron {
  1346. color: rgb(156, 163, 175);
  1347. flex-shrink: 0;
  1348. svg {
  1349. transition: transform 0.2s;
  1350. }
  1351. }
  1352. &.active {
  1353. .coco-collapse-chevron svg {
  1354. transform: rotate(180deg);
  1355. }
  1356. }
  1357. .coco-collapse-body {
  1358. padding: 0px 14px 14px;
  1359. .coco-quick-tabs {
  1360. display: grid;
  1361. grid-template-columns: repeat(2, minmax(0px, 1fr));
  1362. margin-bottom: 12px;
  1363. gap: 8px;
  1364. .coco-quick-tab {
  1365. height: 34px;
  1366. color: rgb(124, 92, 56);
  1367. font-size: 12px;
  1368. font-weight: 600;
  1369. cursor: pointer;
  1370. border-radius: 12px;
  1371. border-width: 1px;
  1372. border-style: solid;
  1373. border-color: rgb(234, 223, 206);
  1374. border-image: initial;
  1375. background: rgb(250, 247, 242);
  1376. transition: 0.2s;
  1377. &.active {
  1378. color: rgb(154, 91, 17);
  1379. box-shadow: rgba(247, 139, 34, 0.12) 0px 8px 18px;
  1380. border-color: rgba(247, 139, 34, 0.48);
  1381. background: rgb(255, 244, 229);
  1382. }
  1383. }
  1384. }
  1385. .coco-quick-list {
  1386. display: flex;
  1387. flex-direction: column;
  1388. gap: 8px;
  1389. .coco-quick-action {
  1390. width: 100%;
  1391. display: flex;
  1392. align-items: flex-start;
  1393. cursor: pointer;
  1394. text-align: left;
  1395. gap: 12px;
  1396. border-width: 1px;
  1397. border-style: solid;
  1398. border-color: rgb(239, 229, 216);
  1399. border-image: initial;
  1400. background: rgb(255, 253, 250);
  1401. border-radius: 14px;
  1402. padding: 12px;
  1403. transition: 0.2s;
  1404. .coco-quick-action-copy {
  1405. min-width: 0px;
  1406. display: flex;
  1407. flex-direction: column;
  1408. flex: 1 1 0%;
  1409. gap: 4px;
  1410. .coco-quick-action-title {
  1411. font-size: 13px;
  1412. font-weight: 700;
  1413. color: rgb(17, 24, 39);
  1414. line-height: 1.4;
  1415. }
  1416. .coco-quick-action-desc {
  1417. font-size: 12px;
  1418. line-height: 1.6;
  1419. color: rgb(139, 115, 86);
  1420. }
  1421. }
  1422. .coco-quick-action-arrow {
  1423. color: rgb(212, 163, 115);
  1424. flex-shrink: 0;
  1425. padding-top: 2px;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. .coco-interactive-web-card {
  1433. width: 100%;
  1434. margin-top: 10px;
  1435. display: flex;
  1436. flex-direction: column;
  1437. text-align: left;
  1438. cursor: pointer;
  1439. border-width: 1px;
  1440. border-style: solid;
  1441. border-color: rgb(247, 197, 143);
  1442. border-image: initial;
  1443. border-radius: 14px;
  1444. background: linear-gradient(rgb(255, 250, 243) 0%, rgb(255, 255, 255) 100%);
  1445. padding: 12px 14px;
  1446. gap: 8px;
  1447. transition: 0.2s;
  1448. position: relative;
  1449. overflow: hidden;
  1450. &:hover {
  1451. box-shadow: rgba(247, 139, 34, 0.1) 0px 10px 24px;
  1452. transform: translateY(-1px);
  1453. border-color: rgb(247, 139, 34);
  1454. }
  1455. &.loading-state {
  1456. opacity: 0.7;
  1457. cursor: not-allowed;
  1458. pointer-events: none;
  1459. // .submenu-icon {
  1460. // animation: pulse 1s infinite;
  1461. // }
  1462. .spin {
  1463. animation: spin 1s linear infinite;
  1464. }
  1465. .submenu-icon {
  1466. position: absolute;
  1467. width: 100%;
  1468. height: 100%;
  1469. background: #00000026;
  1470. top: 0;
  1471. left: 0;
  1472. display: flex;
  1473. align-items: center;
  1474. justify-content: center;
  1475. svg {
  1476. height: 30px;
  1477. color: #fff;
  1478. }
  1479. }
  1480. }
  1481. .coco-interactive-web-card-head,
  1482. .coco-interactive-web-card-foot {
  1483. display: flex;
  1484. align-items: center;
  1485. justify-content: space-between;
  1486. gap: 10px;
  1487. .coco-interactive-web-card-title {
  1488. min-width: 0px;
  1489. font-size: 14px;
  1490. font-weight: 700;
  1491. color: rgb(17, 24, 39);
  1492. line-height: 1.4;
  1493. flex: 1 1 0%;
  1494. }
  1495. .coco-interactive-web-card-action {
  1496. margin-left: auto;
  1497. font-size: 12px;
  1498. font-weight: 700;
  1499. color: rgb(240, 120, 21);
  1500. }
  1501. }
  1502. .coco-interactive-web-card-desc {
  1503. font-size: 12px;
  1504. color: rgb(107, 114, 128);
  1505. line-height: 1.6;
  1506. }
  1507. }
  1508. </style>
  1509. <style>
  1510. .chat table {
  1511. text-align: center;
  1512. border-spacing: 0;
  1513. border-left: 1px solid #000;
  1514. border-bottom: 1px solid #000;
  1515. }
  1516. .chat table td,
  1517. .chat table th {
  1518. border-top: 1px solid #000;
  1519. border-right: 1px solid #000;
  1520. padding: 10px;
  1521. }
  1522. .message-files {
  1523. margin-top: 8px;
  1524. display: flex;
  1525. flex-direction: column;
  1526. gap: 4px;
  1527. }
  1528. .message-file-item {
  1529. display: flex;
  1530. align-items: center;
  1531. gap: 6px;
  1532. font-size: 12px;
  1533. color: #6b7280;
  1534. background: #f3f4f6;
  1535. padding: 4px 8px;
  1536. border-radius: 4px;
  1537. max-width: 200px;
  1538. overflow: hidden;
  1539. }
  1540. .message-file-item span {
  1541. flex: 1;
  1542. white-space: nowrap;
  1543. overflow: hidden;
  1544. text-overflow: ellipsis;
  1545. }
  1546. </style>