UNPKG

@inworld/web-core

Version:
48 lines (47 loc) 1.51 kB
import { ActorType, } from '../../../proto/ai/inworld/packets/packets.pb.js'; export var DialogParticipant; (function (DialogParticipant) { DialogParticipant["UNKNOWN"] = "UNKNOWN"; DialogParticipant["PLAYER"] = "PLAYER"; DialogParticipant["CHARACTER"] = "CHARACTER"; })(DialogParticipant || (DialogParticipant = {})); export class DialogActor { static toProto(talker) { switch (talker) { case DialogParticipant.PLAYER: return { type: ActorType.PLAYER }; case DialogParticipant.CHARACTER: return { type: ActorType.AGENT }; default: return { type: ActorType.UNKNOWN }; } } static fromProto(actor) { switch (actor.type) { case ActorType.PLAYER: return DialogParticipant.PLAYER; case ActorType.AGENT: return DialogParticipant.CHARACTER; default: return DialogParticipant.UNKNOWN; } } } export class PreviousDialog { constructor(phrases) { this.phrases = phrases; } toProto() { const history = this.phrases.map((item) => ({ actor: DialogActor.toProto(item.talker), text: item.phrase, })); return { history }; } static fromProto(dialog) { return new PreviousDialog(dialog.history.map((item) => ({ talker: DialogActor.fromProto(item.actor), phrase: item.text, }))); } }