mirror of
https://github.com/chathub-dev/chathub.git
synced 2025-09-26 20:31:18 +08:00
32 lines
803 B
TypeScript
32 lines
803 B
TypeScript
import { ChatResponseMessage } from './types'
|
|
|
|
export function convertMessageToMarkdown(message: ChatResponseMessage): string {
|
|
if (message.messageType === 'InternalSearchQuery') {
|
|
return message.text
|
|
}
|
|
let adaptiveCardText = ''
|
|
for (const card of message.adaptiveCards) {
|
|
for (const block of card.body) {
|
|
if (block.type === 'TextBlock') {
|
|
adaptiveCardText += '\n' + block.text
|
|
}
|
|
}
|
|
}
|
|
return adaptiveCardText
|
|
}
|
|
|
|
const RecordSeparator = String.fromCharCode(30)
|
|
|
|
export const websocketUtils = {
|
|
packMessage(data: any) {
|
|
return `${JSON.stringify(data)}${RecordSeparator}`
|
|
},
|
|
unpackMessage(data: string | ArrayBuffer | Blob) {
|
|
return data
|
|
.toString()
|
|
.split(RecordSeparator)
|
|
.filter(Boolean)
|
|
.map((s) => JSON.parse(s))
|
|
},
|
|
}
|