updated lite (+3 squashed commit)

Squashed commit:

[605fef9ca] updated lite

[dad606fad] updated sdui

[22246d7eb] updated lite
This commit is contained in:
Concedo
2025-12-29 17:55:46 +08:00
parent 329c0e7e32
commit 20ea081594
2 changed files with 105 additions and 96 deletions
+22 -22
View File
File diff suppressed because one or more lines are too long
+83 -74
View File
@@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
-->
<script id="init-config">
const LITEVER = 303;
const LITEVER = 304;
const urlParams = new URLSearchParams(window.location.search);
var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@@ -3519,6 +3519,7 @@ Current version indicated by LITEVER below.
const koboldcpp_savedata_list_endpoint = "/api/extra/data/list";
const koboldcpp_savedata_save_endpoint = "/api/extra/data/save";
const koboldcpp_savedata_load_endpoint = "/api/extra/data/load";
const koboldcpp_mcp_endpoint = "/mcp";
const oai_models_endpoint = "/models";
const oai_submit_endpoint = "/completions";
@@ -3591,7 +3592,6 @@ Current version indicated by LITEVER below.
const default_xtts_base = " http://localhost:8020";
const default_alltalk_base = "http://localhost:7851";
const default_comfy_base = "http://localhost:8188";
const default_mcp_base = "http://localhost:5001";
const WEBBROWSER_TTS_ID = 1;
const KCPP_TTS_ID = 2;
@@ -3783,7 +3783,7 @@ Current version indicated by LITEVER below.
saved_comfy_url: default_comfy_base,
saved_xtts_url: default_xtts_base,
saved_alltalk_url: default_alltalk_base,
saved_mcp_urls: default_mcp_base,
saved_mcp_urls: "",
prev_custom_endpoint_type: 0, //show a reconnect box to custom endpoint if needed. 0 is horde, otherwise its dropdown value+1
prev_custom_endpoint_model: "", //we may not be able to match, but set it if we do
prev_custom_endpoint_ischatcmpl: true,
@@ -3887,6 +3887,7 @@ Current version indicated by LITEVER below.
enable_tool_use: false,
tools_auto_exec: true,
corsproxy_mcp: false,
kcpp_mcp_bridge: false,
cached_mcp_tools: {}, //key is url, value is tools array
disabled_mcp_tools: [], //maintain a list of unwanted tools that was deselected
@@ -3898,6 +3899,7 @@ Current version indicated by LITEVER below.
legacy_savefile:false,
allow_continue_user_turn: false,
proxy_disable_stream:false,
new_session_erase_memory: false,
//section migrated from story itself
extrastopseq: "",
@@ -7312,65 +7314,72 @@ Current version indicated by LITEVER below.
isError: function (msg) { return "error" in msg; }
};
function ParseMCPResp(response, expectedId, onNotification) {
let ParseMCPSSE = function(response, expectedId, onNotification) {
let ParseMCPSSE = function (response, expectedId, onNotification) {
return new Promise(function (resolve, reject) {
var reader = response.body.getReader();
var decoder = new TextDecoder();
var buffer = "";
function processBuffer() {
let idx;
while ((idx = buffer.search(/\r?\n\r?\n/)) !== -1) {
let rawEvent = buffer.slice(0, idx);
buffer = buffer.slice(idx).replace(/^\r?\n\r?\n/, "");
let eventType = "message";
let dataLines = [];
let lines = rawEvent.split(/\r?\n/);
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if (line.startsWith("event:")) {
eventType = line.slice(6).trim();
} else if (line.startsWith("data:")) {
let d = line.slice(5);
if (d.startsWith(" ")) d = d.slice(1);
dataLines.push(d);
}
}
if (eventType !== "message" || !dataLines.length) continue;
let data = dataLines.join("\n");
if (data[0] !== "{") continue;
let message;
try {
message = JSON.parse(data);
} catch (e) {
continue;
}
if (jsonRPC.isNotification(message)) {
onNotification && onNotification(message);
continue;
}
if (jsonRPC.isResponse(message) && message.id === expectedId) {
reader.cancel().catch(function () {});
resolve(message);
return true;
}
}
return false;
}
function read() {
reader.read().then(function (result) {
if (result.done) {
resolve(null); // End of stream without final response
resolve(null);
return;
}
buffer += decoder.decode(result.value, { stream: true });
var events = buffer.split("\n\n"); // Split on double newlines (SSE event boundary)
buffer = events.pop(); // Keep incomplete event in buffer
for (var i = 0; i < events.length; i++) {
var event = events[i];
// Parse SSE event fields
var eventType = "message"; // default per SSE spec
var data = "";
var lines = event.split("\n");
for (var j = 0; j < lines.length; j++) {
var line = lines[j];
if (line.indexOf("event:") === 0) {
eventType = line.slice(6).trim();
} else if (line.indexOf("data:") === 0) {
data += (data ? "\n" : "") + line.slice(5).trim();
}
}
if (!data || eventType !== "message") continue; // Skip non-message events (e.g., ping) or empty data
if (data.indexOf("{") !== 0) continue; // Skip non-JSON data
try {
var message = JSON.parse(data);
} catch (e) {
continue; // Ignore parse errors
}
if (jsonRPC.isNotification(message)) {
if (onNotification) onNotification(message);
continue;
}
if (jsonRPC.isResponse(message) && message.id === expectedId) {
// Must release reader before resolving
reader.cancel().catch(function () { }); // Cancel the stream
resolve(message);
return;
}
if (!processBuffer()) {
read();
}
read(); // Continue reading
}).catch(reject);
}
read(); // Start reading
read();
});
}
};
var contentType = response.headers.get("Content-Type") || "";
if (contentType.indexOf("text/event-stream") !== -1) {
return ParseMCPSSE(response, expectedId, onNotification);
}
return response.json();
}
class MCPClient {
constructor(url, sessionId, protocolVersion, customHeaders) {
this.url = url;
@@ -7425,7 +7434,6 @@ Current version indicated by LITEVER below.
//MCP Exposed functions
function MCPInit(url, customHeaders, onNotification) {
let mcp_tools = [];
const clientName = 'KoboldAI Lite MCP';
const clientVersion = '1.0.0';
var currentId = ++mcp_req_id;
@@ -7448,7 +7456,7 @@ Current version indicated by LITEVER below.
var sessionId = response.headers.get("MCP-Session-Id");
return ParseMCPResp(response, currentId, onNotification)
.then(function (result) {
var negotiatedVersion = (result.result && result.result.protocolVersion) ? result.result.protocolVersion : MCP_PROTOCOL_VER;
var negotiatedVersion = (result && result.result && result.result.protocolVersion) ? result.result.protocolVersion : MCP_PROTOCOL_VER;
var client = new MCPClient(url, sessionId, negotiatedVersion, customHeaders);
return client.notify("notifications/initialized").then(() => client);
}).catch(error => {
@@ -7462,6 +7470,7 @@ Current version indicated by LITEVER below.
{
return mcp_client.listTools().then(function (toolsResult) {
console.log(toolsResult);
let mcp_tools = [];
if(toolsResult && toolsResult.result && toolsResult.result.tools)
{
//convert to openai tools format
@@ -7605,6 +7614,11 @@ Current version indicated by LITEVER below.
}
servers[url] = { apikey: apiKey, tools:[] };
}
if(document.getElementById("kcpp_mcp_bridge").checked && is_using_kcpp_with_lcppui())
{
let url = apply_proxy_url(custom_kobold_endpoint + koboldcpp_mcp_endpoint);
servers[url] = { apikey: (custom_kobold_key!=""?custom_kobold_key:null), tools:[] };
}
return servers;
}
function Fetch_MCP_Tools() //connects to multiple mcp servers, updates the tool list
@@ -7621,7 +7635,7 @@ Current version indicated by LITEVER below.
{ 'Authorization': `Bearer ${urlsobj[url].apikey}` } : {};
let purl = url;
if(localsettings.corsproxy_mcp)
if(document.getElementById("corsproxy_mcp").checked) //localsettings.corsproxy_mcp not yet saved
{
purl = apply_proxy_url(url,true);
}
@@ -14570,6 +14584,7 @@ Current version indicated by LITEVER below.
document.getElementById("enable_tool_use").checked = localsettings.enable_tool_use;
document.getElementById("tools_auto_exec").checked = localsettings.tools_auto_exec;
document.getElementById("corsproxy_mcp").checked = localsettings.corsproxy_mcp;
document.getElementById("kcpp_mcp_bridge").checked = localsettings.kcpp_mcp_bridge;
document.getElementById("mcpurls").value = localsettings.saved_mcp_urls;
pending_cached_mcp_tools = JSON.parse(JSON.stringify(localsettings.cached_mcp_tools));
pending_disabled_mcp_tools = JSON.parse(JSON.stringify(localsettings.disabled_mcp_tools));
@@ -15344,7 +15359,8 @@ Current version indicated by LITEVER below.
localsettings.enable_tool_use = (document.getElementById("enable_tool_use").checked ? true : false);
localsettings.tools_auto_exec = (document.getElementById("tools_auto_exec").checked ? true : false);
localsettings.corsproxy_mcp = (document.getElementById("corsproxy_mcp").checked ? true : false);
localsettings.saved_mcp_urls = document.getElementById("mcpurls").value.trim()?document.getElementById("mcpurls").value.trim():default_mcp_base;
localsettings.kcpp_mcp_bridge = (document.getElementById("kcpp_mcp_bridge").checked ? true : false);
localsettings.saved_mcp_urls = document.getElementById("mcpurls").value.trim();
localsettings.cached_mcp_tools = JSON.parse(JSON.stringify(pending_cached_mcp_tools));
pending_disabled_mcp_tools = [];
for(key in localsettings.cached_mcp_tools)
@@ -15809,30 +15825,23 @@ Current version indicated by LITEVER below.
function display_newgame() {
mainmenu_untab(true);
document.getElementById("keep_ai_selected").checked = true;
document.getElementById("new_session_erase_memory").checked = localsettings.new_session_erase_memory;
document.getElementById("newgamecontainer").classList.remove("hidden");
if(localflag)
{
document.getElementById("keep_ai_selected_row").classList.add("hidden");
}else
{
document.getElementById("keep_ai_selected_row").classList.remove("hidden");
}
}
function confirm_newgame() {
if(!localflag && !document.getElementById("keep_ai_selected").checked)
{
selected_models = [];
selected_workers = [];
localsettings.opmode = 1;
}
localsettings.new_session_erase_memory = document.getElementById("new_session_erase_memory").checked;
hide_popups();
restart_new_game(true, document.getElementById("keep_memory").checked);
restart_new_game(true, !localsettings.new_session_erase_memory);
sync_multiplayer(true);
update_for_sidepanel();
hide_popups();
}
function cancel_newgame()
{
localsettings.new_session_erase_memory = document.getElementById("new_session_erase_memory").checked;
hide_popups();
}
function estimate_and_show_textDB_usage() {
let currentChunkSize = Number(document.getElementById("documentdb_chunksize").value);
@@ -16266,7 +16275,6 @@ Current version indicated by LITEVER below.
idle_timer = 0;
idle_triggered_counter = 0;
gametext_arr = [];
alt_gametext_branches = [];
redo_arr = [];
last_request_str = "No Requests Available";
last_response_obj = null;
@@ -16309,6 +16317,7 @@ Current version indicated by LITEVER below.
recentSearchQueries = [];
lastSearchResults = [];
toolcall_waiting_approve = null;
alt_gametext_branches = [];
if (!keep_memory)
{
personal_notes = "";
@@ -16350,7 +16359,6 @@ Current version indicated by LITEVER below.
restart_new_game();
display_settings();
confirm_settings();
document.getElementById("keep_memory").checked = false;
clear_bg_img();
pick_default_horde_models();
indexeddb_save("savedusermod","");
@@ -19170,7 +19178,7 @@ Current version indicated by LITEVER below.
}
submit_payload.messages.push(cturn);
}
if(determine_if_can_use_mcp() && localsettings.cached_mcp_tools && Object.keys(localsettings.cached_mcp_tools).length>0)
if(localsettings.enable_tool_use && determine_if_can_use_mcp() && localsettings.cached_mcp_tools && Object.keys(localsettings.cached_mcp_tools).length>0)
{
let senttools = MCPGetAllowedTools();
if(senttools.length>0)
@@ -19357,7 +19365,7 @@ Current version indicated by LITEVER below.
}
}
if(determine_if_can_use_mcp() && localsettings.cached_mcp_tools && Object.keys(localsettings.cached_mcp_tools).length>0)
if(localsettings.enable_tool_use && determine_if_can_use_mcp() && localsettings.cached_mcp_tools && Object.keys(localsettings.cached_mcp_tools).length>0)
{
let senttools = MCPGetAllowedTools();
if(senttools.length>0)
@@ -28445,7 +28453,11 @@ Current version indicated by LITEVER below.
class="helptext">Many public MCP servers restrict CORS, use this to proxy your requests. Uses external tools, please only use if necessary.</span></span></div>
<input title="Use CORS Proxy for MCP" type="checkbox" id="corsproxy_mcp" style="margin:0px 0px 0px auto;">
</div>
<div class="settinglabel">
<div class="justifyleft settingsmall">Include KoboldCpp MCP Bridge <span class="helpicon">?<span
class="helptext">If selected, attempts to connect to any MCP configured in KoboldCpp MCP bridge. Requires KoboldCpp.</span></span></div>
<input title="Include KoboldCpp MCP Bridge" type="checkbox" id="kcpp_mcp_bridge" style="margin:0px 0px 0px auto;">
</div>
<div class="settinglabel">
<div class="justifyleft settingsmall">MCP Server URLs <span class="helpicon">?<span
class="helptext">Connect to local or remote MCP servers to use tools there. One URL per row, optional API keys separated by commas. Caution: MCP API keys are stored in plaintext in saves!</span></span></div>
@@ -28454,6 +28466,7 @@ Current version indicated by LITEVER below.
<button type="button" id="connect_mcp_btn" class="btn btn-primary" style="width:80px; padding:2px 3px;font-size:12px; margin: 0px 0px 0px 3px;" onclick="Fetch_MCP_Tools()">Connect All</button>
</div>
<div class="color_red hidden" id="nomcp">MCP Toolcalling unavailable, requires chat completions.</div>
<div id="tools_list_container" class="tools_list_container">
@@ -29204,7 +29217,7 @@ Current version indicated by LITEVER below.
<option value="google/gemma-3-27b-it">google/gemma-3-27b-it</option>
<option value="meta/llama-3.3-70b-instruct">meta/llama-3.3-70b-instruct</option>
<option value="mistralai/mistral-large">mistralai/mistral-large</option>
<option value="moonshotai/kimi-k2-instruct" selected>moonshotai/kimi-k2-instruct</option>
<option value="moonshotai/kimi-k2-instruct-0905" selected>moonshotai/kimi-k2-instruct-0905</option>
<option value="nvidia/llama-3.3-nemotron-super-49b-v1">nvidia/llama-3.3-nemotron-super-49b-v1</option>
<option value="qwen/qwen3-235b-a22b">qwen/qwen3-235b-a22b</option>
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
@@ -29440,13 +29453,9 @@ Current version indicated by LITEVER below.
Unsaved data will be lost.<br><br>
<div>
<div style="vertical-align: middle;">
<div id="keep_ai_selected_row" title="If disabled, brings you back to the start page">
<span>Keep AI Selected? </span>
<input type="checkbox" id="keep_ai_selected" style=" vertical-align: top;" checked>
</div>
<div>
<span>Keep Memory and World Info? </span>
<input type="checkbox" id="keep_memory" style=" vertical-align: top;">
<span class="color_red">Also Reset Memory and World Info? </span>
<input type="checkbox" id="new_session_erase_memory" style="vertical-align: top;">
</div>
</div>
</div>
@@ -29454,7 +29463,7 @@ Current version indicated by LITEVER below.
</div>
<div class="popupfooter">
<button type="button" class="btn btn-primary" onclick="confirm_newgame()">Ok</button>
<button type="button" class="btn btn-primary" onclick="hide_popups()">Cancel</button>
<button type="button" class="btn btn-primary" onclick="cancel_newgame()">Cancel</button>
</div>
</div>
</div>