@inworld/web-core
Version:
32 lines (31 loc) • 1.33 kB
JavaScript
import { ActorType as ProtoActorType, } from '../../../proto/ai/inworld/packets/packets.pb.js';
export class Actor {
constructor({ name, isPlayer, isCharacter, }) {
this.name = name;
this.isPlayer = isPlayer;
this.isCharacter = isCharacter;
}
static fromProto(proto) {
var _a;
const type = proto === null || proto === void 0 ? void 0 : proto.type;
return new Actor({
name: (_a = proto === null || proto === void 0 ? void 0 : proto.name) !== null && _a !== void 0 ? _a : '',
isPlayer: type === ProtoActorType.PLAYER,
isCharacter: type === ProtoActorType.AGENT,
});
}
}
export class Routing {
constructor({ source, targets }) {
this.source = source;
this.targets = targets;
}
static fromProto(proto) {
var _a, _b;
const targets = ((_a = proto === null || proto === void 0 ? void 0 : proto.target) === null || _a === void 0 ? void 0 : _a.type) ? [proto.target] : (_b = proto === null || proto === void 0 ? void 0 : proto.targets) !== null && _b !== void 0 ? _b : [];
return new Routing({
source: Actor.fromProto(proto === null || proto === void 0 ? void 0 : proto.source),
targets: targets.map((target) => Actor.fromProto(target)),
});
}
}