mirror of
https://github.com/sortedcord/omnia.git
synced 2026-07-22 20:12:48 +05:30
feat(core): Added isAgent field for entities
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { WorldState, Entity, SQLiteRepository, AttributeVisibility } from "@omnia/core";
|
||||
import {
|
||||
WorldState,
|
||||
Entity,
|
||||
SQLiteRepository,
|
||||
AttributeVisibility,
|
||||
} from "@omnia/core";
|
||||
import { Location } from "@omnia/spatial";
|
||||
import { BufferRepository } from "@omnia/memory";
|
||||
import { ScenarioSchema, Scenario } from "./schema.js";
|
||||
@@ -17,24 +22,40 @@ export class ScenarioLoader {
|
||||
* @param targetWorldId The unique ID for the running instance to create (e.g. UUID).
|
||||
* Allows launching multiple active runs from one scenario.
|
||||
*/
|
||||
async initializeWorld(scenarioJson: unknown, targetWorldId: string): Promise<string> {
|
||||
async initializeWorld(
|
||||
scenarioJson: unknown,
|
||||
targetWorldId: string,
|
||||
): Promise<string> {
|
||||
// 1. Validate scenario template schema
|
||||
const scenario: Scenario = ScenarioSchema.parse(scenarioJson);
|
||||
|
||||
// 2. Instantiate running WorldState using the target instance ID
|
||||
const world = new WorldState(targetWorldId, new Date(scenario.startTime));
|
||||
|
||||
|
||||
// Seed world-level attributes as system-only (private, empty ACL)
|
||||
world.addAttribute("name", scenario.name, AttributeVisibility.PRIVATE, new Set());
|
||||
world.addAttribute("description", scenario.description, AttributeVisibility.PRIVATE, new Set());
|
||||
|
||||
world.addAttribute(
|
||||
"name",
|
||||
scenario.name,
|
||||
AttributeVisibility.PRIVATE,
|
||||
new Set(),
|
||||
);
|
||||
world.addAttribute(
|
||||
"description",
|
||||
scenario.description,
|
||||
AttributeVisibility.PRIVATE,
|
||||
new Set(),
|
||||
);
|
||||
|
||||
if (scenario.world?.attributes) {
|
||||
for (const attr of scenario.world.attributes) {
|
||||
const vis = attr.visibility === "PUBLIC" ? AttributeVisibility.PUBLIC : AttributeVisibility.PRIVATE;
|
||||
const vis =
|
||||
attr.visibility === "PUBLIC"
|
||||
? AttributeVisibility.PUBLIC
|
||||
: AttributeVisibility.PRIVATE;
|
||||
world.addAttribute(
|
||||
attr.name,
|
||||
attr.value,
|
||||
vis,
|
||||
attr.name,
|
||||
attr.value,
|
||||
vis,
|
||||
attr.allowedEntities ? new Set(attr.allowedEntities) : null,
|
||||
);
|
||||
}
|
||||
@@ -47,10 +68,13 @@ export class ScenarioLoader {
|
||||
if (scenario.locations) {
|
||||
for (const locData of scenario.locations) {
|
||||
const location = new Location(locData.id, locData.parentId ?? null);
|
||||
|
||||
|
||||
if (locData.attributes) {
|
||||
for (const attr of locData.attributes) {
|
||||
const vis = attr.visibility === "PUBLIC" ? AttributeVisibility.PUBLIC : AttributeVisibility.PRIVATE;
|
||||
const vis =
|
||||
attr.visibility === "PUBLIC"
|
||||
? AttributeVisibility.PUBLIC
|
||||
: AttributeVisibility.PRIVATE;
|
||||
location.addAttribute(
|
||||
attr.name,
|
||||
attr.value,
|
||||
@@ -80,12 +104,19 @@ export class ScenarioLoader {
|
||||
// 5. Instantiate and Persist Entities (with Aliases & Memory Buffers)
|
||||
if (scenario.entities) {
|
||||
for (const entData of scenario.entities) {
|
||||
const entity = new Entity(entData.id, entData.locationId ?? null);
|
||||
|
||||
const entity = new Entity(
|
||||
entData.id,
|
||||
entData.locationId ?? null,
|
||||
entData.isAgent,
|
||||
);
|
||||
|
||||
// Load attributes
|
||||
if (entData.attributes) {
|
||||
for (const attr of entData.attributes) {
|
||||
const vis = attr.visibility === "PUBLIC" ? AttributeVisibility.PUBLIC : AttributeVisibility.PRIVATE;
|
||||
const vis =
|
||||
attr.visibility === "PUBLIC"
|
||||
? AttributeVisibility.PUBLIC
|
||||
: AttributeVisibility.PRIVATE;
|
||||
entity.addAttribute(
|
||||
attr.name,
|
||||
attr.value,
|
||||
|
||||
@@ -38,10 +38,12 @@ export const ScenarioMemoryEntrySchema = z.object({
|
||||
targetIds: z.array(z.string()),
|
||||
modifiers: z.array(z.string()).optional(),
|
||||
}),
|
||||
outcome: z.object({
|
||||
isValid: z.boolean(),
|
||||
reason: z.string(),
|
||||
}).optional(),
|
||||
outcome: z
|
||||
.object({
|
||||
isValid: z.boolean(),
|
||||
reason: z.string(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const ScenarioEntitySchema = z.object({
|
||||
@@ -50,6 +52,7 @@ export const ScenarioEntitySchema = z.object({
|
||||
attributes: z.array(ScenarioAttributeSchema).optional(),
|
||||
aliases: z.record(z.string(), z.string()).optional(), // targetId -> subjective descriptor
|
||||
initialMemories: z.array(ScenarioMemoryEntrySchema).optional(),
|
||||
isAgent: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const ScenarioSchema = z.object({
|
||||
@@ -57,9 +60,11 @@ export const ScenarioSchema = z.object({
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
startTime: z.string(), // ISO string
|
||||
world: z.object({
|
||||
attributes: z.array(ScenarioAttributeSchema).optional(),
|
||||
}).optional(),
|
||||
world: z
|
||||
.object({
|
||||
attributes: z.array(ScenarioAttributeSchema).optional(),
|
||||
})
|
||||
.optional(),
|
||||
locations: z.array(ScenarioLocationSchema).optional(),
|
||||
entities: z.array(ScenarioEntitySchema).optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user