mirror of
https://github.com/sortedcord/omnia.git
synced 2026-07-22 03:52:48 +05:30
refactor: Use a generic serializer for attributableObject and use polymorphism for world
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { WorldState } from "@omnia/core";
|
||||
import { LLMValidator, ValidationResult } from "./llmValidator.js";
|
||||
import { LLMValidator, ValidationResult } from "./llm-validator.js";
|
||||
import { ILLMProvider } from "@omnia/llm";
|
||||
|
||||
export class Architect {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./llmValidator.js";
|
||||
export * from "./llm-validator.js";
|
||||
export * from "./architect.js";
|
||||
|
||||
@@ -29,7 +29,7 @@ export class LLMValidator {
|
||||
}
|
||||
|
||||
// 1. Serialize the objective world state for the LLM
|
||||
const serializedWorld = this.serializeWorldState(worldState);
|
||||
const serializedWorld = worldState.serialize();
|
||||
|
||||
// 2. Build the prompts
|
||||
const systemPrompt = `
|
||||
@@ -75,38 +75,4 @@ Decide if the proposed action is logically valid and physically possible.
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
private serializeWorldState(worldState: WorldState): string {
|
||||
const lines: string[] = [];
|
||||
|
||||
// Serialize world attributes
|
||||
if (worldState.attributes.size > 0) {
|
||||
lines.push("World Attributes:");
|
||||
for (const [name, attr] of worldState.attributes.entries()) {
|
||||
lines.push(
|
||||
` - ${name}: ${attr.getValue()} (Visibility: ${attr.getVisibility()})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize entities and their attributes
|
||||
lines.push("Entities:");
|
||||
for (const entity of worldState.entities.values()) {
|
||||
lines.push(` - Entity [ID: ${entity.id}]:`);
|
||||
if (entity.attributes.size > 0) {
|
||||
for (const [name, attr] of entity.attributes.entries()) {
|
||||
const aclList = Array.from(attr.getAllowedEntities());
|
||||
const aclStr =
|
||||
aclList.length > 0 ? ` (Visible to: ${aclList.join(", ")})` : "";
|
||||
lines.push(
|
||||
` * ${name}: ${attr.getValue()} (Visibility: ${attr.getVisibility()})${aclStr}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
lines.push(" * (No attributes)");
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
@@ -112,4 +112,14 @@ export abstract class AttributableObject implements IAttribute {
|
||||
attr.hasAccess(viewerId),
|
||||
);
|
||||
}
|
||||
|
||||
serialize(): string {
|
||||
const lines: string[] = [];
|
||||
for (const [name, attr] of this.attributes.entries()) {
|
||||
const aclList = Array.from(attr.getAllowedEntities());
|
||||
const aclStr = aclList.length > 0 ? ` (Visible to: ${aclList.join(", ")})` : "";
|
||||
lines.push(`* ${name}: ${attr.getValue()} (Visibility: ${attr.getVisibility()})${aclStr}`);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,33 @@ export class WorldState extends AttributableObject {
|
||||
getEntity(id: string): Entity | undefined {
|
||||
return this.entities.get(id);
|
||||
}
|
||||
|
||||
override serialize(): string {
|
||||
const lines: string[] = [];
|
||||
|
||||
// 1. Serialize self attributes (world attributes)
|
||||
const selfSerialized = super.serialize();
|
||||
if (selfSerialized) {
|
||||
lines.push("World Attributes:");
|
||||
lines.push(selfSerialized.split("\n").map(l => " " + l).join("\n"));
|
||||
}
|
||||
|
||||
// 2. Serialize entities
|
||||
lines.push("Entities:");
|
||||
if (this.entities.size > 0) {
|
||||
for (const entity of this.entities.values()) {
|
||||
lines.push(` - Entity [ID: ${entity.id}]:`);
|
||||
const entitySerialized = entity.serialize();
|
||||
if (entitySerialized) {
|
||||
lines.push(entitySerialized.split("\n").map(l => " " + l).join("\n"));
|
||||
} else {
|
||||
lines.push(" * (No attributes)");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lines.push(" (No entities)");
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user