"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LlamaIndexParser = void 0;
const utilts_1 = require("../../utils/utilts");
const detector_1 = require("./detector");
const openInferenceHandler_1 = require("./handlers/openInferenceHandler");
const otelTracerHandler_1 = require("./handlers/otelTracerHandler");
/**
 * LlamaIndex framework parser.
 *
 * Supports two instrumentation styles (detected automatically):
 * - openinference: OpenInference/Phoenix; exact span names, rich attributes (input.value, llm.model_name, etc.).
 * - otel_tracer: LlamaIndex OTel tracer; span names with UUID suffix, minimal attributes.
 *
 * Design is extensible: other frameworks can use the same pattern (detect variant → delegate to handler).
 */
class LlamaIndexParser {
    constructor() {
        this.name = 'llamaindex';
        this.handlers = new Map([
            ['openinference', new openInferenceHandler_1.OpenInferenceHandler()],
            ['otel_tracer', new otelTracerHandler_1.OtelTracerHandler()]
        ]);
    }
    canParse(spans) {
        return spans.some((s) => utilts_1.FrameworkUtils.getAttr(s.attributes, 'gen_ai.system', 'genai.system') === 'llamaindex' ||
            s.attributes['genai.framework'] === 'llamaindex' ||
            utilts_1.FrameworkUtils.getAttr(s.attributes, 'openinference.span.kind') != null ||
            s.name?.includes('llamaindex') ||
            s.name?.includes('llama_index') ||
            s.name === 'AgentWorkflow.run' ||
            s.name?.startsWith('AgentWorkflow.'));
    }
    getHandler(spans) {
        const kind = (0, detector_1.detectLlamaIndexInstrumentation)(spans);
        const handler = this.handlers.get(kind);
        if (!handler) {
            return this.handlers.get('openinference');
        }
        return handler;
    }
    getTools(spans) {
        return this.getHandler(spans).getTools(spans);
    }
    getAgents(spans) {
        return this.getHandler(spans).getAgents(spans);
    }
    getModels(spans) {
        return this.getHandler(spans).getModels(spans);
    }
    generateDag(spans) {
        return this.getHandler(spans).generateDag(spans);
    }
    generateLinearFlow(spans) {
        return this.getHandler(spans).generateLinearFlow(spans);
    }
    getModelsFromUnscoped(spans) {
        return this.getHandler(spans)?.getModelsFromUnscoped?.(spans) ?? [];
    }
}
exports.LlamaIndexParser = LlamaIndexParser;
//# sourceMappingURL=index.js.map