/**
 * JSON Patch 工具函数
 * 用于创建对话状态的增量更新
 */
/**
 * 条目索引提供器
 * 管理对话条目的递增索引
 */
export class EntryIndexProvider {
    index;
    constructor(startFrom = 0) {
        this.index = startFrom;
    }
    next() {
        return this.index++;
    }
    current() {
        return this.index;
    }
    startFrom(index) {
        this.index = index;
    }
}
/**
 * 添加标准化条目
 */
export function addNormalizedEntry(index, entry) {
    return [
        {
            op: 'add',
            path: `/entries/${index}`,
            value: entry,
        },
    ];
}
/**
 * 替换标准化条目
 */
export function replaceNormalizedEntry(index, entry) {
    return [
        {
            op: 'replace',
            path: `/entries/${index}`,
            value: entry,
        },
    ];
}
/**
 * 更新条目内容
 */
export function updateEntryContent(index, content) {
    return [
        {
            op: 'replace',
            path: `/entries/${index}/content`,
            value: content,
        },
    ];
}
/**
 * 更新工具状态
 */
export function updateToolStatus(index, status) {
    return [
        {
            op: 'replace',
            path: `/entries/${index}/metadata/status`,
            value: status,
        },
    ];
}
/**
 * 设置会话 ID
 */
export function setSessionId(sessionId) {
    return [
        {
            op: 'add',
            path: '/sessionId',
            value: sessionId,
        },
    ];
}
/**
 * 移除条目
 */
export function removeEntry(index) {
    return [
        {
            op: 'remove',
            path: `/entries/${index}`,
        },
    ];
}
/**
 * 合并多个 patch
 */
export function mergePatches(...patches) {
    return patches.flat();
}
/**
 * ConversationPatch 工具对象
 */
export const ConversationPatch = {
    addNormalizedEntry,
    replaceNormalizedEntry,
    updateEntryContent,
    updateToolStatus,
    setSessionId,
    removeEntry,
    mergePatches,
};
//# sourceMappingURL=patch.js.map