up
This commit is contained in:
@@ -64,14 +64,22 @@
|
||||
<tr class="hover:bg-gray-50 transition">
|
||||
<td class="py-2 px-3 font-medium" x-text="item.nombre"></td>
|
||||
<td class="py-2 px-3">
|
||||
<span class="px-2 py-0.5 rounded-full text-xs font-semibold"
|
||||
:class="{
|
||||
'bg-blue-100 text-blue-700': item.modulo === 'landing',
|
||||
'bg-[#e9f0cf] text-[#5a7a1e]': item.modulo === 'query_runner',
|
||||
'bg-gray-100 text-gray-500': !item.modulo
|
||||
}"
|
||||
x-text="item.modulo === 'landing' ? 'Landing' : item.modulo === 'query_runner' ? 'Query Runner' : 'Global'">
|
||||
</span>
|
||||
<template x-if="!item.modulo">
|
||||
<span class="px-2 py-0.5 rounded-full text-xs font-semibold bg-gray-100 text-gray-500">Global</span>
|
||||
</template>
|
||||
<template x-if="item.modulo">
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<template x-for="m in item.modulo.split(',').filter(x => x.trim())" :key="m">
|
||||
<span class="px-2 py-0.5 rounded-full text-xs font-semibold"
|
||||
:class="{
|
||||
'bg-blue-100 text-blue-700': m.trim() === 'landing',
|
||||
'bg-[#e9f0cf] text-[#5a7a1e]': m.trim() === 'query_runner'
|
||||
}"
|
||||
x-text="m.trim() === 'landing' ? 'Landing' : m.trim() === 'query_runner' ? 'Query Runner' : m.trim()">
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
<td class="py-2 px-3">
|
||||
<span class="px-2 py-0.5 rounded-full text-xs font-semibold"
|
||||
@@ -174,15 +182,29 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">Módulo / Servicio</label>
|
||||
<select x-model="form.modulo"
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-[#8eb02f]">
|
||||
<option value="">Global (usado por todos como fallback)</option>
|
||||
<option value="landing">Landing Generator</option>
|
||||
<option value="query_runner">Query Runner SQL</option>
|
||||
</select>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-2">Módulo / Servicio</label>
|
||||
<div class="border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50">
|
||||
<label class="flex items-center gap-2 cursor-pointer select-none">
|
||||
<input type="checkbox"
|
||||
:checked="form.modulos.length === 0"
|
||||
@change="form.modulos = []"
|
||||
class="rounded text-[#8eb02f] focus:ring-[#8eb02f]">
|
||||
<span class="text-sm text-gray-700">Global</span>
|
||||
<span class="text-[10px] text-gray-400 ml-1">— fallback para todos los servicios</span>
|
||||
</label>
|
||||
<template x-for="opt in moduleOptions" :key="opt.value">
|
||||
<label class="flex items-center gap-2 cursor-pointer select-none">
|
||||
<input type="checkbox"
|
||||
:value="opt.value"
|
||||
:checked="form.modulos.includes(opt.value)"
|
||||
@change="toggleModulo(opt.value)"
|
||||
class="rounded text-[#8eb02f] focus:ring-[#8eb02f]">
|
||||
<span class="text-sm text-gray-700" x-text="opt.label"></span>
|
||||
</label>
|
||||
</template>
|
||||
</div>
|
||||
<p class="text-[10px] text-gray-400 mt-1">
|
||||
Asigna esta IA a un servicio específico. "Global" actúa de fallback cuando un servicio no tiene IA propia.
|
||||
"Global" actúa de fallback. Si seleccionas servicios específicos, solo se usará para ellos.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -231,7 +253,12 @@ function aiConfigApp() {
|
||||
search: '',
|
||||
showModal: false, editItem: null, deleteId: null,
|
||||
errorMsg: '', successMsg: '', formError: '',
|
||||
form: { nombre: '', provider: '', api_key: '', base_url: '', model_name: '', is_active: true, notes: '', modulo: '' },
|
||||
form: { nombre: '', provider: '', api_key: '', base_url: '', model_name: '', is_active: true, notes: '', modulos: [] },
|
||||
|
||||
moduleOptions: [
|
||||
{ value: 'landing', label: 'Landing Generator' },
|
||||
{ value: 'query_runner', label: 'Query Runner SQL' },
|
||||
],
|
||||
|
||||
async init() { await this.load() },
|
||||
|
||||
@@ -249,16 +276,28 @@ function aiConfigApp() {
|
||||
|
||||
goPage(p) { this.page = p; this.load() },
|
||||
|
||||
toggleModulo(value) {
|
||||
const idx = this.form.modulos.indexOf(value)
|
||||
if (idx >= 0) {
|
||||
this.form.modulos.splice(idx, 1)
|
||||
} else {
|
||||
this.form.modulos.push(value)
|
||||
}
|
||||
},
|
||||
|
||||
openAdd() {
|
||||
this.editItem = null
|
||||
this.form = { nombre: '', provider: 'qwen', api_key: '', base_url: '', model_name: 'qwen2.5-72b-instruct', is_active: true, notes: '', modulo: '' }
|
||||
this.form = { nombre: '', provider: 'qwen', api_key: '', base_url: '', model_name: 'qwen2.5-72b-instruct', is_active: true, notes: '', modulos: [] }
|
||||
this.formError = ''
|
||||
this.showModal = true
|
||||
},
|
||||
|
||||
openEdit(item) {
|
||||
this.editItem = item
|
||||
this.form = { nombre: item.nombre, provider: item.provider, api_key: '', base_url: item.base_url, model_name: item.model_name, is_active: item.is_active, notes: item.notes, modulo: item.modulo || '' }
|
||||
const modulos = item.modulo
|
||||
? item.modulo.split(',').map(s => s.trim()).filter(s => s)
|
||||
: []
|
||||
this.form = { nombre: item.nombre, provider: item.provider, api_key: '', base_url: item.base_url, model_name: item.model_name, is_active: item.is_active, notes: item.notes, modulos }
|
||||
this.formError = ''
|
||||
this.showModal = true
|
||||
},
|
||||
@@ -267,9 +306,11 @@ function aiConfigApp() {
|
||||
|
||||
async save() {
|
||||
this.saving = true; this.formError = ''
|
||||
const payload = { ...this.form, modulo: this.form.modulos.join(',') }
|
||||
delete payload.modulos
|
||||
const url = this.editItem ? `/app/ai-config/${this.editItem.ID}` : '/app/ai-config'
|
||||
const method = this.editItem ? 'PUT' : 'POST'
|
||||
const res = await fetch(url, { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(this.form) })
|
||||
const res = await fetch(url, { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) })
|
||||
const data = await res.json()
|
||||
this.saving = false
|
||||
if (!res.ok) { this.formError = data.error || 'Error guardando'; return }
|
||||
|
||||
Reference in New Issue
Block a user