@johpaz/hive-agents 1.1.5 → 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.
Files changed (206) hide show
  1. package/README.md +4 -10
  2. package/dist/hive.js +218257 -148718
  3. package/dist/tool-worker.js +68422 -1622
  4. package/dist/ui/assets/{A2UIPage-Dr3p75oE.js → A2UIPage-v-VggXW3.js} +4 -4
  5. package/dist/ui/assets/{AgentCreateForm-DqYhH_gm.js → AgentCreateForm-Dr1l4Cvg.js} +1 -1
  6. package/dist/ui/assets/AgentDetailPage-Dsh_grrr.js +1 -0
  7. package/dist/ui/assets/{AgentNewPage-BRpFxJIT.js → AgentNewPage-D7557C0J.js} +1 -1
  8. package/dist/ui/assets/AgentsPage-C_Z56LL1.js +10 -0
  9. package/dist/ui/assets/{ApiClientPage-R9UDWfR2.js → ApiClientPage-uuBnrh0y.js} +1 -1
  10. package/dist/ui/assets/ChannelsPage-BI4mAgRU.js +8 -0
  11. package/dist/ui/assets/DashboardPage-BjAxvzYP.js +6 -0
  12. package/dist/ui/assets/LoginPage-D7IZKON0.js +1 -0
  13. package/dist/ui/assets/{LogsPage-DICMU_7m.js → LogsPage-mcqOYvGw.js} +1 -1
  14. package/dist/ui/assets/MeetingPage-qPJ1z5HA.js +1 -0
  15. package/dist/ui/assets/ModelSelector-njfNhkng.js +1 -0
  16. package/dist/ui/assets/{NotFound-D4ZlDVg9.js → NotFound-DY8e1RKh.js} +1 -1
  17. package/dist/ui/assets/{Office3DPage-31AMJ-LN.css → Office3DPage-C3SIzd2H.css} +1 -1
  18. package/dist/ui/assets/Office3DPage-Du42LRwi.js +319 -0
  19. package/dist/ui/assets/ProvidersPage-GDCJs8Zb.js +1 -0
  20. package/dist/ui/assets/{RecoverPage-Blms3NBa.js → RecoverPage-B6qvBBIl.js} +1 -1
  21. package/dist/ui/assets/SettingsPage-Br4PfWuc.js +9 -0
  22. package/dist/ui/assets/{SetupPage-CAjLseE_.js → SetupPage-OaouFLGD.js} +1 -1
  23. package/dist/ui/assets/{Vignette-DrI2yK2m.js → Vignette-GSZ-owcN.js} +17 -17
  24. package/dist/ui/assets/VoicePage-DRQZBl3j.js +307 -0
  25. package/dist/ui/assets/WebChatPage-Cypq-SYi.js +29 -0
  26. package/dist/ui/assets/{agentCapabilities-CDSfJWhw.js → agentCapabilities-Bf71Gir4.js} +1 -1
  27. package/dist/ui/assets/{alert-CjiX20jI.js → alert-Dn604uVs.js} +1 -1
  28. package/dist/ui/assets/{badge-B5AKge1b.js → badge-C6H33ePv.js} +1 -1
  29. package/dist/ui/assets/{card-mTJ4oZbL.js → card-D0qneq1i.js} +1 -1
  30. package/dist/ui/assets/{conversationsStore-DhM07qYi.js → conversationsStore-D6XgjMr1.js} +1 -1
  31. package/dist/ui/assets/{dialog-BP3GTCPn.js → dialog-DO1fQCF7.js} +1 -1
  32. package/dist/ui/assets/dist-js-C2MfmbEW.js +1 -0
  33. package/dist/ui/assets/{dist-js-CkNhvsFc.js → dist-js-Djxbxbst.js} +1 -1
  34. package/dist/ui/assets/google-external-e9lvWjy4.js +1 -0
  35. package/dist/ui/assets/index-BKNFH2al.css +2 -0
  36. package/dist/ui/assets/index-U0e4e5mL.js +156 -0
  37. package/dist/ui/assets/{key-DPkOY-J0.js → key-round-Ca0Ns34v.js} +1 -1
  38. package/dist/ui/assets/{label-D_fvqJyD.js → label-CvAtVE-v.js} +1 -1
  39. package/dist/ui/assets/{scroll-area-CbH8FOo8.js → scroll-area-CYMu7sU0.js} +1 -1
  40. package/dist/ui/assets/select-BjBXxyxL.js +1 -0
  41. package/dist/ui/assets/{slider-DXS4h1LB.js → slider-DR31eN3r.js} +1 -1
  42. package/dist/ui/assets/{switch-ndx8VCpm.js → switch-B5dAwb54.js} +1 -1
  43. package/dist/ui/assets/{tabs-epu-3Tl4.js → tabs-Ct92cLXr.js} +1 -1
  44. package/dist/ui/assets/{earth-BJRGJbVn.js → terminal-CpBDERBE.js} +1 -1
  45. package/dist/ui/assets/{textarea-BgZJFZTX.js → textarea-xtFAVuPf.js} +1 -1
  46. package/dist/ui/assets/{useAudioDevices-zj0fuGwZ.js → useAudioDevices-wZArmV3m.js} +1 -1
  47. package/dist/ui/assets/{useHiveAgentsModelLoad-Cd9p-bjs.js → useHiveAgentsModelLoad-CqJkzTOT.js} +1 -1
  48. package/dist/ui/assets/useOfficeModel-DZvwZRCw.js +1 -0
  49. package/dist/ui/assets/{useProviders-Dj1k5PCk.js → useProviders-CeSzDnx-.js} +1 -1
  50. package/dist/ui/assets/vendor-router-DxU0Uf4R.js +3 -0
  51. package/dist/ui/index.html +5 -5
  52. package/package.json +1 -3
  53. package/packages/cli/src/commands/onboard.ts +3 -2
  54. package/packages/core/src/agent/agent-catalog.ts +98 -1
  55. package/packages/core/src/agent/agent-loop.ts +5 -44
  56. package/packages/core/src/agent/context-compiler.ts +6 -94
  57. package/packages/core/src/agent/conversation-store.ts +23 -1
  58. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
  59. package/packages/core/src/agent/minimal-loadout.ts +1 -0
  60. package/packages/core/src/agent/prompt-builder.ts +17 -1
  61. package/packages/core/src/agent/tool-selector.ts +12 -0
  62. package/packages/core/src/artifacts/store.ts +73 -9
  63. package/packages/core/src/canvas/emitter.ts +0 -19
  64. package/packages/core/src/channels/base.ts +26 -0
  65. package/packages/core/src/channels/discord.ts +18 -2
  66. package/packages/core/src/channels/slack.ts +37 -7
  67. package/packages/core/src/channels/telegram.ts +39 -11
  68. package/packages/core/src/channels/whatsapp.ts +16 -1
  69. package/packages/core/src/gateway/channel-notify.ts +42 -0
  70. package/packages/core/src/gateway/google-host.ts +228 -0
  71. package/packages/core/src/gateway/initializer.ts +8 -0
  72. package/packages/core/src/gateway/routes/agents.ts +14 -0
  73. package/packages/core/src/gateway/routes/artifacts.ts +4 -0
  74. package/packages/core/src/gateway/routes/auth.ts +25 -3
  75. package/packages/core/src/gateway/routes/chat.ts +14 -1
  76. package/packages/core/src/gateway/routes/google.ts +252 -0
  77. package/packages/core/src/gateway/routes/meeting.ts +11 -3
  78. package/packages/core/src/gateway/routes/models.ts +27 -11
  79. package/packages/core/src/gateway/routes/multimodal.ts +38 -0
  80. package/packages/core/src/gateway/routes/providers.ts +19 -18
  81. package/packages/core/src/gateway/routes/system.ts +1 -3
  82. package/packages/core/src/gateway/routes/tts-local.ts +20 -374
  83. package/packages/core/src/gateway/routes/voice.ts +29 -35
  84. package/packages/core/src/gateway/server.ts +97 -48
  85. package/packages/core/src/gateway/tts/README.md +7 -86
  86. package/packages/core/src/gateway/tts/build.py +105 -0
  87. package/packages/core/src/gateway/tts/kitten.ts +282 -0
  88. package/packages/core/src/gateway/tts/python.d.ts +4 -0
  89. package/packages/core/src/gateway/tts/src/detect.ts +33 -39
  90. package/packages/core/src/gateway/tts/worker.py +80 -0
  91. package/packages/core/src/gateway/webchat-turn.ts +15 -13
  92. package/packages/core/src/google/client.ts +123 -0
  93. package/packages/core/src/google/config.ts +60 -0
  94. package/packages/core/src/google/google.test.ts +287 -0
  95. package/packages/core/src/google/index.ts +5 -0
  96. package/packages/core/src/google/oauth.ts +144 -0
  97. package/packages/core/src/google/scopes.ts +41 -0
  98. package/packages/core/src/google/token-store.ts +33 -0
  99. package/packages/core/src/multimodal/attachment-ingest.ts +190 -0
  100. package/packages/core/src/multimodal/image-generation.ts +244 -0
  101. package/packages/core/src/multimodal/vision-analyzer.ts +94 -0
  102. package/packages/core/src/multimodal/vision-service.ts +25 -0
  103. package/packages/core/src/storage/collections.ts +8 -8
  104. package/packages/core/src/storage/google-capabilities.ts +91 -0
  105. package/packages/core/src/storage/model-activation.ts +18 -0
  106. package/packages/core/src/storage/model-sync.ts +66 -14
  107. package/packages/core/src/storage/onboarding.ts +10 -2
  108. package/packages/core/src/storage/seed.ts +107 -24
  109. package/packages/core/src/storage/usage.ts +0 -52
  110. package/packages/core/src/tool-runtime/index.ts +2 -0
  111. package/packages/core/src/tools/agents/get-available-models.ts +1 -3
  112. package/packages/core/src/tools/core/index.ts +80 -2
  113. package/packages/core/src/tools/google/calendar.ts +204 -0
  114. package/packages/core/src/tools/google/drive.ts +160 -0
  115. package/packages/core/src/tools/google/gmail.ts +579 -0
  116. package/packages/core/src/tools/google/index.ts +18 -0
  117. package/packages/core/src/tools/google/shared.ts +80 -0
  118. package/packages/core/src/tools/image/image-generate.ts +90 -0
  119. package/packages/core/src/tools/image/index.ts +13 -0
  120. package/packages/core/src/tools/image/office-leer-imagenes.ts +198 -0
  121. package/packages/core/src/tools/index.ts +27 -0
  122. package/packages/core/src/tools/office/index.ts +9 -0
  123. package/packages/core/src/tools/office/office-editar-docx.ts +184 -0
  124. package/packages/core/src/tools/office/office-editar-pptx.ts +126 -0
  125. package/packages/core/src/tools/office/office-editar-xlsx.ts +122 -0
  126. package/packages/core/src/tools/office/office-escribir-docx.ts +3 -2
  127. package/packages/core/src/tools/office/office-escribir-pdf.ts +3 -2
  128. package/packages/core/src/tools/office/office-escribir-pptx.ts +3 -2
  129. package/packages/core/src/tools/office/office-escribir-xlsx.ts +3 -2
  130. package/packages/core/src/tools/office/office-images.ts +137 -0
  131. package/packages/core/src/tools/office/office-leer-docx.ts +16 -3
  132. package/packages/core/src/tools/office/office-leer-pdf.ts +41 -57
  133. package/packages/core/src/tools/office/office-leer-pptx.ts +54 -88
  134. package/packages/core/src/tools/office/office-leer-xlsx.ts +6 -2
  135. package/packages/core/src/tools/office/office-pdf-images.ts +225 -0
  136. package/packages/core/src/tools/office/pdf-text.ts +186 -0
  137. package/packages/core/src/tools/office/pptx-slides.ts +83 -0
  138. package/packages/core/src/tools/office/resolve-input.ts +49 -0
  139. package/packages/core/src/tools/web/browser-screenshot.ts +7 -0
  140. package/packages/core/src/voice/index.ts +123 -155
  141. package/packages/core/src/voice/local-model.ts +8 -0
  142. package/packages/core/src/voice/stt-models.ts +39 -0
  143. package/packages/skills/src/bundled/google/google_calendar/SKILL.md +51 -0
  144. package/packages/skills/src/bundled/google/google_drive/SKILL.md +50 -0
  145. package/packages/skills/src/bundled/google/google_gmail/SKILL.md +61 -0
  146. package/packages/skills/src/bundled-data.generated.ts +45 -0
  147. package/dist/ui/assets/AgentDetailPage-BVtE88U5.js +0 -1
  148. package/dist/ui/assets/AgentsPage-BOIJ55cj.js +0 -10
  149. package/dist/ui/assets/ChannelsPage-C5V2BmjL.js +0 -8
  150. package/dist/ui/assets/DashboardPage-B18gMzNj.js +0 -6
  151. package/dist/ui/assets/LoginPage-nrsYF9AY.js +0 -1
  152. package/dist/ui/assets/MeetingPage-xslJGfIz.js +0 -1
  153. package/dist/ui/assets/ModelSelector-BX4IvuYY.js +0 -1
  154. package/dist/ui/assets/Office3DPage-a6cuzt5X.js +0 -727
  155. package/dist/ui/assets/ProvidersPage-C8-xGoeh.js +0 -1
  156. package/dist/ui/assets/SettingsPage-BBeeq_QS.js +0 -9
  157. package/dist/ui/assets/VoicePage-BeSSYstD.js +0 -307
  158. package/dist/ui/assets/WebChatPage-Bat7uUfd.js +0 -29
  159. package/dist/ui/assets/dist-js-jWCEHSkB.js +0 -1
  160. package/dist/ui/assets/index-BG3nUPKq.js +0 -156
  161. package/dist/ui/assets/index-DmFPF9xQ.css +0 -2
  162. package/dist/ui/assets/lock-open-v0EphssG.js +0 -1
  163. package/dist/ui/assets/select-v_3QBYrD.js +0 -1
  164. package/dist/ui/assets/terminal-BEcTK780.js +0 -1
  165. package/dist/ui/assets/useOfficeModel-BaDn7U-X.js +0 -1
  166. package/dist/ui/assets/vendor-router-DSMCk-Ka.js +0 -3
  167. package/packages/core/src/agent/jev-decisions.ts +0 -242
  168. package/packages/core/src/agent/jev-planner.ts +0 -293
  169. package/packages/core/src/gateway/tts/package.json +0 -25
  170. package/packages/core/src/gateway/tts/src/client.ts +0 -59
  171. package/packages/core/src/gateway/tts/src/index.ts +0 -15
  172. package/packages/core/src/gateway/tts/src/install.ts +0 -137
  173. package/packages/core/src/gateway/tts/src/models.ts +0 -50
  174. package/packages/core/src/gateway/tts/src/server.ts +0 -253
  175. /package/dist/ui/assets/{core-p4c5dns5.js → core-npANj14X.js} +0 -0
  176. /package/dist/ui/assets/{download-BQXrpH0m.js → download-D0aDV8Y_.js} +0 -0
  177. /package/dist/ui/assets/{ellipsis-vertical-D7uFJLGh.js → ellipsis-vertical-BOW_iEOO.js} +0 -0
  178. /package/dist/ui/assets/{external-link-6oTH9pUM.js → external-link-DNJH7epD.js} +0 -0
  179. /package/dist/ui/assets/{eye-CxvxtQT5.js → eye-BVfTWOME.js} +0 -0
  180. /package/dist/ui/assets/{file-text-D5ZJEx3E.js → file-text-ByqNMpXm.js} +0 -0
  181. /package/dist/ui/assets/{gateway-url-BALS_wVh.js → gateway-url-BzQV75Ig.js} +0 -0
  182. /package/dist/ui/assets/{gauge-CEu7PhTW.js → gauge-CB4np0Vz.js} +0 -0
  183. /package/dist/ui/assets/{history-DLK5rTlP.js → history-CbhJX41s.js} +0 -0
  184. /package/dist/ui/assets/{info-8ReWzubE.js → info-BCD3-QX9.js} +0 -0
  185. /package/dist/ui/assets/{lock-3IApZyVy.js → lock-DpBean4K.js} +0 -0
  186. /package/dist/ui/assets/{mail-vwCEHyhQ.js → mail-Biwn8WrV.js} +0 -0
  187. /package/dist/ui/assets/{mic-CpDU_2as.js → mic-Rq4BxU1R.js} +0 -0
  188. /package/dist/ui/assets/{pause-BAMsNQkh.js → pause-87NGXbsz.js} +0 -0
  189. /package/dist/ui/assets/{pencil-CKritjT_.js → pencil-BG8EFaS3.js} +0 -0
  190. /package/dist/ui/assets/{play-Cwpe4tp6.js → play-D3De6YsQ.js} +0 -0
  191. /package/dist/ui/assets/{plus-RD44ce15.js → plus-Bp8-V68t.js} +0 -0
  192. /package/dist/ui/assets/{radio-lFPMHi6-.js → radio-m7rzuDKK.js} +0 -0
  193. /package/dist/ui/assets/{refresh-cw-DtJMHRHO.js → refresh-cw-D6F1zoC6.js} +0 -0
  194. /package/dist/ui/assets/{rotate-ccw-b3E_4PoX.js → rotate-ccw-DUlEC1_D.js} +0 -0
  195. /package/dist/ui/assets/{search-z2oZt00P.js → search-CfNwwpMW.js} +0 -0
  196. /package/dist/ui/assets/{send-CpoY_2F-.js → send-CI868CBV.js} +0 -0
  197. /package/dist/ui/assets/{settings-qV3kVkeG.js → settings-AEM2uWiD.js} +0 -0
  198. /package/dist/ui/assets/{shield-CIarwBvx.js → shield-DvVIcbzd.js} +0 -0
  199. /package/dist/ui/assets/{sparkles-DVvY6jDT.js → sparkles-DRe4GbSH.js} +0 -0
  200. /package/dist/ui/assets/{square-D5zdNkAY.js → square-DTWkjTT3.js} +0 -0
  201. /package/dist/ui/assets/{trash-2-D6oziYAK.js → trash-2-BZsMCfso.js} +0 -0
  202. /package/dist/ui/assets/{utils-DEmd_M8c.js → utils-lc8H6VGT.js} +0 -0
  203. /package/dist/ui/assets/{volume-2-EaA0JRvD.js → volume-2-CBMYsuF3.js} +0 -0
  204. /package/dist/ui/assets/{volume-x-CROXNMGT.js → volume-x-vNFf2e4-.js} +0 -0
  205. /package/dist/ui/assets/{wifi-BUJuOcgP.js → wifi-DNv53AfN.js} +0 -0
  206. /package/dist/ui/assets/{zap-DSoX9NDk.js → zap-Yed86Sh8.js} +0 -0
@@ -1,389 +1,35 @@
1
- import { resolvePort } from "../../utils/port";
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
- // Datos de TTS en HIVE_HOME/tts/ — funciona igual en dev, npm global y Docker
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
- let ttsServer: ReturnType<typeof Bun.serve> | null = null
18
- let installing = false
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 async function handleGetLocalTTSLogs(
70
- req: Request,
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 handleInstallLocalTTS(
80
- req: Request,
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
- async function ensureTTSRunning(): Promise<boolean> {
164
- if (await isRunning()) return true
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 initializeLocalTTS() {
181
- const { installed } = isInstalled()
182
- if (installed) {
183
- const running = await isRunning()
184
- if (!running) {
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
- body = await req.json()
301
- } catch {
302
- return addCors(Response.json({ error: "Body JSON inválido" }, { status: 400 }), req)
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 [sttModels, ttsModels] = await Promise.all([
10
- modelsCol.findBy("model_type", "stt"),
11
- modelsCol.findBy("model_type", "tts"),
12
+ const [models, nvidia] = await Promise.all([
13
+ modelsCol.scan({}),
14
+ (await col<ProviderDoc>("providers")).get("nvidia"),
12
15
  ])
13
- const ids = new Set([...sttModels, ...ttsModels].map(e => e.doc.provider_id))
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
- /** Providers de voz locales (modelos con capability "local", ej. Piper) no requieren API key. */
18
- async function isLocalVoiceProvider(providerId: string): Promise<boolean> {
19
- const modelsCol = await col<ModelDoc>("models")
20
- const models = await modelsCol.findBy("provider_id", providerId)
21
- return models.some(e =>
22
- (e.doc.model_type === "stt" || e.doc.model_type === "tts") &&
23
- !!e.doc.capabilities?.includes('"local"')
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: (await isLocalVoiceProvider(id)) || !!(await loadProviderApiKey(id))
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 "piper": {
113
- // Consultar voces disponibles en el servidor TTS local
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
  }