/** * TraitRuntimeIntegration * * Integrates HoloScript's VRTraitRegistry into any runtime loop. * This is the execution engine that makes all trait handlers actually run: * * 1. Parses .holo/.hsplus files → AST with trait declarations * 2. Uses VRTraitRegistry to attach traits to nodes * 3. Calls updateAllTraits() each frame with real TraitContext * 4. Dispatches TraitEvents from platform packages (XR input, physics, etc.) * * Usage: * const factory = createTraitContextFactory({ physics, audio, haptics }); * const integration = new TraitRuntimeIntegration(factory); * integration.attachTraitsFromAST(parsedNodes); * // Each frame: * integration.update(deltaTime); * * @module TraitRuntimeIntegration */ import { VRTraitRegistry } from '@holoscript/core'; import type { HSPlusNode, VRTraitName } from '@holoscript/core'; import type { TraitContext, TraitEvent } from '@holoscript/core'; import { AssetLoadCoordinator, SecurityEventBus, GenerativeJobMonitor, SessionPresenceCoordinator, NeuralForgeCoordinator, ObjectTrackingCoordinator } from '@holoscript/core/coordinators'; import type { TraitContextFactory } from './TraitContextFactory'; export interface TrackedNode { node: HSPlusNode; traitNames: VRTraitName[]; } export interface TraitRuntimeStats { trackedNodes: number; totalTraits: number; updatesPerSecond: number; lastUpdateMs: number; } export declare class TraitRuntimeIntegration { private registry; private contextFactory; private context; private trackedNodes; private frameCount; private lastStatsTime; private updatesPerSecond; private lastUpdateMs; private paused; /** * Asset load consumer-bus — Pattern E remediation per /stub-audit * Phase 3.5 + task_1777281302813_eezs (commit 7ae7971cc). Subscribes * to the engine's TraitContextFactory event stream and tracks * GLTF/USD/FBX asset loading state across the runtime. Downstream * consumers (loading screens, asset caches, scene-progress overlays) * call `traitRuntime.assetLoadCoordinator.subscribe(listener)` to * observe state changes. */ readonly assetLoadCoordinator: AssetLoadCoordinator; /** * Security event consumer-bus — second of the 4 buses identified by * /stub-audit Phase 3.5. Subscribes to the engine's event stream and * tracks state across the security trait cluster: RBAC + SSO + Quota * + Tenant + AuditLog + ForgetPolicy (~75 void events). Downstream * consumers (SIEM bridges, admin dashboards, compliance reports) * call `traitRuntime.securityEventBus.subscribe(listener)` to observe * domain-tagged envelopes (auth/authz/quota/tenant/audit/forget). */ readonly securityEventBus: SecurityEventBus; /** * Generative-job consumer-bus — third of the 4 buses. Subscribes to * the lifecycle vocabulary of the generative-AI trait cluster: * AiInpainting + AiTextureGen + ControlNet + DiffusionRealtime (23 * events). Tracks per-job state (queued/running/completed/cancelled/ * errored) and per-kind throughput stats. Downstream consumers * (Studio progress overlays, GPU budget enforcement, latency * dashboards, realtime-diffusion FPS displays) call * `traitRuntime.generativeJobMonitor.subscribe(listener)`. */ readonly generativeJobMonitor: GenerativeJobMonitor; /** * Session presence consumer-bus — fourth of the 5 buses. * Subscribes to the multiplayer-presence trait cluster: SharePlay + * SpatialVoice + WorldHeartbeat + Messaging (26 events). Tracks * sessions, voice peers + mute state, messaging connections, and * heartbeat liveness. Downstream consumers (lobby UI, peer roster, * presence indicators, uptime dashboards, network-quality meters) * call `traitRuntime.sessionPresenceCoordinator.subscribe(listener)`. */ readonly sessionPresenceCoordinator: SessionPresenceCoordinator; /** * Neural-forge consumer-bus — fifth of the 5 buses. Subscribes to * the NeuralForgeTrait synthesis-lifecycle event vocabulary: * neural_forge_connected, neural_synthesis_request, * neural_synthesis_timeout, neural_shard_created, * neural_cognition_evolved (5 events). Tracks per-node state * (shards, weights, pending synthesis, timeout fallback). Downstream * consumers (Studio NPC panels, Brittney synthesis routing, Quest 3 * cognition overlays, logging/metrics) call * `traitRuntime.neuralForgeCoordinator.subscribe(listener)`. * Closes Pattern E for neural_forge (task_1777423899630_nsna). */ readonly neuralForgeCoordinator: NeuralForgeCoordinator; /** * Object-tracking consumer-bus. Subscribes to ObjectTrackingTrait's * tracking lifecycle events and exposes current tracked anchor state * to Studio, Quest overlays, and runtime diagnostics. */ readonly objectTrackingCoordinator: ObjectTrackingCoordinator; constructor(contextFactory: TraitContextFactory); /** * Register a node and attach its declared traits. */ registerNode(node: HSPlusNode): void; /** * Attach traits from parsed AST nodes. * Walks the AST and registers any node that has traits declared. */ attachTraitsFromAST(nodes: HSPlusNode[]): void; /** * Dynamically attach a trait to an already-registered node. */ attachTrait(nodeId: string, traitName: VRTraitName, config?: unknown): void; /** * Detach a trait from a node. */ detachTrait(nodeId: string, traitName: VRTraitName): void; /** * Unregister a node and detach all its traits. */ unregisterNode(nodeId: string): void; /** * Call every frame. Updates all traits on all tracked nodes. * @param delta Time in seconds since last frame */ update(delta: number): void; /** * Dispatch a TraitEvent to a specific node. */ dispatchEvent(nodeId: string, event: TraitEvent): void; /** * Dispatch a TraitEvent to ALL tracked nodes. */ broadcastEvent(event: TraitEvent): void; pause(): void; resume(): void; isPaused(): boolean; /** * Refresh the TraitContext (call after hot-swapping a provider). */ refreshContext(): void; getNode(nodeId: string): HSPlusNode | undefined; getNodeTraits(nodeId: string): VRTraitName[]; getAllNodeIds(): string[]; getStats(): TraitRuntimeStats; getRegistry(): VRTraitRegistry; getContext(): TraitContext; reset(): void; dispose(): void; } export declare function createTraitRuntime(contextFactory: TraitContextFactory): TraitRuntimeIntegration; //# sourceMappingURL=TraitRuntimeIntegration.d.ts.map