VirtualKimi commited on
Commit
64bd9f9
·
verified ·
1 Parent(s): cd34b78

Upload kimi-script.js

Browse files
Files changed (1) hide show
  1. kimi-js/kimi-script.js +30 -1
kimi-js/kimi-script.js CHANGED
@@ -179,6 +179,17 @@ document.addEventListener("DOMContentLoaded", async function () {
179
  // Hydrate API config UI from DB after ApiUi is defined and function declared
180
  initializeApiConfigUI();
181
 
 
 
 
 
 
 
 
 
 
 
 
182
  const providerSelectEl = document.getElementById("llm-provider");
183
  if (providerSelectEl) {
184
  providerSelectEl.addEventListener("change", async function (e) {
@@ -232,7 +243,8 @@ document.addEventListener("DOMContentLoaded", async function () {
232
  if (apiKeyInput) apiKeyInput.placeholder = p.keyPh;
233
  if (modelIdInput) {
234
  modelIdInput.placeholder = p.model;
235
- // Value only for OpenRouter; others cleared to encourage provider-specific model naming
 
236
  modelIdInput.value = provider === "openrouter" && window.kimiLLM ? window.kimiLLM.currentModel : "";
237
  }
238
  if (window.kimiDB) {
@@ -264,6 +276,23 @@ document.addEventListener("DOMContentLoaded", async function () {
264
  ApiUi.clearStatus();
265
  }
266
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
268
 
269
  const loadingScreen = document.getElementById("loading-screen");
 
179
  // Hydrate API config UI from DB after ApiUi is defined and function declared
180
  initializeApiConfigUI();
181
 
182
+ // Listen for model changes and update the UI only for OpenRouter
183
+ window.addEventListener("llmModelChanged", function (event) {
184
+ const modelIdInput = ApiUi.modelIdInput();
185
+ const providerSelect = ApiUi.providerSelect();
186
+
187
+ // Only update the field if current provider is OpenRouter
188
+ if (modelIdInput && event.detail && event.detail.id && providerSelect && providerSelect.value === "openrouter") {
189
+ modelIdInput.value = event.detail.id;
190
+ }
191
+ });
192
+
193
  const providerSelectEl = document.getElementById("llm-provider");
194
  if (providerSelectEl) {
195
  providerSelectEl.addEventListener("change", async function (e) {
 
243
  if (apiKeyInput) apiKeyInput.placeholder = p.keyPh;
244
  if (modelIdInput) {
245
  modelIdInput.placeholder = p.model;
246
+ // Only populate the field for OpenRouter since those are the models we have in the list
247
+ // For other providers, user must manually enter the provider-specific model ID
248
  modelIdInput.value = provider === "openrouter" && window.kimiLLM ? window.kimiLLM.currentModel : "";
249
  }
250
  if (window.kimiDB) {
 
276
  ApiUi.clearStatus();
277
  }
278
  });
279
+
280
+ // Listen for model ID changes and update the current model
281
+ const modelIdInput = ApiUi.modelIdInput();
282
+ if (modelIdInput) {
283
+ modelIdInput.addEventListener("blur", async function (e) {
284
+ const newModelId = e.target.value.trim();
285
+ if (newModelId && window.kimiLLM && newModelId !== window.kimiLLM.currentModel) {
286
+ try {
287
+ await window.kimiLLM.setCurrentModel(newModelId);
288
+ } catch (error) {
289
+ console.warn("Failed to set model:", error.message);
290
+ // Reset to current model if setting failed
291
+ e.target.value = window.kimiLLM.currentModel || "";
292
+ }
293
+ }
294
+ });
295
+ }
296
  }
297
 
298
  const loadingScreen = document.getElementById("loading-screen");