UNPKG

@inworld/web-core

Version:
34 lines (33 loc) 1.17 kB
import { TextEventSourceType, } from '../../../proto/ai/inworld/packets/packets.pb.js'; import { InworldTextPacketType } from '../../common/data_structures/index.js'; export class TextEvent { constructor({ text, final, type, }) { this.type = InworldTextPacketType.TYPED_IN; this.text = text; this.final = final; if (type) { this.type = type; } } static fromProto(proto) { return new TextEvent({ text: proto.text, final: proto.final, type: TextEvent.getType(proto.sourceType), }); } static getType(protoType) { switch (protoType) { case TextEventSourceType.SPEECH_TO_TEXT: return InworldTextPacketType.SPEECH_TO_TEXT; case TextEventSourceType.TYPED_IN: return InworldTextPacketType.TYPED_IN; case TextEventSourceType.GENERATED: return InworldTextPacketType.GENERATED; case TextEventSourceType.FILLER: return InworldTextPacketType.FILLER; default: return InworldTextPacketType.UNKNOWN; } } }