mirror of
https://github.com/sortedcord/omnia.git
synced 2026-07-22 12:02:49 +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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user