@7n/tauri-components 0.3.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/core/dispatch.js +5 -1
- package/src/vue/use-agent.js +3 -2
- package/src/vue/use-omlx.js +35 -6
package/package.json
CHANGED
package/src/core/dispatch.js
CHANGED
|
@@ -44,7 +44,11 @@ export function createDispatch(catalog, transport) {
|
|
|
44
44
|
return { ok: true, output }
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
|
-
|
|
47
|
+
const envelope = { code: 'io', message: String(error?.message ?? error) }
|
|
48
|
+
// Preserve a backend-provided error kind (e.g. a typed Tauri command error)
|
|
49
|
+
// so callers can branch on it — e.g. re-auth on a 'ReauthRequired' kind.
|
|
50
|
+
if (error?.kind !== undefined) envelope.kind = error.kind
|
|
51
|
+
return { ok: false, error: envelope }
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
}
|
package/src/vue/use-agent.js
CHANGED
|
@@ -23,12 +23,13 @@ const DEFAULT_ACTOR = { kind: 'human', id: 'local' }
|
|
|
23
23
|
* @param {Record<string, number>} [config.actorTiers] tier overrides
|
|
24
24
|
* @param {{ kind: string, id: string }} [config.actor] caller identity (default human:local)
|
|
25
25
|
* @param {{ storagePrefix?: string, defaultBaseUrl?: string, defaultModel?: string }} [config.omlx] omlx config options
|
|
26
|
+
* @param {(tool: object, input: object) => unknown} [config.transport] tool transport (default Tauri invoke); override to route some tools elsewhere (e.g. JS/OPFS-backed handlers)
|
|
26
27
|
* @returns {object} in-app agent gateway
|
|
27
28
|
*/
|
|
28
|
-
export function useAgent({ catalog, systemPrompt, grounding, actorTiers, actor = DEFAULT_ACTOR, omlx } = {}) {
|
|
29
|
+
export function useAgent({ catalog, systemPrompt, grounding, actorTiers, actor = DEFAULT_ACTOR, omlx, transport = tauriTransport } = {}) {
|
|
29
30
|
const { baseUrl, model, apiKey, save, loadEnv } = useOmlx(omlx)
|
|
30
31
|
const journal = createTauriJournalStore()
|
|
31
|
-
const kit = createAgentKit({ catalog, systemPrompt, transport
|
|
32
|
+
const kit = createAgentKit({ catalog, systemPrompt, transport, journal, actorTiers, grounding })
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Build an omlx chat fn from the current config (tauri-http transport).
|
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 }
|