export const WORKFLOW_SESSION_METADATA_ENV = "ATOMIC_WORKFLOW_SESSION_METADATA";
function isNonEmptyString(value) {
    return typeof value === "string" && value.trim().length > 0;
}
/** Returns valid workflow ownership metadata without rewriting its string values. */
export function validSessionWorkflowMetadata(value) {
    if (value === null || typeof value !== "object" || Array.isArray(value))
        return undefined;
    const metadata = value;
    if (!isNonEmptyString(metadata.runId)
        || !isNonEmptyString(metadata.stageId)
        || !isNonEmptyString(metadata.stageName)) {
        return undefined;
    }
    return value;
}
/** A session is hidden from normal history only when both ownership markers are valid. */
export function classifiedWorkflowMetadata(header) {
    if (header?.internal !== true)
        return undefined;
    return validSessionWorkflowMetadata(header.workflow);
}
export function isClassifiedWorkflowSession(header) {
    return classifiedWorkflowMetadata(header) !== undefined;
}
export function workflowSessionMetadataFromEnv(env = process.env) {
    const serialized = env[WORKFLOW_SESSION_METADATA_ENV];
    if (!serialized)
        return undefined;
    try {
        return validSessionWorkflowMetadata(JSON.parse(serialized));
    }
    catch {
        return undefined;
    }
}
//# sourceMappingURL=session-manager-classification.js.map