import { parseJwt } from "../util/parse-jwt.js";
import { LLMObsTracer } from "./tracer.js";
// Helper function for workflow tracing with common patterns
export function traceWorkflow(name, operation, tags, llmobs = LLMObsTracer.instance) {
    return llmobs.trace({
        kind: "workflow",
        name,
    }, async (span) => {
        if (tags) {
            llmobs.annotate({ tags });
        }
        return operation(span);
    });
}
// Helper function for task tracing with common patterns
export function traceTask(name, operation, tags, llmobs = LLMObsTracer.instance) {
    return llmobs.trace({
        kind: "task",
        name,
    }, async (span) => {
        if (tags) {
            llmobs.annotate({ tags });
        }
        return operation(span);
    });
}
// Helper function for LLM tracing with common patterns
export function traceLLM(name, modelName, modelProvider, operation, tags, llmobs = LLMObsTracer.instance) {
    return llmobs.trace({
        kind: "llm",
        name,
        modelName,
        modelProvider,
    }, async (span) => {
        if (tags) {
            llmobs.annotate({ tags });
        }
        return operation(span);
    });
}
// Helper to extract JWT trace tags
export function getJwtTraceTags(jwt) {
    const result = {};
    const parsed = parseJwt(jwt);
    if (parsed.orgId)
        result["org.id"] = parsed.orgId;
    if (parsed.orgName)
        result["org.name"] = parsed.orgName;
    if (parsed.userId)
        result["user.id"] = parsed.userId;
    if (parsed.userEmail)
        result["user.email"] = parsed.userEmail;
    return result;
}
// Helper to combine common tags with enhanced user information
export function getCommonTraceTags(jwt, applicationId, organizationId, additionalTags = {}) {
    const result = {};
    // Extract and add JWT tags using the extracted function
    Object.assign(result, getJwtTraceTags(jwt));
    // Add required tags (no if checks needed since they're required)
    result["application.id"] = applicationId;
    result["organization.id"] = organizationId;
    // Add additional tags
    Object.assign(result, additionalTags);
    return result;
}
//# sourceMappingURL=helpers.js.map