"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 ("u" > 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__, {
    groupModels: ()=>groupModels,
    getSubstitutionTarget: ()=>getSubstitutionTarget,
    filterModels: ()=>filterModels,
    deriveModelTags: ()=>deriveModelTags,
    defaultCostTier: ()=>defaultCostTier
});
const external_badges_cjs_namespaceObject = require("./badges.cjs");
const external_i18n_cjs_namespaceObject = require("./i18n.cjs");
const RECOMMENDED_SUBSCRIPTION = 'UiPathOwned';
const isByoModel = (m)=>'BYOMAdded' === m.modelSubscriptionType || 'BYOMReplacedAlternative' === m.modelSubscriptionType || 'BYOMReplacedLikeForLike' === m.modelSubscriptionType || !!m.byomDetails || !!m.byoConnectionLabel;
function deriveModelTags(model, context = {}) {
    const tags = [];
    const localize = (desc)=>{
        if (context.i18n) return (0, external_i18n_cjs_namespaceObject.tr)(context.i18n, desc);
        return desc.message ?? desc.id;
    };
    const isByo = isByoModel(model);
    const isRecommended = void 0 !== context.recommendedModelIds ? context.recommendedModelIds.includes(model.modelId) : model.isRecommended ?? (model.modelSubscriptionType === RECOMMENDED_SUBSCRIPTION && !model.isPreview && !model.deprecationDetails?.usageEndDate);
    if (isRecommended) tags.push({
        kind: 'recommended',
        label: localize(external_i18n_cjs_namespaceObject.TAG_LABELS.recommended),
        tooltip: localize(external_i18n_cjs_namespaceObject.TAG_LABELS.recommendedTooltip)
    });
    const isPreview = void 0 !== context.previewModelIds ? context.previewModelIds.includes(model.modelId) : !!model.isPreview;
    if (!isByo && isPreview) tags.push({
        kind: 'preview',
        label: localize(external_i18n_cjs_namespaceObject.TAG_LABELS.preview)
    });
    const substitutionTarget = getSubstitutionTarget(model);
    if (substitutionTarget) tags.push({
        kind: 'substituted',
        label: context.i18n ? context.i18n._({
            id: 'modelPicker.tag.substituted.label',
            message: 'Routes to {target}',
            values: {
                target: substitutionTarget
            }
        }) : `Routes to ${substitutionTarget}`,
        tooltip: context.i18n ? context.i18n._({
            id: 'modelPicker.tag.substituted.tooltip',
            message: 'This model is retired. Your traffic is currently being routed to {target}. Update your configuration to make this explicit.',
            values: {
                target: substitutionTarget
            }
        }) : `This model is retired. Your traffic is currently being routed to ${substitutionTarget}. Update your configuration to make this explicit.`
    });
    else if (model.deprecationDetails?.usageEndDate) {
        const date = formatDate(model.deprecationDetails.usageEndDate);
        tags.push({
            kind: 'deprecating',
            label: context.i18n ? context.i18n._({
                id: 'modelPicker.tag.deprecating.label',
                message: 'Deprecating {date}',
                values: {
                    date
                }
            }) : `Deprecating ${date}`,
            tooltip: model.deprecationDetails.replacedBy ? context.i18n ? context.i18n._({
                id: 'modelPicker.tag.deprecating.tooltip',
                message: 'Will be replaced by {replacement}',
                values: {
                    replacement: model.deprecationDetails.replacedBy
                }
            }) : `Will be replaced by ${model.deprecationDetails.replacedBy}` : void 0
        });
    }
    if (isByo) tags.push({
        kind: 'custom',
        label: localize(external_i18n_cjs_namespaceObject.TAG_LABELS.custom)
    });
    if (!isByo) {
        const geo = model.routingDetails?.geography;
        if (geo && context.homeRegion && 'GLOBAL' !== geo && geo !== context.homeRegion) tags.push({
            kind: 'out-of-region',
            label: context.i18n ? context.i18n._({
                id: 'modelPicker.tag.outOfRegion.label',
                message: 'Out of region ({geography})',
                values: {
                    geography: geo
                }
            }) : `Out of region (${geo})`,
            tooltip: context.i18n ? context.i18n._({
                id: 'modelPicker.tag.outOfRegion.tooltip',
                message: 'Routes traffic outside {homeRegion}',
                values: {
                    homeRegion: context.homeRegion
                }
            }) : `Routes traffic outside ${context.homeRegion}`
        });
    }
    if (context.badgesFor) for (const kind of context.badgesFor(model) ?? []){
        const def = external_badges_cjs_namespaceObject.MODEL_BADGES[kind];
        if (def) tags.push({
            kind,
            label: localize(def.label),
            tooltip: def.tooltip ? localize(def.tooltip) : void 0,
            variant: def.variant
        });
    }
    if (context.customTagsFor) {
        const extra = context.customTagsFor(model);
        if (extra?.length) tags.push(...extra);
    }
    return tags;
}
const DEFAULT_BASIC_THRESHOLD = 1.0;
const DEFAULT_PREMIUM_THRESHOLD = 5.0;
function defaultCostTier(model) {
    const inputCost = model.modelDetails?.costDetails?.inputTokenCost;
    if (null == inputCost) return null;
    if (inputCost < DEFAULT_BASIC_THRESHOLD) return 'basic';
    if (inputCost < DEFAULT_PREMIUM_THRESHOLD) return 'standard';
    return 'premium';
}
function getSubstitutionTarget(model) {
    const effective = model.effectiveModel;
    if (effective && effective !== model.modelName && effective !== model.modelId) return model.deprecationDetails?.replacedBy ?? effective;
    const routed = model.routingDetails?.model;
    if (routed && routed !== model.modelName && routed !== model.modelId) return model.deprecationDetails?.replacedBy ?? routed;
    return null;
}
const VENDOR_LABELS = {
    AnthropicClaude: 'Anthropic',
    OpenAi: 'OpenAI',
    AzureOpenAi: 'Azure OpenAI',
    VertexAi: 'Google Vertex',
    AwsBedrock: 'AWS Bedrock'
};
function vendorLabel(vendor) {
    return VENDOR_LABELS[vendor] ?? vendor;
}
function formatDate(iso) {
    const date = new Date(iso);
    if (Number.isNaN(date.getTime())) return iso;
    return date.toLocaleDateString(void 0, {
        month: 'short',
        year: 'numeric'
    });
}
function buildSubscriptionMatchers(ctx) {
    const isRecommended = (m)=>void 0 !== ctx.recommendedModelIds ? ctx.recommendedModelIds.includes(m.modelId) : m.isRecommended ?? (m.modelSubscriptionType === RECOMMENDED_SUBSCRIPTION && !m.isPreview && !m.deprecationDetails?.usageEndDate);
    const isPreview = (m)=>void 0 !== ctx.previewModelIds ? ctx.previewModelIds.includes(m.modelId) : !!m.isPreview;
    const localize = (desc)=>{
        if (ctx.i18n) return (0, external_i18n_cjs_namespaceObject.tr)(ctx.i18n, desc);
        return desc.message ?? desc.id;
    };
    return [
        {
            key: 'byo',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.byo),
            hint: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.byoHint),
            match: (m)=>isByoModel(m)
        },
        {
            key: 'recommended',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.recommended),
            hint: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.recommendedHint),
            match: (m)=>isRecommended(m) && !m.deprecationDetails?.usageEndDate
        },
        {
            key: 'preview',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.preview),
            hint: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.previewHint),
            match: (m)=>isPreview(m) && !isByoModel(m) && !m.deprecationDetails?.usageEndDate
        },
        {
            key: 'more',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.more),
            hint: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.moreHint),
            match: (m)=>!isByoModel(m) && !m.deprecationDetails?.usageEndDate
        },
        {
            key: 'deprecating',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.deprecating),
            hint: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.deprecatingHint),
            match: (m)=>!!m.deprecationDetails?.usageEndDate
        },
        {
            key: 'shared',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.other),
            match: ()=>true
        }
    ];
}
function groupModels(models, strategy = "subscription", context = {}) {
    const localize = (desc)=>{
        if (context.i18n) return (0, external_i18n_cjs_namespaceObject.tr)(context.i18n, desc);
        return desc.message ?? desc.id;
    };
    if ('flat' === strategy) return [
        {
            key: 'all',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.allModels),
            models
        }
    ];
    if ('vendor' === strategy) {
        const byVendor = new Map();
        const byo = [];
        for (const m of models){
            if (isByoModel(m)) {
                byo.push(m);
                continue;
            }
            const k = m.vendor || 'Other';
            if (!byVendor.has(k)) byVendor.set(k, []);
            byVendor.get(k).push(m);
        }
        const groups = [];
        if (byo.length) groups.push({
            key: 'byo',
            label: localize(external_i18n_cjs_namespaceObject.GROUP_LABELS.byo),
            models: byo
        });
        const matchers = buildSubscriptionMatchers(context);
        const ranks = new Map();
        const lifecycleRank = (m)=>{
            let r = ranks.get(m);
            if (void 0 === r) {
                const i = matchers.findIndex((g)=>g.match(m));
                r = -1 === i ? matchers.length : i;
                ranks.set(m, r);
            }
            return r;
        };
        for (const [key, list] of byVendor.entries())groups.push({
            key,
            label: vendorLabel(key),
            models: list.sort((a, b)=>lifecycleRank(a) - lifecycleRank(b))
        });
        return groups;
    }
    const matchers = buildSubscriptionMatchers(context);
    const buckets = {};
    for (const m of models){
        const bucket = matchers.find((g)=>g.match(m));
        if (!bucket) continue;
        const list = buckets[bucket.key] ?? (buckets[bucket.key] = []);
        list.push(m);
    }
    const out = [];
    for (const g of matchers){
        const list = buckets[g.key];
        if (list?.length) out.push({
            key: g.key,
            label: g.label,
            hint: g.hint,
            models: list
        });
    }
    return out;
}
function filterModels(models, query) {
    const q = query.trim().toLowerCase();
    if (!q) return models;
    return models.filter((m)=>{
        const haystack = [
            m.modelName,
            m.displayName,
            m.modelId,
            m.vendor,
            m.modelFamily,
            m.effectiveModel,
            m.byoConnectionLabel
        ].filter(Boolean).join(' ').toLowerCase();
        return haystack.includes(q);
    });
}
exports.defaultCostTier = __webpack_exports__.defaultCostTier;
exports.deriveModelTags = __webpack_exports__.deriveModelTags;
exports.filterModels = __webpack_exports__.filterModels;
exports.getSubstitutionTarget = __webpack_exports__.getSubstitutionTarget;
exports.groupModels = __webpack_exports__.groupModels;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "defaultCostTier",
    "deriveModelTags",
    "filterModels",
    "getSubstitutionTarget",
    "groupModels"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
