| 3 | import { ModelMessage } from 'ai'; |
| 4 | |
| 5 | class AiStreamingMessage implements CustomMessage<AiStreamingMessage> { |
| 6 | private readonly topic: Topic; |
| 7 | public readonly messageId: string; |
| 8 | public readonly content: string; |
| 9 | public readonly isStreaming: boolean; |
| 10 | |
| 11 | constructor(topic: Topic, messageId: string, content: string, isStreaming = true) { |
| 12 | this.topic = topic; |
| 13 | this.messageId = messageId; |
| 14 | this.content = content; |
| 15 | this.isStreaming = isStreaming; |
| 16 | } |
| 17 | |
| 18 | async toMsg(): Promise<ModelMessage[]> { |
| 19 | const content = this.content.replace(/\[\[switch:[\s\S]*?\]\]/g, ''); |
| 20 | return [{ |
| 21 | role: 'assistant', |
| 22 | content, |
| 23 | }]; |
| 24 | } |
| 25 | |
| 26 | msgType: MsgType = 'ai-streaming'; |
| 27 | |
| 28 | copy(): AiStreamingMessage { |
| 29 | return new AiStreamingMessage(this.topic, this.messageId, this.content, this.isStreaming); |
| 30 | } |
| 31 | |
| 32 | withUpdate(content: string, isStreaming = this.isStreaming): AiStreamingMessage { |
| 33 | return new AiStreamingMessage(this.topic, this.messageId, content, isStreaming); |
| 34 | } |
| 35 | |
| 36 | getTopic(): Topic { |
| 37 | return this.topic; |
| 38 | } |
| 39 | |
| 40 | getTaskIds(): number[] { |
| 41 | return []; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | export default AiStreamingMessage; |
nothing calls this directly
no outgoing calls
no test coverage detected