export function slugify(value) {
    return value
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, '-')
        .replace(/^-+|-+$/g, '')
        .slice(0, 80) || 'item';
}
export function quote(value) {
    const trimmed = value?.trim();
    return trimmed ? `> ${trimmed.replace(/\n+/g, '\n> ')}` : null;
}
export function formatDateTime(timestamp) {
    if (!timestamp || !Number.isFinite(timestamp))
        return null;
    return new Date(timestamp).toISOString();
}
export function joinSections(...sections) {
    return sections.filter((section) => typeof section === 'string' && section.trim().length > 0).join('\n\n');
}
export function dedupe(values, key) {
    const seen = new Set();
    const result = [];
    for (const value of values) {
        const id = key(value);
        if (seen.has(id))
            continue;
        seen.add(id);
        result.push(value);
    }
    return result;
}
export function buildBulletList(items) {
    return items.length > 0 ? items.map((item) => `- ${item}`).join('\n') : '- none';
}
export function sortByTitle(values) {
    return [...values].sort((a, b) => (a.title ?? '').localeCompare(b.title ?? ''));
}
export function materializedTargetReference(target) {
    if ((target.kind === 'source' || target.kind === 'node') && target.itemId) {
        return { kind: target.kind, id: target.itemId };
    }
    return null;
}
export function isActiveKnowledgeEdge(edge) {
    return edge.weight > 0
        && edge.metadata.deleted !== true
        && edge.metadata.linkStatus !== 'unlinked';
}
