@7n/tauri-components 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/vue/use-omlx.js +35 -6
package/package.json
CHANGED
package/src/vue/use-omlx.js
CHANGED
|
@@ -14,6 +14,35 @@ import { invoke } from '@tauri-apps/api/core'
|
|
|
14
14
|
|
|
15
15
|
const DEFAULT_BASE_URL = 'http://127.0.0.1:8000/v1'
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Read a localStorage value, or null when localStorage is unavailable
|
|
19
|
+
* (component tests without a DOM store, SSR).
|
|
20
|
+
* @param {string} key storage key
|
|
21
|
+
* @returns {string|null} stored value, or null
|
|
22
|
+
*/
|
|
23
|
+
function readStored(key) {
|
|
24
|
+
try {
|
|
25
|
+
return globalThis.localStorage?.getItem(key) ?? null
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Write a localStorage value; no-op when localStorage is unavailable.
|
|
34
|
+
* @param {string} key storage key
|
|
35
|
+
* @param {string} value value to store
|
|
36
|
+
*/
|
|
37
|
+
function writeStored(key, value) {
|
|
38
|
+
try {
|
|
39
|
+
globalThis.localStorage?.setItem(key, value)
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// no localStorage (tests / SSR) — in-memory ref state is still updated
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
17
46
|
/**
|
|
18
47
|
* @param {{ storagePrefix?: string, defaultBaseUrl?: string, defaultModel?: string }} [options] config
|
|
19
48
|
* @returns {{ baseUrl: import('vue').Ref<string>, model: import('vue').Ref<string>, apiKey: import('vue').Ref<string>, save: () => void, loadEnv: () => Promise<void> }} persisted omlx config, an env loader and a saver
|
|
@@ -22,8 +51,8 @@ export function useOmlx({ storagePrefix = 'agent', defaultBaseUrl = DEFAULT_BASE
|
|
|
22
51
|
const baseUrlKey = `${storagePrefix}:omlxBaseUrl`
|
|
23
52
|
const modelKey = `${storagePrefix}:omlxModel`
|
|
24
53
|
|
|
25
|
-
const baseUrl = ref(
|
|
26
|
-
const model = ref(
|
|
54
|
+
const baseUrl = ref(readStored(baseUrlKey) || defaultBaseUrl)
|
|
55
|
+
const model = ref(readStored(modelKey) || defaultModel)
|
|
27
56
|
// Filled from the global env in loadEnv(); never persisted to localStorage.
|
|
28
57
|
const apiKey = ref('')
|
|
29
58
|
|
|
@@ -43,8 +72,8 @@ export function useOmlx({ storagePrefix = 'agent', defaultBaseUrl = DEFAULT_BASE
|
|
|
43
72
|
}
|
|
44
73
|
if (!env) return
|
|
45
74
|
if (env.apiKey) apiKey.value = env.apiKey
|
|
46
|
-
if (env.baseUrl && !
|
|
47
|
-
if (env.model && !
|
|
75
|
+
if (env.baseUrl && !readStored(baseUrlKey)) baseUrl.value = env.baseUrl
|
|
76
|
+
if (env.model && !readStored(modelKey)) model.value = env.model
|
|
48
77
|
}
|
|
49
78
|
|
|
50
79
|
/**
|
|
@@ -52,8 +81,8 @@ export function useOmlx({ storagePrefix = 'agent', defaultBaseUrl = DEFAULT_BASE
|
|
|
52
81
|
* persisted — it comes from the global OMLX_API_KEY env on each launch.
|
|
53
82
|
*/
|
|
54
83
|
function save() {
|
|
55
|
-
|
|
56
|
-
|
|
84
|
+
writeStored(baseUrlKey, baseUrl.value)
|
|
85
|
+
writeStored(modelKey, model.value)
|
|
57
86
|
}
|
|
58
87
|
|
|
59
88
|
return { baseUrl, model, apiKey, save, loadEnv }
|