- Added a new SceneRulebook system to manage data-driven validation rules for actions. - Introduced rule checks for actions like "take", "open", "move", "introduce", and "describe". - Created a rulebook engine to evaluate conditions and enforce rules during action validation. - Enhanced action handling with support for scene entry and character descriptions. - Updated the architecture documentation to reflect the new rule-based validation approach. - Added new endpoints and improved the persistence layer for rulebooks.
22 lines
818 B
TypeScript
22 lines
818 B
TypeScript
import type { Action } from "./contracts/action";
|
|
import type { SceneRulebook } from "./contracts/rulebook";
|
|
import type { ValidationResult } from "./contracts/validation";
|
|
import type { WorldState } from "./contracts/world";
|
|
import { createDefaultRulebook } from "./defaultRulebook";
|
|
import { validateWithRulebook } from "./rulebookEngine";
|
|
|
|
/**
|
|
* Validate a list of parsed actions against the world state.
|
|
*
|
|
* Pass a SceneRulebook to use data-driven scene rules.
|
|
* Falls back to the built-in default rulebook when none is provided.
|
|
*/
|
|
export function validateActions(
|
|
actions: Action[],
|
|
worldState: WorldState,
|
|
rulebook?: SceneRulebook
|
|
): ValidationResult[] {
|
|
const activeRulebook = rulebook ?? createDefaultRulebook(worldState.id);
|
|
return validateWithRulebook(actions, worldState, activeRulebook);
|
|
}
|