feat: fetch APInex models from main thread, populate default-model dropdown (networkAccess added)
This commit is contained in:
1 parent
1468570d0f
commit
ce5aa025aa
3 files changed
+64
-2
No files matched your search
+25
@@ -502,6 +502,31 @@ export default function () {
|
||||
})
|
||||
})
|
||||
|
||||
// UI asks to list models for a provider. Network must run here (main thread) —
|
||||
// the plugin UI iframe is CSP-sandboxed and cannot fetch external URLs.
|
||||
on('FETCH_MODELS', async function (payload: { baseUrl: string, apiKey: string }) {
|
||||
try {
|
||||
const base = payload.baseUrl.replace(/\/+$/, '')
|
||||
const res = await fetch(base + '/models', {
|
||||
headers: { Authorization: 'Bearer ' + payload.apiKey }
|
||||
})
|
||||
if (!res.ok) {
|
||||
emit('MODELS_RESULT', { ok: false, error: 'HTTP ' + res.status, models: [] })
|
||||
return
|
||||
}
|
||||
const json: any = await res.json()
|
||||
let models: string[] = []
|
||||
if (Array.isArray(json.data)) {
|
||||
models = json.data.map((m: any) => m.id).filter((x: any) => typeof x === 'string' && x.length > 0)
|
||||
} else if (Array.isArray(json.models)) {
|
||||
models = json.models.map((m: any) => m.id || m).filter((x: any) => typeof x === 'string')
|
||||
}
|
||||
emit('MODELS_RESULT', { ok: true, models })
|
||||
} catch (e) {
|
||||
emit('MODELS_RESULT', { ok: false, error: String(e), models: [] })
|
||||
}
|
||||
})
|
||||
|
||||
showUI({ width: 320, height: 200, themeColors: true, title: 'AI assistant (MVP)' })
|
||||
|
||||
// Restore persisted window placement (saved in clientStorage on the Figma file).
|
||||
|
||||
Reference in new issue
Block a user