nn-ui-v2 / build /server /chunks /LlmSelector-fG0hpxMx.js
muryshev's picture
update
9923f3d
import { c as create_ssr_component, a as subscribe, e as escape, v as validate_component, h as each, s as setContext, d as add_attribute, j as getContext, q as compute_slots } from './ssr-6MZFlfLu.js';
import { w as writable } from './index2-f61NAEsz.js';
import './ProgressBar.svelte_svelte_type_style_lang-H22V2Yrx.js';
import { g as getModalStore } from './stores-0qksNY90.js';
const cBase$1 = "";
const ListBox = create_ssr_component(($$result, $$props, $$bindings, slots) => {
let classesBase;
let { multiple = false } = $$props;
let { spacing = "space-y-1" } = $$props;
let { rounded = "rounded-token" } = $$props;
let { active = "variant-filled" } = $$props;
let { hover = "hover:variant-soft" } = $$props;
let { padding = "px-4 py-2" } = $$props;
let { regionLead = "" } = $$props;
let { regionDefault = "" } = $$props;
let { regionTrail = "" } = $$props;
let { labelledby = "" } = $$props;
setContext("multiple", multiple);
setContext("rounded", rounded);
setContext("active", active);
setContext("hover", hover);
setContext("padding", padding);
setContext("regionLead", regionLead);
setContext("regionDefault", regionDefault);
setContext("regionTrail", regionTrail);
if ($$props.multiple === void 0 && $$bindings.multiple && multiple !== void 0)
$$bindings.multiple(multiple);
if ($$props.spacing === void 0 && $$bindings.spacing && spacing !== void 0)
$$bindings.spacing(spacing);
if ($$props.rounded === void 0 && $$bindings.rounded && rounded !== void 0)
$$bindings.rounded(rounded);
if ($$props.active === void 0 && $$bindings.active && active !== void 0)
$$bindings.active(active);
if ($$props.hover === void 0 && $$bindings.hover && hover !== void 0)
$$bindings.hover(hover);
if ($$props.padding === void 0 && $$bindings.padding && padding !== void 0)
$$bindings.padding(padding);
if ($$props.regionLead === void 0 && $$bindings.regionLead && regionLead !== void 0)
$$bindings.regionLead(regionLead);
if ($$props.regionDefault === void 0 && $$bindings.regionDefault && regionDefault !== void 0)
$$bindings.regionDefault(regionDefault);
if ($$props.regionTrail === void 0 && $$bindings.regionTrail && regionTrail !== void 0)
$$bindings.regionTrail(regionTrail);
if ($$props.labelledby === void 0 && $$bindings.labelledby && labelledby !== void 0)
$$bindings.labelledby(labelledby);
classesBase = `${cBase$1} ${spacing} ${rounded} ${$$props.class ?? ""}`;
return `<div class="${"listbox " + escape(classesBase, true)}" role="listbox"${add_attribute("aria-labelledby", labelledby, 0)} data-testid="listbox">${slots.default ? slots.default({}) : ``}</div>`;
});
const cBase = "cursor-pointer -outline-offset-[3px]";
const cLabel = "flex items-center space-x-4";
const cRegionLead = "";
const cRegionDefault = "flex-1";
const cRegionTrail = "";
function areDeeplyEqual(param1, param2) {
if (param1 === param2)
return true;
if (!(param1 instanceof Object) || !(param2 instanceof Object))
return false;
const keys1 = Object.keys(param1);
const keys2 = Object.keys(param2);
if (keys1.length !== keys2.length)
return false;
for (const key of keys1) {
const value1 = param1[key];
const value2 = param2[key];
if (!areDeeplyEqual(value1, value2))
return false;
}
return true;
}
const ListBoxItem = create_ssr_component(($$result, $$props, $$bindings, slots) => {
let selected;
let classesActive;
let classesBase;
let classesLabel;
let classesRegionLead;
let classesRegionDefault;
let classesRegionTrail;
let $$slots = compute_slots(slots);
let { group } = $$props;
let { name } = $$props;
let { value } = $$props;
let { multiple = getContext("multiple") } = $$props;
let { rounded = getContext("rounded") } = $$props;
let { active = getContext("active") } = $$props;
let { hover = getContext("hover") } = $$props;
let { padding = getContext("padding") } = $$props;
let { regionLead = getContext("regionLead") } = $$props;
let { regionDefault = getContext("regionDefault") } = $$props;
let { regionTrail = getContext("regionTrail") } = $$props;
let checked;
let elemInput;
function updateCheckbox(group2) {
checked = group2.indexOf(value) >= 0;
}
function updateGroup(checked2) {
const index = group.indexOf(value);
if (checked2) {
if (index < 0) {
group.push(value);
group = group;
}
} else {
if (index >= 0) {
group.splice(index, 1);
group = group;
}
}
}
if ($$props.group === void 0 && $$bindings.group && group !== void 0)
$$bindings.group(group);
if ($$props.name === void 0 && $$bindings.name && name !== void 0)
$$bindings.name(name);
if ($$props.value === void 0 && $$bindings.value && value !== void 0)
$$bindings.value(value);
if ($$props.multiple === void 0 && $$bindings.multiple && multiple !== void 0)
$$bindings.multiple(multiple);
if ($$props.rounded === void 0 && $$bindings.rounded && rounded !== void 0)
$$bindings.rounded(rounded);
if ($$props.active === void 0 && $$bindings.active && active !== void 0)
$$bindings.active(active);
if ($$props.hover === void 0 && $$bindings.hover && hover !== void 0)
$$bindings.hover(hover);
if ($$props.padding === void 0 && $$bindings.padding && padding !== void 0)
$$bindings.padding(padding);
if ($$props.regionLead === void 0 && $$bindings.regionLead && regionLead !== void 0)
$$bindings.regionLead(regionLead);
if ($$props.regionDefault === void 0 && $$bindings.regionDefault && regionDefault !== void 0)
$$bindings.regionDefault(regionDefault);
if ($$props.regionTrail === void 0 && $$bindings.regionTrail && regionTrail !== void 0)
$$bindings.regionTrail(regionTrail);
{
if (multiple)
updateCheckbox(group);
}
{
if (multiple)
updateGroup(checked);
}
selected = multiple ? group.some((groupVal) => areDeeplyEqual(value, groupVal)) : areDeeplyEqual(group, value);
classesActive = selected ? active : hover;
classesBase = `${cBase} ${rounded} ${padding} ${classesActive} ${$$props.class ?? ""}`;
classesLabel = `${cLabel}`;
classesRegionLead = `${cRegionLead} ${regionLead}`;
classesRegionDefault = `${cRegionDefault} ${regionDefault}`;
classesRegionTrail = `${cRegionTrail} ${regionTrail}`;
return `<label> <div class="${"listbox-item " + escape(classesBase, true)}" data-testid="listbox-item" role="option"${add_attribute("aria-selected", selected, 0)} tabindex="0"> <div class="h-0 w-0 overflow-hidden">${multiple ? `<input type="checkbox"${add_attribute("name", name, 0)}${add_attribute("value", value, 0)} tabindex="-1"${add_attribute("this", elemInput, 0)}${add_attribute("checked", checked, 1)}>` : `<input type="radio"${add_attribute("name", name, 0)}${add_attribute("value", value, 0)} tabindex="-1"${add_attribute("this", elemInput, 0)}${value === group ? add_attribute("checked", true, 1) : ""}>`}</div> <div class="${"listbox-label " + escape(classesLabel, true)}"> ${$$slots.lead ? `<div class="${"listbox-label-lead " + escape(classesRegionLead, true)}">${slots.lead ? slots.lead({}) : ``}</div>` : ``} <div class="${"listbox-label-content " + escape(classesRegionDefault, true)}">${slots.default ? slots.default({}) : ``}</div> ${$$slots.trail ? `<div class="${"listbox-label-trail " + escape(classesRegionTrail, true)}">${slots.trail ? slots.trail({}) : ``}</div>` : ``}</div></div></label>`;
});
const LlmSettings = create_ssr_component(($$result, $$props, $$bindings, slots) => {
getModalStore();
let { llmParams } = $$props;
let { addLlmCallback } = $$props;
let { removeCallback } = $$props;
({ ...llmParams });
if ($$props.llmParams === void 0 && $$bindings.llmParams && llmParams !== void 0)
$$bindings.llmParams(llmParams);
if ($$props.addLlmCallback === void 0 && $$bindings.addLlmCallback && addLlmCallback !== void 0)
$$bindings.addLlmCallback(addLlmCallback);
if ($$props.removeCallback === void 0 && $$bindings.removeCallback && removeCallback !== void 0)
$$bindings.removeCallback(removeCallback);
return ` <button class="btn variant-outline-tertiary" data-svelte-h="svelte-qhip0s">Настроить LLM</button> `;
});
const LlmSelector = create_ssr_component(($$result, $$props, $$bindings, slots) => {
let $llmList, $$unsubscribe_llmList;
let { selectedLLM = null } = $$props;
let { skipLoadList = false } = $$props;
let { label = selectedLLM?.name || "Выбрать LLM" } = $$props;
const popupId = Math.random();
const llmList = writable([]);
$$unsubscribe_llmList = subscribe(llmList, (value) => $llmList = value);
const addOrUpdateLlm = (newLlm) => {
llmList.update((currentList) => {
let found = false;
for (let llm of currentList) {
if (newLlm.name.endsWith(" (изменено)")) {
if (llm.name === newLlm.name) {
Object.assign(llm, newLlm);
found = true;
break;
}
}
}
if (!found) {
const newItem = {
...newLlm,
name: newLlm.name + " (изменено)"
};
currentList.push(newItem);
selectedLLM = newItem;
}
return currentList;
});
};
const addLlmCallback = (item) => {
addOrUpdateLlm(item);
};
const removeLlm = (name) => {
llmList.update((currentList) => {
const list = currentList.filter((llm) => llm.name !== name);
return list;
});
};
const removeCallback = (name) => {
removeLlm(name);
selectedLLM = $llmList[0];
};
if ($$props.selectedLLM === void 0 && $$bindings.selectedLLM && selectedLLM !== void 0)
$$bindings.selectedLLM(selectedLLM);
if ($$props.skipLoadList === void 0 && $$bindings.skipLoadList && skipLoadList !== void 0)
$$bindings.skipLoadList(skipLoadList);
if ($$props.label === void 0 && $$bindings.label && label !== void 0)
$$bindings.label(label);
let $$settled;
let $$rendered;
let previous_head = $$result.head;
do {
$$settled = true;
$$result.head = previous_head;
label = selectedLLM?.name || "Выбрать LLM";
$$rendered = `<button class="btn variant-filled w-72 justify-between">${escape(label)} <i class="fa-solid fa-angle-down"></i></button> <div class="card w-72 shadow-xl py-2" data-popup="${"listPopup" + escape(popupId, true)}">${validate_component(ListBox, "ListBox").$$render($$result, { rounded: "rounded-none" }, {}, {
default: () => {
return ` ${each($llmList, (llm) => {
return `${validate_component(ListBoxItem, "ListBoxItem").$$render(
$$result,
{
name: "medium",
value: llm,
group: selectedLLM
},
{
group: ($$value) => {
selectedLLM = $$value;
$$settled = false;
}
},
{
default: () => {
return `${escape(llm.name)} `;
}
}
)}`;
})}`;
}
})}</div> ${selectedLLM ? `${validate_component(LlmSettings, "LlmSettings").$$render(
$$result,
{
addLlmCallback,
removeCallback,
llmParams: selectedLLM
},
{
llmParams: ($$value) => {
selectedLLM = $$value;
$$settled = false;
}
},
{}
)}` : ``}`;
} while (!$$settled);
$$unsubscribe_llmList();
return $$rendered;
});
export { LlmSelector as L };
//# sourceMappingURL=LlmSelector-fG0hpxMx.js.map