"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ResolvedModelAdapter: ()=>ResolvedModelAdapter
});
const json_js_namespaceObject = require("../service-caller/json.js");
const factory_js_namespaceObject = require("../shared/model-locate-result/factory.js");
const external_chat_content_js_namespaceObject = require("./chat-content.js");
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;
}
const defaultReplanningCycleLimit = 20;
const defaultImageDetail = (_input)=>void 0;
const defaultChatCompletionParams = ({ midsceneDefaults, userConfig })=>({
        config: {
            temperature: userConfig.temperature ?? midsceneDefaults.temperature
        }
    });
const midsceneChatCompletionDefaults = {
    temperature: 0
};
const defaultLocateResultAdapterDefinition = {
    coordinates: {
        shape: 'bbox',
        order: 'xy',
        normalizedBy: 1000
    }
};
function resolveJsonParser(jsonParser) {
    if (!jsonParser || 'lenient-json' === jsonParser) return json_js_namespaceObject.normalJsonParser;
    if ('function' == typeof jsonParser) return jsonParser;
    throw new Error(`Unknown json parser preset: ${jsonParser}`);
}
function resolveChatCompletion(chatCompletion) {
    const buildChatCompletionParams = chatCompletion?.buildChatCompletionParams ?? defaultChatCompletionParams;
    const resolveImageDetail = chatCompletion?.resolveImageDetail ?? defaultImageDetail;
    const unsupportedUserConfig = chatCompletion?.unsupportedUserConfig ?? [];
    const extractContentAndReasoning = chatCompletion?.extractContentAndReasoning ?? external_chat_content_js_namespaceObject.defaultExtractContentAndReasoning;
    return {
        unsupportedUserConfig,
        buildChatCompletionParams: (input)=>{
            const context = {
                ...input,
                userConfig: input.userConfig ?? {},
                midsceneDefaults: midsceneChatCompletionDefaults
            };
            return buildChatCompletionParams(context);
        },
        resolveImageDetail: (input)=>resolveImageDetail({
                ...input,
                userConfig: input.userConfig ?? {},
                midsceneDefaults: midsceneChatCompletionDefaults
            }),
        extractContentAndReasoning
    };
}
function resolveImagePreprocess(imagePreprocess) {
    return {
        padBlockSize: imagePreprocess?.padBlockSize
    };
}
function resolvePlanning(planning) {
    if (planning?.kind === 'custom') return {
        kind: 'custom',
        cacheEnabled: planning.cacheEnabled ?? true,
        defaultReplanningCycleLimit: planning.defaultReplanningCycleLimit ?? defaultReplanningCycleLimit,
        supportsActionDeepLocate: planning.supportsActionDeepLocate ?? false,
        planFn: planning.planFn
    };
    return {
        kind: 'standard',
        cacheEnabled: planning?.cacheEnabled ?? true,
        defaultReplanningCycleLimit: planning?.defaultReplanningCycleLimit ?? defaultReplanningCycleLimit,
        supportsActionDeepLocate: planning?.supportsActionDeepLocate ?? true
    };
}
function resolveLocate(locate) {
    if (locate?.kind === 'custom') return {
        kind: 'custom',
        supportsSearchArea: locate.supportsSearchArea ?? false,
        locateFn: locate.locateFn
    };
    return {
        kind: 'standard',
        supportsSearchArea: locate?.supportsSearchArea ?? true,
        resultAdapter: (0, factory_js_namespaceObject.createLocateResultAdapter)(locate?.resultAdapter ?? defaultLocateResultAdapterDefinition)
    };
}
class ResolvedModelAdapter {
    constructor(config, modelFamily){
        _define_property(this, "jsonParser", void 0);
        _define_property(this, "chatCompletion", void 0);
        _define_property(this, "imagePreprocess", void 0);
        _define_property(this, "planning", void 0);
        _define_property(this, "locate", void 0);
        this.jsonParser = resolveJsonParser(config.jsonParser);
        this.chatCompletion = resolveChatCompletion(config.chatCompletion);
        this.imagePreprocess = resolveImagePreprocess(config.imagePreprocess);
        this.planning = resolvePlanning(config.planning);
        this.locate = resolveLocate(config.locate);
    }
}
exports.ResolvedModelAdapter = __webpack_exports__.ResolvedModelAdapter;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ResolvedModelAdapter"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});

//# sourceMappingURL=resolved.js.map