mirror of
https://github.com/sortedcord/omnia.git
synced 2026-07-22 03:52:48 +05:30
feat: Added Alias Resolver DeltaGenerator
This commit is contained in:
@@ -63,3 +63,58 @@ Target IDs: ${intent.targetIds.join(", ") || "(None)"}
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const AliasDeltaSchema = z.object({
|
||||
alias: z.string(),
|
||||
});
|
||||
|
||||
export type AliasDelta = z.infer<typeof AliasDeltaSchema>;
|
||||
|
||||
export class AliasDeltaGenerator {
|
||||
constructor(private llmProvider: ILLMProvider) {}
|
||||
|
||||
/**
|
||||
* Generates a natural, subjective descriptive alias for a target entity
|
||||
* based on its visible attributes from the perspective of a viewer entity.
|
||||
*/
|
||||
async generate(
|
||||
viewer: import("@omnia/core").Entity,
|
||||
target: import("@omnia/core").Entity,
|
||||
): Promise<string> {
|
||||
const visibleAttrs = target.getVisibleAttributesFor(viewer.id);
|
||||
const attrsStr = visibleAttrs.map((a) => `* ${a.name}: ${a.getValue()}`).join("\n");
|
||||
|
||||
const systemPrompt = `
|
||||
You are the Alias Delta Generator for the World Architect.
|
||||
Your task is to generate a natural, subjective, descriptive alias (noun phrase) that a viewer entity would use to refer to a target entity they are seeing for the first time, based ONLY on the target entity's visible public attributes.
|
||||
|
||||
Rules:
|
||||
1. The alias must be a simple, natural, subjective noun phrase (e.g. "the tall woman in the grey jumpsuit", "the red-haired man", "the hooded figure").
|
||||
2. Base the description strictly on the target's visible attributes. Do not invent details not present in the attributes.
|
||||
3. Never use raw system IDs or UUIDs in the alias description.
|
||||
4. Do not use the target's private name attribute unless they have explicit access to it (which is already filtered in the attributes list).
|
||||
5. Return a structured JSON object containing:
|
||||
- "alias": string representing the descriptive alias.
|
||||
`.trim();
|
||||
|
||||
const userContext = `
|
||||
Viewer Entity ID: ${viewer.id}
|
||||
Target Entity ID: ${target.id}
|
||||
|
||||
Target's Visible Attributes:
|
||||
${attrsStr || "(No visible attributes)"}
|
||||
`.trim();
|
||||
|
||||
const response = await this.llmProvider.generateStructuredResponse({
|
||||
systemPrompt,
|
||||
userContext,
|
||||
schema: AliasDeltaSchema,
|
||||
});
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
throw new Error(`Failed to generate alias delta: ${response.error || "Unknown LLM error"}`);
|
||||
}
|
||||
|
||||
return response.data.alias;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, test, expect } from "vitest";
|
||||
import Database from "better-sqlite3";
|
||||
import { WorldState, Entity, SQLiteRepository } from "@omnia/core";
|
||||
import { WorldState, Entity, SQLiteRepository, AttributeVisibility } from "@omnia/core";
|
||||
import { MockLLMProvider } from "@omnia/llm";
|
||||
import { Architect } from "@omnia/architect";
|
||||
import { Architect, AliasDeltaGenerator } from "@omnia/architect";
|
||||
import { Intent } from "@omnia/intent";
|
||||
|
||||
describe("Architect & LLMValidator Unit Tests (Tier 1)", () => {
|
||||
@@ -172,3 +172,25 @@ describe("TimeDeltaGenerator & Architect.processIntent Unit Tests (Tier 1)", ()
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
|
||||
describe("AliasDeltaGenerator Unit Tests (Tier 1)", () => {
|
||||
test("successfully generates descriptive alias based on visible attributes", async () => {
|
||||
const world = new WorldState("world-1");
|
||||
const viewer = new Entity("viewer-1");
|
||||
const target = new Entity("target-1");
|
||||
target.addAttribute("appearance", "A tall elf with silver hair", AttributeVisibility.PUBLIC);
|
||||
target.addAttribute("clothing", "A green tunic", AttributeVisibility.PUBLIC);
|
||||
world.addEntity(viewer);
|
||||
world.addEntity(target);
|
||||
|
||||
const mockResponse = {
|
||||
alias: "the tall silver-haired elf in the green tunic",
|
||||
};
|
||||
const llmProvider = new MockLLMProvider([mockResponse]);
|
||||
const generator = new AliasDeltaGenerator(llmProvider);
|
||||
|
||||
const result = await generator.generate(viewer, target);
|
||||
|
||||
expect(result).toBe("the tall silver-haired elf in the green tunic");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user