function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
var TASK_STATUSES = [
    'success',
    'pending',
    'loading',
    'error'
];
var isTaskStatus = function isTaskStatus(v) {
    return typeof v === 'string' && TASK_STATUSES.includes(v);
};
/**
 * 将 ```agentic-ui-task JSON 规范化为 TaskListProps（与 parseCode 解析结果一致）
 */ export function normalizeTaskListPropsFromJson(parsed) {
    var root = parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) ? parsed : null;
    var rawItems = root && Array.isArray(root.items) ? root.items : Array.isArray(parsed) ? parsed : [];
    var items = rawItems.filter(function(x) {
        return !!x && (typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object';
    }).map(function(x) {
        var status = isTaskStatus(x.status) ? x.status : 'pending';
        var key = x.key !== undefined && x.key !== null ? String(x.key) : '';
        var title = x.title === undefined || x.title === null ? undefined : String(x.title);
        var content = '';
        if (x.content !== undefined && x.content !== null) {
            if (Array.isArray(x.content)) {
                content = x.content.map(function(line) {
                    return String(line);
                }).join('\n');
            } else {
                content = String(x.content);
            }
        }
        return {
            key: key,
            title: title,
            content: content,
            status: status
        };
    }).filter(function(item) {
        return item.key.length > 0;
    });
    var variantRaw = root ? root.variant : undefined;
    /** 嵌入块默认紧凑摘要条；需完整任务链样式时设 `variant: "default"` */ var variant = variantRaw === 'default' ? 'default' : 'simple';
    var className = root && typeof root.className === 'string' ? root.className : undefined;
    return {
        items: items,
        variant: variant,
        className: className
    };
}
var TOOL_STATUSES = [
    'idle',
    'loading',
    'success',
    'error'
];
var isToolCallStatus = function isToolCallStatus(v) {
    return typeof v === 'string' && TOOL_STATUSES.includes(v);
};
var toolFromRecord = function toolFromRecord(x) {
    var id = x.id !== undefined && x.id !== null ? String(x.id) : x.key !== undefined && x.key !== null ? String(x.key) : '';
    if (!id) return null;
    var status = isToolCallStatus(x.status) ? x.status : 'idle';
    return {
        id: id,
        toolName: x.toolName !== undefined && x.toolName !== null ? String(x.toolName) : '',
        toolTarget: x.toolTarget !== undefined && x.toolTarget !== null ? String(x.toolTarget) : '',
        time: x.time !== undefined && x.time !== null ? String(x.time) : undefined,
        errorMessage: typeof x.errorMessage === 'string' ? x.errorMessage : undefined,
        type: x.type === 'summary' || x.type === 'normal' || typeof x.type === 'string' ? x.type : undefined,
        content: x.content !== undefined && x.content !== null ? String(x.content) : undefined,
        status: status,
        testId: typeof x.testId === 'string' ? x.testId : undefined
    };
};
export function normalizeToolUseBarPropsFromJson(parsed) {
    var root = parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) ? parsed : null;
    var tools = [];
    if (root && Array.isArray(root.tools)) {
        var raw = root.tools;
        tools = raw.filter(function(x) {
            return !!x && (typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object';
        }).map(function(x) {
            return toolFromRecord(x);
        }).filter(function(t) {
            return t !== null;
        });
    } else if (root && Array.isArray(root.items)) {
        var rawItems = root.items;
        tools = rawItems.filter(function(x) {
            return !!x && (typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object';
        }).filter(function(x) {
            return typeof x.text === 'string';
        }).map(function(x, i) {
            var id = x.key !== undefined && x.key !== null ? String(x.key) : String(i);
            return toolFromRecord(_object_spread_props(_object_spread({}, x), {
                id: id,
                toolName: x.text,
                toolTarget: '',
                status: 'idle'
            }));
        }).filter(function(t) {
            return t !== null;
        });
    }
    var className = root && typeof root.className === 'string' ? root.className : undefined;
    var light = root && root.light === true ? true : undefined;
    var disableAnimation = root && root.disableAnimation === true ? true : undefined;
    return {
        tools: tools,
        className: className,
        light: light,
        disableAnimation: disableAnimation
    };
}
var fileItemFromRecord = function fileItemFromRecord(x, index) {
    var name = x.name !== undefined && x.name !== null ? String(x.name) : "file-".concat(index);
    var url = x.url !== undefined && x.url !== null ? String(x.url) : undefined;
    var previewUrl = x.previewUrl !== undefined && x.previewUrl !== null ? String(x.previewUrl) : undefined;
    var type = x.type !== undefined && x.type !== null ? String(x.type) : 'application/octet-stream';
    var size = typeof x.size === 'number' ? x.size : undefined;
    var uuid = x.uuid !== undefined && x.uuid !== null ? String(x.uuid) : x.id !== undefined && x.id !== null ? String(x.id) : "file-".concat(index);
    var rawStatus = x.status;
    var status = rawStatus === 'error' || rawStatus === 'uploading' || rawStatus === 'pending' || rawStatus === 'done' ? rawStatus : undefined;
    var errorMessage = typeof x.errorMessage === 'string' ? x.errorMessage : undefined;
    return {
        name: name,
        type: type,
        url: url,
        previewUrl: previewUrl,
        uuid: uuid,
        size: size,
        status: status,
        errorMessage: errorMessage
    };
};
/**
 * 将 ```agentic-ui-filemap JSON 规范化为 FileMapView 所需 props
 *
 * @param parsed - 解析后的 JSON 数据
 * @param normalizeFile - 可选的自定义文件规范化函数，接收原始 JSON 条目和默认生成的
 *   AttachmentFile，返回最终的 AttachmentFile；返回 null 时该条目被过滤掉
 */ export function normalizeFileMapPropsFromJson(parsed, normalizeFile) {
    var root = parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && !Array.isArray(parsed) ? parsed : null;
    var rawItems = [];
    if (root && Array.isArray(root.fileList)) {
        rawItems = root.fileList;
    } else if (root && Array.isArray(root.files)) {
        rawItems = root.files;
    } else if (Array.isArray(parsed)) {
        rawItems = parsed;
    }
    var fileList = rawItems.filter(function(x) {
        return !!x && (typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object';
    }).map(function(x, i) {
        var defaultFile = fileItemFromRecord(x, i);
        if (!normalizeFile) return defaultFile;
        return normalizeFile(x, defaultFile);
    }).filter(function(f) {
        return f !== null;
    });
    var className = root && typeof root.className === 'string' ? root.className : undefined;
    return {
        fileList: fileList,
        className: className
    };
}
