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 _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import { mapOpenAIMessagesToMessageBubbleData } from "./mapOpenAIMessages";
import { normalizeOpenClawMessagesToOpenAI } from "./normalizeOpenClawMessages";
/**
 * 将 OpenClaw 会话 / transcript 风格的 `messages` 转为 `MessageBubbleData[]`
 *（内部先归一化为 OpenAI 形状再复用 {@link mapOpenAIMessagesToMessageBubbleData}）。
 */ export function mapOpenClawMessagesToMessageBubbleData(messages, options, mapMessage) {
    var openai = normalizeOpenClawMessagesToOpenAI(messages);
    var _ref = options !== null && options !== void 0 ? options : {}, _ref_useOpenClawTimestamps = _ref.useOpenClawTimestamps, useOpenClawTimestamps = _ref_useOpenClawTimestamps === void 0 ? true : _ref_useOpenClawTimestamps, _ref_preserveOpenClawRawInExtra = _ref.preserveOpenClawRawInExtra, preserveOpenClawRawInExtra = _ref_preserveOpenClawRawInExtra === void 0 ? true : _ref_preserveOpenClawRawInExtra, rest = _object_without_properties(_ref, [
        "useOpenClawTimestamps",
        "preserveOpenClawRawInExtra"
    ]);
    if (!useOpenClawTimestamps && !preserveOpenClawRawInExtra && !mapMessage) {
        return mapOpenAIMessagesToMessageBubbleData(openai, rest);
    }
    var innerMap = function innerMap(msg, index, draft) {
        var d = draft;
        var rawClaw = messages[index];
        if (useOpenClawTimestamps && rawClaw && typeof rawClaw.timestamp === 'number' && Number.isFinite(rawClaw.timestamp)) {
            d = _object_spread_props(_object_spread({}, d), {
                createAt: rawClaw.timestamp,
                updateAt: rawClaw.timestamp
            });
        }
        if (preserveOpenClawRawInExtra && rawClaw) {
            d = _object_spread_props(_object_spread({}, d), {
                extra: _object_spread_props(_object_spread({}, d.extra), {
                    openclaw: {
                        raw: rawClaw
                    }
                })
            });
        }
        if (mapMessage) {
            d = mapMessage(msg, index, d);
        }
        return d;
    };
    return mapOpenAIMessagesToMessageBubbleData(openai, rest, innerMap);
}
