@johpaz/hive-agents 1.1.6 → 1.1.11
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/README.md +4 -10
- package/dist/hive.js +5258 -2985
- package/dist/tool-worker.js +197 -75
- package/dist/ui/assets/{A2UIPage-CxE3jH4_.js → A2UIPage-v-VggXW3.js} +4 -4
- package/dist/ui/assets/{AgentCreateForm-SGj5AqAX.js → AgentCreateForm-Dr1l4Cvg.js} +1 -1
- package/dist/ui/assets/AgentDetailPage-Dsh_grrr.js +1 -0
- package/dist/ui/assets/{AgentNewPage-xvAmX6kw.js → AgentNewPage-D7557C0J.js} +1 -1
- package/dist/ui/assets/AgentsPage-C_Z56LL1.js +10 -0
- package/dist/ui/assets/{ApiClientPage-NLw2wHjH.js → ApiClientPage-uuBnrh0y.js} +1 -1
- package/dist/ui/assets/ChannelsPage-BI4mAgRU.js +8 -0
- package/dist/ui/assets/DashboardPage-BjAxvzYP.js +6 -0
- package/dist/ui/assets/LoginPage-D7IZKON0.js +1 -0
- package/dist/ui/assets/{LogsPage-G9d2G1nL.js → LogsPage-mcqOYvGw.js} +1 -1
- package/dist/ui/assets/MeetingPage-qPJ1z5HA.js +1 -0
- package/dist/ui/assets/ModelSelector-njfNhkng.js +1 -0
- package/dist/ui/assets/{NotFound-D4ZlDVg9.js → NotFound-DY8e1RKh.js} +1 -1
- package/dist/ui/assets/{Office3DPage-31AMJ-LN.css → Office3DPage-C3SIzd2H.css} +1 -1
- package/dist/ui/assets/Office3DPage-Du42LRwi.js +319 -0
- package/dist/ui/assets/ProvidersPage-GDCJs8Zb.js +1 -0
- package/dist/ui/assets/{RecoverPage-Dr6qKgV5.js → RecoverPage-B6qvBBIl.js} +1 -1
- package/dist/ui/assets/SettingsPage-Br4PfWuc.js +9 -0
- package/dist/ui/assets/{SetupPage-BoVKIf4r.js → SetupPage-OaouFLGD.js} +1 -1
- package/dist/ui/assets/{Vignette-DrI2yK2m.js → Vignette-GSZ-owcN.js} +17 -17
- package/dist/ui/assets/VoicePage-DRQZBl3j.js +307 -0
- package/dist/ui/assets/WebChatPage-Cypq-SYi.js +29 -0
- package/dist/ui/assets/{agentCapabilities-CDSfJWhw.js → agentCapabilities-Bf71Gir4.js} +1 -1
- package/dist/ui/assets/{alert-CjiX20jI.js → alert-Dn604uVs.js} +1 -1
- package/dist/ui/assets/{badge-B5AKge1b.js → badge-C6H33ePv.js} +1 -1
- package/dist/ui/assets/{card-mTJ4oZbL.js → card-D0qneq1i.js} +1 -1
- package/dist/ui/assets/{conversationsStore-ns_ZfKgg.js → conversationsStore-D6XgjMr1.js} +1 -1
- package/dist/ui/assets/{dialog-C3n2xYF2.js → dialog-DO1fQCF7.js} +1 -1
- package/dist/ui/assets/dist-js-C2MfmbEW.js +1 -0
- package/dist/ui/assets/{dist-js-CkNhvsFc.js → dist-js-Djxbxbst.js} +1 -1
- package/dist/ui/assets/google-external-e9lvWjy4.js +1 -0
- package/dist/ui/assets/index-BKNFH2al.css +2 -0
- package/dist/ui/assets/index-U0e4e5mL.js +156 -0
- package/dist/ui/assets/{key-DPkOY-J0.js → key-round-Ca0Ns34v.js} +1 -1
- package/dist/ui/assets/{label-D_fvqJyD.js → label-CvAtVE-v.js} +1 -1
- package/dist/ui/assets/{scroll-area-CbH8FOo8.js → scroll-area-CYMu7sU0.js} +1 -1
- package/dist/ui/assets/select-BjBXxyxL.js +1 -0
- package/dist/ui/assets/{slider-DXS4h1LB.js → slider-DR31eN3r.js} +1 -1
- package/dist/ui/assets/{switch-ndx8VCpm.js → switch-B5dAwb54.js} +1 -1
- package/dist/ui/assets/{tabs-epu-3Tl4.js → tabs-Ct92cLXr.js} +1 -1
- package/dist/ui/assets/{earth-BJRGJbVn.js → terminal-CpBDERBE.js} +1 -1
- package/dist/ui/assets/{textarea-BgZJFZTX.js → textarea-xtFAVuPf.js} +1 -1
- package/dist/ui/assets/{useAudioDevices-CsPrtpWY.js → useAudioDevices-wZArmV3m.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-nn4gON9g.js → useHiveAgentsModelLoad-CqJkzTOT.js} +1 -1
- package/dist/ui/assets/useOfficeModel-DZvwZRCw.js +1 -0
- package/dist/ui/assets/{useProviders-9tvEC3hX.js → useProviders-CeSzDnx-.js} +1 -1
- package/dist/ui/assets/vendor-router-DxU0Uf4R.js +3 -0
- package/dist/ui/index.html +5 -5
- package/package.json +1 -3
- package/packages/core/src/agent/agent-catalog.ts +98 -1
- package/packages/core/src/agent/agent-loop.ts +5 -44
- package/packages/core/src/agent/context-compiler.ts +6 -94
- package/packages/core/src/agent/conversation-store.ts +23 -1
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
- package/packages/core/src/agent/prompt-builder.ts +17 -1
- package/packages/core/src/agent/tool-selector.ts +8 -0
- package/packages/core/src/artifacts/store.ts +66 -8
- package/packages/core/src/canvas/emitter.ts +0 -19
- package/packages/core/src/gateway/google-host.ts +228 -0
- package/packages/core/src/gateway/initializer.ts +8 -0
- package/packages/core/src/gateway/routes/agents.ts +14 -0
- package/packages/core/src/gateway/routes/auth.ts +25 -3
- package/packages/core/src/gateway/routes/chat.ts +14 -1
- package/packages/core/src/gateway/routes/google.ts +252 -0
- package/packages/core/src/gateway/routes/meeting.ts +11 -3
- package/packages/core/src/gateway/routes/models.ts +27 -11
- package/packages/core/src/gateway/routes/multimodal.ts +19 -0
- package/packages/core/src/gateway/routes/providers.ts +19 -18
- package/packages/core/src/gateway/routes/system.ts +1 -3
- package/packages/core/src/gateway/routes/tts-local.ts +20 -374
- package/packages/core/src/gateway/routes/voice.ts +29 -35
- package/packages/core/src/gateway/server.ts +58 -32
- package/packages/core/src/gateway/tts/README.md +7 -86
- package/packages/core/src/gateway/tts/build.py +105 -0
- package/packages/core/src/gateway/tts/kitten.ts +282 -0
- package/packages/core/src/gateway/tts/python.d.ts +4 -0
- package/packages/core/src/gateway/tts/src/detect.ts +33 -39
- package/packages/core/src/gateway/tts/worker.py +80 -0
- package/packages/core/src/google/client.ts +123 -0
- package/packages/core/src/google/config.ts +60 -0
- package/packages/core/src/google/google.test.ts +287 -0
- package/packages/core/src/google/index.ts +5 -0
- package/packages/core/src/google/oauth.ts +144 -0
- package/packages/core/src/google/scopes.ts +41 -0
- package/packages/core/src/google/token-store.ts +33 -0
- package/packages/core/src/multimodal/attachment-ingest.ts +19 -4
- package/packages/core/src/multimodal/image-generation.ts +244 -0
- package/packages/core/src/storage/collections.ts +8 -8
- package/packages/core/src/storage/google-capabilities.ts +91 -0
- package/packages/core/src/storage/model-activation.ts +18 -0
- package/packages/core/src/storage/model-sync.ts +66 -14
- package/packages/core/src/storage/onboarding.ts +10 -2
- package/packages/core/src/storage/seed.ts +81 -18
- package/packages/core/src/storage/usage.ts +0 -52
- package/packages/core/src/tools/agents/get-available-models.ts +1 -3
- package/packages/core/src/tools/core/index.ts +1 -1
- package/packages/core/src/tools/google/calendar.ts +204 -0
- package/packages/core/src/tools/google/drive.ts +160 -0
- package/packages/core/src/tools/google/gmail.ts +579 -0
- package/packages/core/src/tools/google/index.ts +18 -0
- package/packages/core/src/tools/google/shared.ts +80 -0
- package/packages/core/src/tools/image/image-generate.ts +90 -0
- package/packages/core/src/tools/image/index.ts +13 -0
- package/packages/core/src/tools/image/office-leer-imagenes.ts +198 -0
- package/packages/core/src/tools/index.ts +27 -0
- package/packages/core/src/tools/office/office-images.ts +137 -0
- package/packages/core/src/tools/office/office-leer-docx.ts +10 -1
- package/packages/core/src/tools/office/office-leer-pdf.ts +1 -1
- package/packages/core/src/tools/office/office-leer-pptx.ts +4 -1
- package/packages/core/src/tools/office/office-pdf-images.ts +225 -0
- package/packages/core/src/tools/office/pdf-text.ts +2 -2
- package/packages/core/src/tools/web/browser-screenshot.ts +7 -0
- package/packages/core/src/voice/index.ts +123 -155
- package/packages/core/src/voice/local-model.ts +8 -0
- package/packages/core/src/voice/stt-models.ts +39 -0
- package/packages/skills/src/bundled/google/google_calendar/SKILL.md +51 -0
- package/packages/skills/src/bundled/google/google_drive/SKILL.md +50 -0
- package/packages/skills/src/bundled/google/google_gmail/SKILL.md +61 -0
- package/packages/skills/src/bundled-data.generated.ts +45 -0
- package/dist/ui/assets/AgentDetailPage-CyYbqzHr.js +0 -1
- package/dist/ui/assets/AgentsPage-CEWNs4Lt.js +0 -10
- package/dist/ui/assets/ChannelsPage-CmeXP-hI.js +0 -8
- package/dist/ui/assets/DashboardPage-C3z4kZXD.js +0 -6
- package/dist/ui/assets/LoginPage-DDisP8hm.js +0 -1
- package/dist/ui/assets/MeetingPage-CKyjxtFr.js +0 -1
- package/dist/ui/assets/ModelSelector-VVwpDrYF.js +0 -1
- package/dist/ui/assets/Office3DPage-CYxB6z2p.js +0 -727
- package/dist/ui/assets/ProvidersPage-CM9-E-Pf.js +0 -1
- package/dist/ui/assets/SettingsPage-BvD-vs5g.js +0 -9
- package/dist/ui/assets/VoicePage-CmudxYny.js +0 -307
- package/dist/ui/assets/WebChatPage-CnoXpEOl.js +0 -29
- package/dist/ui/assets/dist-js-jWCEHSkB.js +0 -1
- package/dist/ui/assets/index-C0W6p0lk.js +0 -156
- package/dist/ui/assets/index-DmFPF9xQ.css +0 -2
- package/dist/ui/assets/lock-open-v0EphssG.js +0 -1
- package/dist/ui/assets/select-v_3QBYrD.js +0 -1
- package/dist/ui/assets/terminal-BEcTK780.js +0 -1
- package/dist/ui/assets/useOfficeModel-BaDn7U-X.js +0 -1
- package/dist/ui/assets/vendor-router-DSMCk-Ka.js +0 -3
- package/packages/core/src/agent/jev-decisions.ts +0 -242
- package/packages/core/src/agent/jev-planner.ts +0 -293
- package/packages/core/src/gateway/tts/package.json +0 -25
- package/packages/core/src/gateway/tts/src/client.ts +0 -59
- package/packages/core/src/gateway/tts/src/index.ts +0 -15
- package/packages/core/src/gateway/tts/src/install.ts +0 -137
- package/packages/core/src/gateway/tts/src/models.ts +0 -50
- package/packages/core/src/gateway/tts/src/server.ts +0 -253
- /package/dist/ui/assets/{core-p4c5dns5.js → core-npANj14X.js} +0 -0
- /package/dist/ui/assets/{download-BQXrpH0m.js → download-D0aDV8Y_.js} +0 -0
- /package/dist/ui/assets/{ellipsis-vertical-D7uFJLGh.js → ellipsis-vertical-BOW_iEOO.js} +0 -0
- /package/dist/ui/assets/{external-link-6oTH9pUM.js → external-link-DNJH7epD.js} +0 -0
- /package/dist/ui/assets/{eye-CxvxtQT5.js → eye-BVfTWOME.js} +0 -0
- /package/dist/ui/assets/{file-text-D5ZJEx3E.js → file-text-ByqNMpXm.js} +0 -0
- /package/dist/ui/assets/{gateway-url-BALS_wVh.js → gateway-url-BzQV75Ig.js} +0 -0
- /package/dist/ui/assets/{gauge-CEu7PhTW.js → gauge-CB4np0Vz.js} +0 -0
- /package/dist/ui/assets/{history-DLK5rTlP.js → history-CbhJX41s.js} +0 -0
- /package/dist/ui/assets/{info-8ReWzubE.js → info-BCD3-QX9.js} +0 -0
- /package/dist/ui/assets/{lock-3IApZyVy.js → lock-DpBean4K.js} +0 -0
- /package/dist/ui/assets/{mail-vwCEHyhQ.js → mail-Biwn8WrV.js} +0 -0
- /package/dist/ui/assets/{mic-CpDU_2as.js → mic-Rq4BxU1R.js} +0 -0
- /package/dist/ui/assets/{pause-BAMsNQkh.js → pause-87NGXbsz.js} +0 -0
- /package/dist/ui/assets/{pencil-CKritjT_.js → pencil-BG8EFaS3.js} +0 -0
- /package/dist/ui/assets/{play-Cwpe4tp6.js → play-D3De6YsQ.js} +0 -0
- /package/dist/ui/assets/{plus-RD44ce15.js → plus-Bp8-V68t.js} +0 -0
- /package/dist/ui/assets/{radio-lFPMHi6-.js → radio-m7rzuDKK.js} +0 -0
- /package/dist/ui/assets/{refresh-cw-DtJMHRHO.js → refresh-cw-D6F1zoC6.js} +0 -0
- /package/dist/ui/assets/{rotate-ccw-b3E_4PoX.js → rotate-ccw-DUlEC1_D.js} +0 -0
- /package/dist/ui/assets/{search-z2oZt00P.js → search-CfNwwpMW.js} +0 -0
- /package/dist/ui/assets/{send-CpoY_2F-.js → send-CI868CBV.js} +0 -0
- /package/dist/ui/assets/{settings-qV3kVkeG.js → settings-AEM2uWiD.js} +0 -0
- /package/dist/ui/assets/{shield-CIarwBvx.js → shield-DvVIcbzd.js} +0 -0
- /package/dist/ui/assets/{sparkles-DVvY6jDT.js → sparkles-DRe4GbSH.js} +0 -0
- /package/dist/ui/assets/{square-D5zdNkAY.js → square-DTWkjTT3.js} +0 -0
- /package/dist/ui/assets/{trash-2-D6oziYAK.js → trash-2-BZsMCfso.js} +0 -0
- /package/dist/ui/assets/{utils-DEmd_M8c.js → utils-lc8H6VGT.js} +0 -0
- /package/dist/ui/assets/{volume-2-EaA0JRvD.js → volume-2-CBMYsuF3.js} +0 -0
- /package/dist/ui/assets/{volume-x-CROXNMGT.js → volume-x-vNFf2e4-.js} +0 -0
- /package/dist/ui/assets/{wifi-BUJuOcgP.js → wifi-DNv53AfN.js} +0 -0
- /package/dist/ui/assets/{zap-DSoX9NDk.js → zap-Yed86Sh8.js} +0 -0
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
loadProviderHeaders, storeProviderHeaders,
|
|
8
8
|
deleteProviderApiKey,
|
|
9
9
|
} from "../../storage/crypto"
|
|
10
|
-
import { getJevStatus, resetJevStatus } from "../../agent/jev-decisions"
|
|
11
10
|
import { loadHiveAgentsModel, getHiveAgentsModelStatus } from "../../agent/llm-providers/hiveagents"
|
|
12
11
|
import { logger } from "../../utils/logger"
|
|
13
12
|
import { fetchProviderModels, syncProviderModels } from "../../storage/model-sync"
|
|
13
|
+
import { reconcileProviderVoiceModels } from "../../storage/model-activation"
|
|
14
|
+
import { supportsStt } from "../../voice/stt-models"
|
|
14
15
|
|
|
15
16
|
const log = logger.child("gateway")
|
|
16
17
|
|
|
@@ -27,7 +28,6 @@ export async function handleGetProviders(req: Request, addCorsHeaders: (r: Respo
|
|
|
27
28
|
modelsByProvider[pid].push({ ...m.doc, provider_id: pid, wire_id: wireModelId(pid, m.doc.id) })
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const jevStatus = await getJevStatus()
|
|
31
31
|
const providers = await Promise.all(rawProviders.map(async (p) => {
|
|
32
32
|
const apiKey = await loadProviderApiKey(p.doc.id)
|
|
33
33
|
const headers = await loadProviderHeaders(p.doc.id)
|
|
@@ -43,7 +43,6 @@ export async function handleGetProviders(req: Request, addCorsHeaders: (r: Respo
|
|
|
43
43
|
has_api_key: apiKey ? 1 : 0,
|
|
44
44
|
has_headers: Object.keys(headers).length > 0 ? 1 : 0,
|
|
45
45
|
masked_api_key: apiKey ? maskApiKey(apiKey) : null,
|
|
46
|
-
...(p.doc.id === "openrouter" || p.doc.id === "hiveagents" ? { jev: jevStatus } : {}),
|
|
47
46
|
models: providerModels,
|
|
48
47
|
}
|
|
49
48
|
}))
|
|
@@ -56,14 +55,16 @@ export async function handleCreateProvider(req: Request, addCorsHeaders: (r: Res
|
|
|
56
55
|
const providersCol = await col<ProviderDoc>("providers")
|
|
57
56
|
const existing = await providersCol.get(body.id)
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
const active = body.enabled === undefined || !!body.enabled
|
|
59
|
+
const provider: ProviderDoc = {
|
|
60
60
|
id: body.id, name: body.name, base_url: body.base_url || null,
|
|
61
61
|
category: existing?.doc.category ?? "llm",
|
|
62
62
|
num_ctx: existing?.doc.num_ctx ?? null, num_gpu: existing?.doc.num_gpu ?? -1,
|
|
63
|
-
enabled:
|
|
64
|
-
active: true,
|
|
63
|
+
enabled: active, active,
|
|
65
64
|
created_at: existing?.doc.created_at ?? Date.now(),
|
|
66
|
-
}
|
|
65
|
+
}
|
|
66
|
+
await providersCol.put(body.id, provider, existing ? { expectedVersion: existing.version } : undefined)
|
|
67
|
+
await reconcileProviderVoiceModels(provider)
|
|
67
68
|
|
|
68
69
|
return addCorsHeaders(Response.json({ ok: true }), req)
|
|
69
70
|
}
|
|
@@ -79,7 +80,6 @@ export async function handleToggleProvider(req: Request, addCorsHeaders: (r: Res
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
await updateDoc<ProviderDoc>("providers", providerId, { active: !!active, enabled: !!active })
|
|
82
|
-
if (providerId === "openrouter" || providerId === "hiveagents") resetJevStatus()
|
|
83
83
|
|
|
84
84
|
// Cascade: activate/deactivate all models for this provider
|
|
85
85
|
await updateManyByIndex<ModelDoc>("models", "provider_id", providerId, { active: !!active, enabled: !!active })
|
|
@@ -102,19 +102,17 @@ export async function handleUpdateProvider(req: Request, addCorsHeaders: (r: Res
|
|
|
102
102
|
if (body.name) patch.name = body.name
|
|
103
103
|
const baseUrl = body.base_url !== undefined ? body.base_url : body.baseUrl
|
|
104
104
|
if (baseUrl !== undefined) patch.base_url = baseUrl || null
|
|
105
|
-
|
|
106
|
-
if (
|
|
105
|
+
const active = body.active ?? body.enabled
|
|
106
|
+
if (active !== undefined) patch.active = patch.enabled = !!active
|
|
107
107
|
if (body.config?.apiKey || body.apiKey) {
|
|
108
108
|
await storeProviderApiKey(id, body.config?.apiKey || body.apiKey)
|
|
109
109
|
if (id === "openrouter") {
|
|
110
110
|
patch.active = true
|
|
111
111
|
patch.enabled = true
|
|
112
|
-
resetJevStatus()
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
if (body.clearApiKey === true) {
|
|
116
115
|
await deleteProviderApiKey(id)
|
|
117
|
-
if (id === "openrouter" || id === "hiveagents") resetJevStatus()
|
|
118
116
|
}
|
|
119
117
|
if (body.headers) {
|
|
120
118
|
await storeProviderHeaders(id, body.headers)
|
|
@@ -123,14 +121,13 @@ export async function handleUpdateProvider(req: Request, addCorsHeaders: (r: Res
|
|
|
123
121
|
if (numCtx !== undefined) patch.num_ctx = numCtx ? Number(numCtx) : null
|
|
124
122
|
|
|
125
123
|
if (Object.keys(patch).length > 0) {
|
|
126
|
-
await updateDoc<ProviderDoc>("providers", id, patch).catch(() => { /* provider not found */ })
|
|
127
|
-
if ((id === "openrouter" || id === "hiveagents") && (patch.active !== undefined || patch.enabled !== undefined)) resetJevStatus()
|
|
124
|
+
const provider = await updateDoc<ProviderDoc>("providers", id, patch).catch(() => { /* provider not found */ })
|
|
128
125
|
|
|
129
126
|
// Cascade active/enabled changes to models
|
|
130
127
|
if (patch.active !== undefined) {
|
|
131
128
|
await updateManyByIndex<ModelDoc>("models", "provider_id", id, { active: patch.active, enabled: patch.active })
|
|
132
|
-
} else if (patch.
|
|
133
|
-
await
|
|
129
|
+
} else if (provider && patch.base_url !== undefined) {
|
|
130
|
+
await reconcileProviderVoiceModels(provider)
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
133
|
|
|
@@ -231,7 +228,7 @@ export async function handleSyncProviderModels(
|
|
|
231
228
|
return addCorsHeaders(new Response("Provider not found", { status: 404 }), req)
|
|
232
229
|
}
|
|
233
230
|
|
|
234
|
-
// Lo que el proveedor declara de cada modelo se guarda
|
|
231
|
+
// Lo que el proveedor declara de cada modelo se guarda conservando los datos del usuario y
|
|
235
232
|
// sin apagar ni borrar los que el proveedor ya no lista: ver storage/model-sync.ts.
|
|
236
233
|
const result = await syncProviderModels(providerId)
|
|
237
234
|
if (!result.ok) {
|
|
@@ -240,7 +237,11 @@ export async function handleSyncProviderModels(
|
|
|
240
237
|
}
|
|
241
238
|
// Se devuelve el doc completo: recortar los campos dejaba a la UI sin
|
|
242
239
|
// context_window ni precio justo después de sincronizar.
|
|
243
|
-
const
|
|
240
|
+
const provider = await providersCol.get(providerId)
|
|
241
|
+
const models = (await (await col<ModelDoc>("models")).findBy("provider_id", providerId)).map(m => ({
|
|
242
|
+
...m.doc,
|
|
243
|
+
supports_stt: supportsStt(m.doc, provider?.doc.base_url),
|
|
244
|
+
}))
|
|
244
245
|
return addCorsHeaders(Response.json({ success: true, synced: result.found, ...result, models }), req)
|
|
245
246
|
}
|
|
246
247
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { col } from "../../storage/hive.ts"
|
|
2
|
-
import { getUsageStats, hourBucket
|
|
2
|
+
import { getUsageStats, hourBucket } from "../../storage/usage.ts"
|
|
3
3
|
import type { ActivityRollupDoc } from "../../storage/collections.ts"
|
|
4
4
|
import { loadConfig } from "../../config/loader.ts"
|
|
5
5
|
import { sessionManager } from "../session.ts"
|
|
@@ -354,7 +354,6 @@ export async function handleGetUsageStats(req: Request, addCorsHeaders: (r: Resp
|
|
|
354
354
|
toonSavingsPercent: summary.toonSavingsPercent,
|
|
355
355
|
byProvider: summary.byProvider,
|
|
356
356
|
byModel: summary.byModel,
|
|
357
|
-
jev: summary.jev,
|
|
358
357
|
}
|
|
359
358
|
|
|
360
359
|
return addCorsHeaders(Response.json(stats), req)
|
|
@@ -375,7 +374,6 @@ interface UsageStats {
|
|
|
375
374
|
toonSavingsPercent: number;
|
|
376
375
|
byProvider: Record<string, { tokens: number; costUsd: number; inputTokens: number; outputTokens: number }>;
|
|
377
376
|
byModel: Record<string, { tokens: number; costUsd: number; provider: string; inputTokens: number; outputTokens: number }>;
|
|
378
|
-
jev: JevUsageSummary;
|
|
379
377
|
}
|
|
380
378
|
|
|
381
379
|
export async function handleSystemReload(req: Request, addCorsHeaders: (r: Response, req: Request) => Response): Promise<Response> {
|
|
@@ -1,389 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, readdirSync, readFileSync } from "fs"
|
|
3
|
-
import { join } from "path"
|
|
4
|
-
import { homedir } from "os"
|
|
5
|
-
import { TTS_MODELS, getModelById } from "../tts/src/models.ts"
|
|
6
|
-
import { runInstall } from "../tts/src/install.ts"
|
|
7
|
-
import { startTTSServer } from "../tts/src/server.ts"
|
|
1
|
+
import { getLocalTTSStatus, getLocalVoices, LocalTTSError, startLocalTTS, stopLocalTTS, synthesizeLocalTTS } from "../tts/kitten"
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
const TTS_ROOT =
|
|
11
|
-
process.env.HIVE_TTS_ROOT ??
|
|
12
|
-
join(process.env.HIVE_HOME ?? join(homedir(), ".hive"), "tts")
|
|
13
|
-
const BIN_PATH = join(TTS_ROOT, "bin", process.platform === "win32" ? "piper.exe" : "piper")
|
|
14
|
-
const VOICES_DIR = join(TTS_ROOT, "voices")
|
|
15
|
-
const TTS_PORT = resolvePort(process.env.TTS_PORT, 5500)
|
|
3
|
+
type Cors = (response: Response, request: Request) => Response
|
|
16
4
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let installLogs: string[] = []
|
|
20
|
-
let downloadingModelId: string | null = null
|
|
21
|
-
let downloadLogs: string[] = []
|
|
22
|
-
|
|
23
|
-
function isInstalled(): { piperExists: boolean; voiceExists: boolean; installed: boolean } {
|
|
24
|
-
const piperExists = existsSync(BIN_PATH)
|
|
25
|
-
const voiceExists = getInstalledVoices().length > 0
|
|
26
|
-
return { piperExists, voiceExists, installed: piperExists && voiceExists }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getInstalledVoices(): string[] {
|
|
30
|
-
if (!existsSync(VOICES_DIR)) return []
|
|
31
|
-
const files = readdirSync(VOICES_DIR)
|
|
32
|
-
return files
|
|
33
|
-
.filter((f) => f.endsWith(".onnx"))
|
|
34
|
-
.map((f) => f.replace(".onnx", ""))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function isRunning(): Promise<boolean> {
|
|
38
|
-
try {
|
|
39
|
-
const res = await fetch(`http://localhost:${TTS_PORT}/health`, {
|
|
40
|
-
signal: AbortSignal.timeout(600),
|
|
41
|
-
})
|
|
42
|
-
return res.ok
|
|
43
|
-
} catch {
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function handleGetLocalTTSStatus(
|
|
49
|
-
req: Request,
|
|
50
|
-
addCors: (r: Response, req: Request) => Response
|
|
51
|
-
): Promise<Response> {
|
|
52
|
-
const { piperExists, voiceExists, installed } = isInstalled()
|
|
53
|
-
const running = await isRunning()
|
|
54
|
-
const voices = getInstalledVoices()
|
|
55
|
-
return addCors(
|
|
56
|
-
Response.json({
|
|
57
|
-
installed,
|
|
58
|
-
piperExists,
|
|
59
|
-
voiceExists,
|
|
60
|
-
running,
|
|
61
|
-
port: TTS_PORT,
|
|
62
|
-
installing,
|
|
63
|
-
voices
|
|
64
|
-
}),
|
|
65
|
-
req
|
|
66
|
-
)
|
|
5
|
+
export function handleGetLocalTTSStatus(req: Request, addCors: Cors): Response {
|
|
6
|
+
return addCors(Response.json(getLocalTTSStatus()), req)
|
|
67
7
|
}
|
|
68
8
|
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
addCors: (r: Response, req: Request) => Response
|
|
72
|
-
): Promise<Response> {
|
|
73
|
-
return addCors(
|
|
74
|
-
Response.json({ logs: installLogs.slice(-100), ttsRoot: TTS_ROOT, bunPath: process.execPath }),
|
|
75
|
-
req
|
|
76
|
-
)
|
|
9
|
+
export function handleStartLocalTTS(req: Request, addCors: Cors): Response {
|
|
10
|
+
return addCors(Response.json({ started: startLocalTTS() }), req)
|
|
77
11
|
}
|
|
78
12
|
|
|
79
|
-
export async function
|
|
80
|
-
|
|
81
|
-
addCors: (r: Response, req: Request) => Response
|
|
82
|
-
): Promise<Response> {
|
|
83
|
-
if (installing) {
|
|
84
|
-
return addCors(Response.json({ started: false, reason: "Ya hay una instalación en curso" }), req)
|
|
85
|
-
}
|
|
86
|
-
if (isInstalled().installed) {
|
|
87
|
-
return addCors(Response.json({ started: false, reason: "Piper ya está instalado" }), req)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
installing = true
|
|
91
|
-
installLogs = [`[${new Date().toISOString()}] Iniciando instalación de Piper...`]
|
|
92
|
-
installLogs.push(` TTS_ROOT: ${TTS_ROOT}`)
|
|
93
|
-
|
|
94
|
-
// Interceptar console.log de runInstall para capturar en installLogs
|
|
95
|
-
const origLog = console.log
|
|
96
|
-
const origWarn = console.warn
|
|
97
|
-
console.log = (...args) => { installLogs.push(args.join(" ")); origLog(...args) }
|
|
98
|
-
console.warn = (...args) => { installLogs.push(`[warn] ${args.join(" ")}`); origWarn(...args) }
|
|
99
|
-
|
|
100
|
-
runInstall(TTS_ROOT)
|
|
101
|
-
.then(() => {
|
|
102
|
-
installLogs.push(`[${new Date().toISOString()}] Instalación completada`)
|
|
103
|
-
})
|
|
104
|
-
.catch((err) => {
|
|
105
|
-
installLogs.push(`[error] ${err instanceof Error ? err.message : String(err)}`)
|
|
106
|
-
console.error(`[hive-tts install] Falló: ${err}`)
|
|
107
|
-
})
|
|
108
|
-
.finally(() => {
|
|
109
|
-
installing = false
|
|
110
|
-
console.log = origLog
|
|
111
|
-
console.warn = origWarn
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
return addCors(Response.json({ started: true }), req)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export async function handleStartLocalTTS(
|
|
118
|
-
req: Request,
|
|
119
|
-
addCors: (r: Response, req: Request) => Response
|
|
120
|
-
): Promise<Response> {
|
|
121
|
-
if (await isRunning()) {
|
|
122
|
-
return addCors(Response.json({ started: false, reason: "El servidor TTS ya está ejecutándose" }), req)
|
|
123
|
-
}
|
|
124
|
-
if (!isInstalled().installed) {
|
|
125
|
-
return addCors(
|
|
126
|
-
Response.json({ started: false, reason: "Piper no está instalado. Instálalo primero." }, { status: 400 }),
|
|
127
|
-
req
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
ttsServer = startTTSServer({ port: TTS_PORT })
|
|
133
|
-
installLogs.push(`[tts-server] Servidor TTS iniciado en puerto ${TTS_PORT}`)
|
|
134
|
-
} catch (err) {
|
|
135
|
-
const msg = err instanceof Error ? err.message : String(err)
|
|
136
|
-
console.error(`[tts-server] Falló al iniciar: ${msg}`)
|
|
137
|
-
installLogs.push(`[error] Servidor TTS falló al iniciar: ${msg}`)
|
|
138
|
-
return addCors(Response.json({ started: false, reason: msg }), req)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Esperar hasta 3s a que el server levante
|
|
142
|
-
for (let i = 0; i < 6; i++) {
|
|
143
|
-
await Bun.sleep(500)
|
|
144
|
-
if (await isRunning()) break
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const running = await isRunning()
|
|
148
|
-
return addCors(Response.json({ started: running }), req)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export async function handleStopLocalTTS(
|
|
152
|
-
req: Request,
|
|
153
|
-
addCors: (r: Response, req: Request) => Response
|
|
154
|
-
): Promise<Response> {
|
|
155
|
-
if (ttsServer) {
|
|
156
|
-
ttsServer.stop(true)
|
|
157
|
-
ttsServer = null
|
|
158
|
-
}
|
|
159
|
-
|
|
13
|
+
export async function handleStopLocalTTS(req: Request, addCors: Cors): Promise<Response> {
|
|
14
|
+
await stopLocalTTS()
|
|
160
15
|
return addCors(Response.json({ stopped: true }), req)
|
|
161
16
|
}
|
|
162
17
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (!isInstalled().installed) return false
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
ttsServer = startTTSServer({ port: TTS_PORT })
|
|
169
|
-
} catch {
|
|
170
|
-
return false
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
for (let i = 0; i < 10; i++) {
|
|
174
|
-
await Bun.sleep(500)
|
|
175
|
-
if (await isRunning()) return true
|
|
176
|
-
}
|
|
177
|
-
return false
|
|
18
|
+
export function handleGetLocalVoices(req: Request, addCors: Cors): Response {
|
|
19
|
+
return addCors(Response.json({ voices: getLocalVoices() }), req)
|
|
178
20
|
}
|
|
179
21
|
|
|
180
|
-
export async function
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
ttsServer = startTTSServer({ port: TTS_PORT })
|
|
187
|
-
console.log(`[tts-server] Servidor TTS auto-iniciado en puerto ${TTS_PORT}`)
|
|
188
|
-
} catch (err) {
|
|
189
|
-
console.error(`[tts-server] Falló el auto-inicio: ${err instanceof Error ? err.message : String(err)}`)
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
console.log(`[tts-server] Servidor TTS ya está ejecutándose en puerto ${TTS_PORT}`)
|
|
193
|
-
}
|
|
22
|
+
export async function handleSpeakLocalTTS(req: Request, addCors: Cors): Promise<Response> {
|
|
23
|
+
const body = await req.json().catch(() => null)
|
|
24
|
+
const text = typeof body?.text === "string" ? body.text.trim() : ""
|
|
25
|
+
if (!text || (body.voice !== undefined && typeof body.voice !== "string")) {
|
|
26
|
+
return addCors(Response.json({ error: "Se requiere texto y una voz válida" }, { status: 400 }), req)
|
|
194
27
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Proxy de síntesis para el browser — evita exponer el puerto TTS directamente
|
|
198
|
-
export async function handleSpeakLocalTTS(
|
|
199
|
-
req: Request,
|
|
200
|
-
addCors: (r: Response, req: Request) => Response
|
|
201
|
-
): Promise<Response> {
|
|
202
|
-
let body: { text?: string; voice?: string }
|
|
203
|
-
try {
|
|
204
|
-
body = await req.json()
|
|
205
|
-
} catch {
|
|
206
|
-
return addCors(Response.json({ error: "Body JSON inválido" }, { status: 400 }), req)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const { text, voice } = body
|
|
210
|
-
if (!text || typeof text !== "string" || text.trim().length === 0) {
|
|
211
|
-
return addCors(Response.json({ error: "'text' requerido" }, { status: 400 }), req)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const running = await ensureTTSRunning()
|
|
215
|
-
if (!running) {
|
|
216
|
-
return addCors(
|
|
217
|
-
Response.json({ error: "Piper TTS no disponible" }, { status: 503 }),
|
|
218
|
-
req
|
|
219
|
-
)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
const res = await fetch(`http://localhost:${TTS_PORT}/tts`, {
|
|
224
|
-
method: "POST",
|
|
225
|
-
headers: { "Content-Type": "application/json" },
|
|
226
|
-
body: JSON.stringify({ text: text.trim(), voice }),
|
|
227
|
-
signal: AbortSignal.timeout(15_000),
|
|
228
|
-
})
|
|
229
|
-
if (!res.ok) {
|
|
230
|
-
const err = await res.json().catch(() => ({ error: "TTS error" }))
|
|
231
|
-
return addCors(Response.json(err, { status: 503 }), req)
|
|
232
|
-
}
|
|
233
|
-
const wav = await res.arrayBuffer()
|
|
234
|
-
return addCors(
|
|
235
|
-
new Response(wav, {
|
|
236
|
-
headers: {
|
|
237
|
-
"Content-Type": "audio/wav",
|
|
238
|
-
"Content-Length": String(wav.byteLength),
|
|
239
|
-
},
|
|
240
|
-
}),
|
|
241
|
-
req
|
|
242
|
-
)
|
|
243
|
-
} catch {
|
|
244
|
-
return addCors(
|
|
245
|
-
Response.json({ error: "Error al sintetizar con Piper" }, { status: 503 }),
|
|
246
|
-
req
|
|
247
|
-
)
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// ─── Gestión de modelos ──────────────────────────────────────────────────────
|
|
252
|
-
|
|
253
|
-
export async function handleGetAvailableModels(
|
|
254
|
-
req: Request,
|
|
255
|
-
addCors: (r: Response, req: Request) => Response
|
|
256
|
-
): Promise<Response> {
|
|
257
|
-
const installedVoices = getInstalledVoices()
|
|
258
|
-
const modelsWithStatus = TTS_MODELS.map((model) => ({
|
|
259
|
-
...model,
|
|
260
|
-
installed: installedVoices.includes(model.id),
|
|
261
|
-
}))
|
|
262
|
-
return addCors(Response.json({ models: modelsWithStatus }), req)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export async function handleGetInstalledVoices(
|
|
266
|
-
req: Request,
|
|
267
|
-
addCors: (r: Response, req: Request) => Response
|
|
268
|
-
): Promise<Response> {
|
|
269
|
-
const voices = getInstalledVoices().map((id) => {
|
|
270
|
-
const model = getModelById(id)
|
|
271
|
-
|
|
272
|
-
// Leer configuración de inferencia del modelo
|
|
273
|
-
let inferenceConfig = { length_scale: 1, noise_scale: 0.667, noise_w: 0.8 }
|
|
274
|
-
const configPath = join(VOICES_DIR, `${id}.onnx.json`)
|
|
275
|
-
if (existsSync(configPath)) {
|
|
276
|
-
try {
|
|
277
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"))
|
|
278
|
-
inferenceConfig = { ...inferenceConfig, ...config.inference }
|
|
279
|
-
} catch {
|
|
280
|
-
// Ignore
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
id,
|
|
286
|
-
name: model?.name || id,
|
|
287
|
-
language: model?.language || "unknown",
|
|
288
|
-
inference: inferenceConfig,
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
return addCors(Response.json({ voices }), req)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export async function handleDownloadModel(
|
|
295
|
-
req: Request,
|
|
296
|
-
addCors: (r: Response, req: Request) => Response
|
|
297
|
-
): Promise<Response> {
|
|
298
|
-
let body: { modelId?: string }
|
|
299
28
|
try {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
29
|
+
const audio = await synthesizeLocalTTS(text, body.voice)
|
|
30
|
+
return addCors(new Response(audio.body, { headers: { "Content-Type": "audio/wav" } }), req)
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
const message = cause instanceof LocalTTSError ? cause.message : "Kitten TTS no disponible"
|
|
33
|
+
return addCors(Response.json({ error: message }, { status: cause instanceof LocalTTSError ? cause.status : 503 }), req)
|
|
303
34
|
}
|
|
304
|
-
|
|
305
|
-
const { modelId } = body
|
|
306
|
-
if (!modelId || typeof modelId !== "string") {
|
|
307
|
-
return addCors(Response.json({ error: "modelId requerido" }, { status: 400 }), req)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const model = getModelById(modelId)
|
|
311
|
-
if (!model) {
|
|
312
|
-
return addCors(Response.json({ error: `Modelo no encontrado: ${modelId}` }, { status: 404 }), req)
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (downloadingModelId) {
|
|
316
|
-
return addCors(
|
|
317
|
-
Response.json({
|
|
318
|
-
started: false,
|
|
319
|
-
reason: `Ya hay una descarga en curso: ${downloadingModelId}`
|
|
320
|
-
}, { status: 409 }),
|
|
321
|
-
req
|
|
322
|
-
)
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Verificar si ya está instalado
|
|
326
|
-
const installedVoices = getInstalledVoices()
|
|
327
|
-
if (installedVoices.includes(modelId)) {
|
|
328
|
-
return addCors(
|
|
329
|
-
Response.json({ started: false, reason: "El modelo ya está instalado" }, { status: 409 }),
|
|
330
|
-
req
|
|
331
|
-
)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
downloadingModelId = modelId
|
|
335
|
-
downloadLogs = [`[${new Date().toISOString()}] Iniciando descarga de ${model.name}...`]
|
|
336
|
-
|
|
337
|
-
// Ejecutar descarga en background
|
|
338
|
-
;(async () => {
|
|
339
|
-
try {
|
|
340
|
-
const modelDest = join(VOICES_DIR, `${modelId}.onnx`)
|
|
341
|
-
const configDest = join(VOICES_DIR, `${modelId}.onnx.json`)
|
|
342
|
-
|
|
343
|
-
downloadLogs.push(` Descargando modelo: ${model.size}`)
|
|
344
|
-
downloadLogs.push(` URL: ${model.modelUrl}`)
|
|
345
|
-
|
|
346
|
-
// Descargar modelo
|
|
347
|
-
const modelRes = await fetch(model.modelUrl)
|
|
348
|
-
if (!modelRes.ok) {
|
|
349
|
-
throw new Error(`HTTP ${modelRes.status} al descargar modelo`)
|
|
350
|
-
}
|
|
351
|
-
const modelBuf = await modelRes.arrayBuffer()
|
|
352
|
-
await Bun.write(modelDest, modelBuf)
|
|
353
|
-
downloadLogs.push(` ✓ Modelo descargado (${(modelBuf.byteLength / 1024 / 1024).toFixed(1)} MB)`)
|
|
354
|
-
|
|
355
|
-
// Descargar config
|
|
356
|
-
downloadLogs.push(` Descargando configuración...`)
|
|
357
|
-
const configRes = await fetch(model.configUrl)
|
|
358
|
-
if (!configRes.ok) {
|
|
359
|
-
throw new Error(`HTTP ${configRes.status} al descargar config`)
|
|
360
|
-
}
|
|
361
|
-
const configBuf = await configRes.arrayBuffer()
|
|
362
|
-
await Bun.write(configDest, configBuf)
|
|
363
|
-
downloadLogs.push(` ✓ Configuración descargada`)
|
|
364
|
-
|
|
365
|
-
downloadLogs.push(`[${new Date().toISOString()}] ${model.name} instalado exitosamente`)
|
|
366
|
-
} catch (err) {
|
|
367
|
-
downloadLogs.push(`[error] ${err instanceof Error ? err.message : String(err)}`)
|
|
368
|
-
console.error(`[hive-tts download] Error:`, err)
|
|
369
|
-
} finally {
|
|
370
|
-
downloadingModelId = null
|
|
371
|
-
}
|
|
372
|
-
})()
|
|
373
|
-
|
|
374
|
-
return addCors(Response.json({ started: true, modelId }), req)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
export async function handleGetDownloadLogs(
|
|
378
|
-
req: Request,
|
|
379
|
-
addCors: (r: Response, req: Request) => Response
|
|
380
|
-
): Promise<Response> {
|
|
381
|
-
return addCors(
|
|
382
|
-
Response.json({
|
|
383
|
-
logs: downloadLogs,
|
|
384
|
-
downloading: downloadingModelId !== null,
|
|
385
|
-
currentModelId: downloadingModelId
|
|
386
|
-
}),
|
|
387
|
-
req
|
|
388
|
-
)
|
|
389
35
|
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { col, updateDoc } from "../../storage/hive"
|
|
2
2
|
import type { ModelDoc, ProviderDoc, ChannelDoc } from "../../storage/collections"
|
|
3
3
|
import { voiceService } from "../../voice"
|
|
4
|
+
import { LOCAL_TTS_PROVIDER } from "../../voice/local-model"
|
|
5
|
+
import { nvidiaSttBase, supportsStt } from "../../voice/stt-models"
|
|
6
|
+
import { getLocalTTSStatus, getLocalVoices } from "../tts/kitten"
|
|
4
7
|
import { storeProviderApiKey, loadProviderApiKey } from "../../storage/crypto"
|
|
5
8
|
|
|
6
9
|
/** Providers de voz = providers con al menos un modelo STT/TTS en la BD. */
|
|
7
10
|
async function getVoiceProviderIds(): Promise<string[]> {
|
|
8
11
|
const modelsCol = await col<ModelDoc>("models")
|
|
9
|
-
const [
|
|
10
|
-
modelsCol.
|
|
11
|
-
|
|
12
|
+
const [models, nvidia] = await Promise.all([
|
|
13
|
+
modelsCol.scan({}),
|
|
14
|
+
(await col<ProviderDoc>("providers")).get("nvidia"),
|
|
12
15
|
])
|
|
13
|
-
const ids = new Set(
|
|
16
|
+
const ids = new Set(models
|
|
17
|
+
.filter(({ doc }) => doc.model_type === "tts" || supportsStt(doc, nvidia?.doc.base_url))
|
|
18
|
+
.map(({ doc }) => doc.provider_id))
|
|
14
19
|
return [...ids]
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
async function isVoiceProviderConfigured(id: string): Promise<boolean> {
|
|
23
|
+
if (id === LOCAL_TTS_PROVIDER) return getLocalTTSStatus().running
|
|
24
|
+
if (id === "nvidia") {
|
|
25
|
+
const provider = await (await col<ProviderDoc>("providers")).get(id)
|
|
26
|
+
if (nvidiaSttBase(provider?.doc.base_url)) return true
|
|
27
|
+
}
|
|
28
|
+
// Match the credentials shown in Providers. Process environment keys can
|
|
29
|
+
// still be used by the runtime, but don't configure a provider in the UI.
|
|
30
|
+
return !!(await loadProviderApiKey(id)).trim()
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
export async function handleGetVoiceProviders(req: Request, addCorsHeaders: (r: Response, req: Request) => Response): Promise<Response> {
|
|
@@ -34,7 +40,7 @@ export async function handleGetConfiguredVoiceProviders(req: Request, addCorsHea
|
|
|
34
40
|
const voiceProviderIds = await getVoiceProviderIds()
|
|
35
41
|
const results = await Promise.all(voiceProviderIds.map(async id => ({
|
|
36
42
|
id,
|
|
37
|
-
configured:
|
|
43
|
+
configured: await isVoiceProviderConfigured(id)
|
|
38
44
|
})))
|
|
39
45
|
|
|
40
46
|
const providers: Record<string, boolean> = {}
|
|
@@ -91,6 +97,13 @@ export async function handleGetVoiceProviderVoices(
|
|
|
91
97
|
providerId: string
|
|
92
98
|
): Promise<Response> {
|
|
93
99
|
try {
|
|
100
|
+
const modelId = new URL(req.url).searchParams.get("model")
|
|
101
|
+
if (modelId) {
|
|
102
|
+
const model = await (await col<ModelDoc>("models")).get(modelId)
|
|
103
|
+
if (model?.doc.provider_id !== providerId || model.doc.model_type !== "tts") {
|
|
104
|
+
return addCorsHeaders(Response.json({ voices: [], error: "Modelo TTS desconocido" }, { status: 404 }), req)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
94
107
|
let voices: Array<{ id: string; name: string }>
|
|
95
108
|
|
|
96
109
|
switch (providerId) {
|
|
@@ -104,33 +117,14 @@ export async function handleGetVoiceProviderVoices(
|
|
|
104
117
|
voices = voiceService.getGeminiVoices()
|
|
105
118
|
break
|
|
106
119
|
case "groq":
|
|
107
|
-
voices = voiceService.getGroqVoices()
|
|
120
|
+
voices = voiceService.getGroqVoices(modelId ?? undefined)
|
|
108
121
|
break
|
|
109
122
|
case "qwen":
|
|
110
123
|
voices = voiceService.getQwenVoices()
|
|
111
124
|
break
|
|
112
|
-
case
|
|
113
|
-
|
|
114
|
-
const TTS_PORT = Number(process.env.TTS_PORT ?? 5500)
|
|
115
|
-
try {
|
|
116
|
-
const res = await fetch(`http://localhost:${TTS_PORT}/voices`, {
|
|
117
|
-
signal: AbortSignal.timeout(1000),
|
|
118
|
-
})
|
|
119
|
-
if (res.ok) {
|
|
120
|
-
const data = await res.json()
|
|
121
|
-
voices = (data.voices || []).map((v: string) => ({
|
|
122
|
-
id: v,
|
|
123
|
-
name: v.replace(/_/g, " ").replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase()),
|
|
124
|
-
}))
|
|
125
|
-
} else {
|
|
126
|
-
voices = [{ id: "es_MX-claude-14947-epoch-high", name: "Piper Local (Claude Spanish)" }]
|
|
127
|
-
}
|
|
128
|
-
} catch {
|
|
129
|
-
// Servidor TTS no disponible - usar fallback para permitir selección
|
|
130
|
-
voices = [{ id: "es_MX-claude-14947-epoch-high", name: "Piper Local (Claude Spanish)" }]
|
|
131
|
-
}
|
|
125
|
+
case LOCAL_TTS_PROVIDER:
|
|
126
|
+
voices = getLocalVoices()
|
|
132
127
|
break
|
|
133
|
-
}
|
|
134
128
|
default:
|
|
135
129
|
return addCorsHeaders(Response.json({ voices: [] }), req)
|
|
136
130
|
}
|