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 buildDisplayContent(msg, appendThinking, appendImagesPlaceholder) {
    var _msg_content;
    var text = (_msg_content = msg.content) !== null && _msg_content !== void 0 ? _msg_content : '';
    if (appendThinking && msg.thinking) {
        text += "".concat(text ? '\n\n' : '', "[thinking]\n").concat(msg.thinking);
    }
    if (appendImagesPlaceholder && msg.images && msg.images.length > 0) {
        text += "".concat(text ? '\n\n' : '', "[images: ").concat(msg.images.length, " attached]");
    }
    return text;
}
/**
 * 将单条 Ollama `ChatMessage` 转为 {@link OpenAIChatMessage}，供统一映射层使用。
 */ export function normalizeOllamaMessageToOpenAI(msg, options) {
    var appendThinking = (options === null || options === void 0 ? void 0 : options.appendThinkingToContent) !== false;
    var appendImages = (options === null || options === void 0 ? void 0 : options.appendImagesPlaceholder) !== false;
    var content = buildDisplayContent(msg, appendThinking, appendImages);
    var base = {
        id: msg.id
    };
    if (msg.role === 'assistant') {
        var _msg_tool_calls;
        return _object_spread(_object_spread_props(_object_spread({}, base), {
            role: 'assistant',
            content: content
        }), ((_msg_tool_calls = msg.tool_calls) === null || _msg_tool_calls === void 0 ? void 0 : _msg_tool_calls.length) ? {
            tool_calls: msg.tool_calls
        } : {});
    }
    if (msg.role === 'tool') {
        var prefix = msg.tool_name ? "[tool_name: ".concat(msg.tool_name, "]\n") : '';
        return _object_spread(_object_spread_props(_object_spread({}, base), {
            role: 'tool',
            content: prefix + content
        }), msg.tool_call_id ? {
            tool_call_id: msg.tool_call_id
        } : {}, msg.tool_name ? {
            name: msg.tool_name
        } : {});
    }
    if (msg.role === 'system') {
        return _object_spread_props(_object_spread({}, base), {
            role: 'system',
            content: content
        });
    }
    return _object_spread_props(_object_spread({}, base), {
        role: 'user',
        content: content
    });
}
/**
 * 批量将 Ollama `messages` 转为 OpenAI 形状
 */ export function normalizeOllamaMessagesToOpenAI(messages, options) {
    return messages.map(function(m) {
        return normalizeOllamaMessageToOpenAI(m, options);
    });
}
