mirror of
https://github.com/open-webui/assistant
synced 2025-05-13 16:30:35 +00:00
feat: config versioning
This commit is contained in:
parent
4e31e7c468
commit
94866399f8
13
src/App.vue
13
src/App.vue
@ -64,7 +64,7 @@ onBeforeMount(async () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class=" h-screen w-screen p-3 flex justify-center">
|
<div class=" h-screen w-screen p-3 flex justify-center">
|
||||||
<div class=" my-auto w-full flex flex-col gap-2">
|
<form class=" my-auto w-full flex flex-col gap-2" @submit.prevent="saveHandler">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<div class=" text-sm font-semibold">Open WebUI Assistant</div>
|
<div class=" text-sm font-semibold">Open WebUI Assistant</div>
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ onBeforeMount(async () => {
|
|||||||
<div v-else>
|
<div v-else>
|
||||||
<button
|
<button
|
||||||
class="bg-neutral-700 hover:bg-neutral-800 transition text-white text-xs px-3 py-1 rounded-lg"
|
class="bg-neutral-700 hover:bg-neutral-800 transition text-white text-xs px-3 py-1 rounded-lg"
|
||||||
@click="saveHandler">Connect</button>
|
type="submit">Connect</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -87,10 +87,10 @@ onBeforeMount(async () => {
|
|||||||
|
|
||||||
<input v-model="url"
|
<input v-model="url"
|
||||||
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
||||||
placeholder="Open WebUI URL" :disabled='connected' />
|
placeholder="Open WebUI URL" :disabled='connected' required />
|
||||||
<input v-model="token"
|
<input v-model="token"
|
||||||
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
||||||
placeholder="Open WebUI Token" :disabled='connected' />
|
placeholder="Open WebUI Token" :disabled='connected' required />
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
@ -103,7 +103,8 @@ onBeforeMount(async () => {
|
|||||||
<option v-for="model in models" v-bind:value="model.name">{{ model.name }}</option>
|
<option v-for="model in models" v-bind:value="model.name">{{ model.name }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<button class="p-1 bg-gray-100 hover:bg-gray-200 transition rounded-lg" @click="selectModelHandler">
|
<button class="p-1 bg-gray-100 hover:bg-gray-200 transition rounded-lg" type="button"
|
||||||
|
@click="selectModelHandler">
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||||
<path fill-rule="evenodd"
|
<path fill-rule="evenodd"
|
||||||
@ -118,7 +119,7 @@ onBeforeMount(async () => {
|
|||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
34
src/main.ts
34
src/main.ts
@ -15,6 +15,8 @@ import { default as fs } from "fs";
|
|||||||
|
|
||||||
keyboard.config.autoDelayMs = 0;
|
keyboard.config.autoDelayMs = 0;
|
||||||
|
|
||||||
|
const configPath = app.getPath("userData") + "/config.json";
|
||||||
|
|
||||||
let WEBUI_VERSION: string | null = null;
|
let WEBUI_VERSION: string | null = null;
|
||||||
let models: object[] = [];
|
let models: object[] = [];
|
||||||
|
|
||||||
@ -235,7 +237,7 @@ const selectModel = async (modelId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadConfig = async () => {
|
const loadConfig = async () => {
|
||||||
fs.readFile("config.json", "utf8", (err, data) => {
|
fs.readFile(configPath, "utf8", (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Error reading config file:", err);
|
console.error("Error reading config file:", err);
|
||||||
return;
|
return;
|
||||||
@ -248,16 +250,24 @@ const loadConfig = async () => {
|
|||||||
// Do something with the config object
|
// Do something with the config object
|
||||||
console.log("Config:", _config);
|
console.log("Config:", _config);
|
||||||
|
|
||||||
if (_config.url) {
|
if (_config.version === 1) {
|
||||||
config.url = _config.url;
|
console.log("Config loaded successfully:", config);
|
||||||
}
|
// Use the loaded configuration
|
||||||
|
|
||||||
if (_config.token) {
|
if (_config.url) {
|
||||||
config.token = _config.token;
|
config.url = _config.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_config.model) {
|
if (_config.token) {
|
||||||
selectedModel = _config.model;
|
config.token = _config.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_config.model) {
|
||||||
|
selectedModel = _config.model;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error("Incompatible configuration version.");
|
||||||
|
// Handle incompatible version gracefully
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error parsing JSON:", error);
|
console.error("Error parsing JSON:", error);
|
||||||
@ -267,8 +277,9 @@ const loadConfig = async () => {
|
|||||||
|
|
||||||
const saveConfigToFile = async () => {
|
const saveConfigToFile = async () => {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
"config.json",
|
configPath,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
version: 1,
|
||||||
...config,
|
...config,
|
||||||
model: selectModel,
|
model: selectModel,
|
||||||
})
|
})
|
||||||
@ -282,6 +293,9 @@ app
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
console.log(process.cwd());
|
||||||
|
console.log(app.getPath("userData"));
|
||||||
|
|
||||||
ipcMain.handle("check-connection", async (event, arg) => {
|
ipcMain.handle("check-connection", async (event, arg) => {
|
||||||
await getVersion();
|
await getVersion();
|
||||||
return WEBUI_VERSION !== null;
|
return WEBUI_VERSION !== null;
|
||||||
|
Loading…
Reference in New Issue
Block a user