/**
 * In-flight event storage with parent-child tracking.
 *
 * Uses LangChain UUIDs directly (hyphens stripped) as trace/span IDs.
 */
import { GraphTracker } from "./graph.mjs";
export class Events {
    constructor() {
        this._events = new Map();
        this._parentMap = new Map();
        this._rootRunId = null;
        this.graph = new GraphTracker();
    }
    store(runId, event) {
        this._events.set(runId, event);
    }
    get(runId) {
        return this._events.get(runId);
    }
    remove(runId) {
        this._events.delete(runId);
    }
    mapParent(runId, parentRunId) {
        this._parentMap.set(runId, parentRunId);
    }
    getTraceId(runId) {
        const root = this._getRoot(runId);
        return root.replace(/-/g, "");
    }
    getSpanId(runId) {
        return runId.replace(/-/g, "");
    }
    setRootIfNeeded(runId) {
        if (this._rootRunId === null)
            this._rootRunId = runId;
    }
    isRoot(runId) {
        return runId === this._rootRunId;
    }
    isGraphNode(runId) {
        const parent = this._parentMap.get(runId);
        return parent != null && parent === this._rootRunId;
    }
    get rootRunId() {
        return this._rootRunId;
    }
    _getRoot(runId) {
        const parent = this._parentMap.get(runId);
        if (parent == null) {
            return runId;
        }
        return this._getRoot(parent);
    }
}
//# sourceMappingURL=events.mjs.map