@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.
Files changed (182) hide show
  1. package/README.md +4 -10
  2. package/dist/hive.js +5258 -2985
  3. package/dist/tool-worker.js +197 -75
  4. package/dist/ui/assets/{A2UIPage-CxE3jH4_.js → A2UIPage-v-VggXW3.js} +4 -4
  5. package/dist/ui/assets/{AgentCreateForm-SGj5AqAX.js → AgentCreateForm-Dr1l4Cvg.js} +1 -1
  6. package/dist/ui/assets/AgentDetailPage-Dsh_grrr.js +1 -0
  7. package/dist/ui/assets/{AgentNewPage-xvAmX6kw.js → AgentNewPage-D7557C0J.js} +1 -1
  8. package/dist/ui/assets/AgentsPage-C_Z56LL1.js +10 -0
  9. package/dist/ui/assets/{ApiClientPage-NLw2wHjH.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-G9d2G1nL.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-Dr6qKgV5.js → RecoverPage-B6qvBBIl.js} +1 -1
  21. package/dist/ui/assets/SettingsPage-Br4PfWuc.js +9 -0
  22. package/dist/ui/assets/{SetupPage-BoVKIf4r.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-ns_ZfKgg.js → conversationsStore-D6XgjMr1.js} +1 -1
  31. package/dist/ui/assets/{dialog-C3n2xYF2.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-CsPrtpWY.js → useAudioDevices-wZArmV3m.js} +1 -1
  47. package/dist/ui/assets/{useHiveAgentsModelLoad-nn4gON9g.js → useHiveAgentsModelLoad-CqJkzTOT.js} +1 -1
  48. package/dist/ui/assets/useOfficeModel-DZvwZRCw.js +1 -0
  49. package/dist/ui/assets/{useProviders-9tvEC3hX.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/core/src/agent/agent-catalog.ts +98 -1
  54. package/packages/core/src/agent/agent-loop.ts +5 -44
  55. package/packages/core/src/agent/context-compiler.ts +6 -94
  56. package/packages/core/src/agent/conversation-store.ts +23 -1
  57. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +1 -1
  58. package/packages/core/src/agent/prompt-builder.ts +17 -1
  59. package/packages/core/src/agent/tool-selector.ts +8 -0
  60. package/packages/core/src/artifacts/store.ts +66 -8
  61. package/packages/core/src/canvas/emitter.ts +0 -19
  62. package/packages/core/src/gateway/google-host.ts +228 -0
  63. package/packages/core/src/gateway/initializer.ts +8 -0
  64. package/packages/core/src/gateway/routes/agents.ts +14 -0
  65. package/packages/core/src/gateway/routes/auth.ts +25 -3
  66. package/packages/core/src/gateway/routes/chat.ts +14 -1
  67. package/packages/core/src/gateway/routes/google.ts +252 -0
  68. package/packages/core/src/gateway/routes/meeting.ts +11 -3
  69. package/packages/core/src/gateway/routes/models.ts +27 -11
  70. package/packages/core/src/gateway/routes/multimodal.ts +19 -0
  71. package/packages/core/src/gateway/routes/providers.ts +19 -18
  72. package/packages/core/src/gateway/routes/system.ts +1 -3
  73. package/packages/core/src/gateway/routes/tts-local.ts +20 -374
  74. package/packages/core/src/gateway/routes/voice.ts +29 -35
  75. package/packages/core/src/gateway/server.ts +58 -32
  76. package/packages/core/src/gateway/tts/README.md +7 -86
  77. package/packages/core/src/gateway/tts/build.py +105 -0
  78. package/packages/core/src/gateway/tts/kitten.ts +282 -0
  79. package/packages/core/src/gateway/tts/python.d.ts +4 -0
  80. package/packages/core/src/gateway/tts/src/detect.ts +33 -39
  81. package/packages/core/src/gateway/tts/worker.py +80 -0
  82. package/packages/core/src/google/client.ts +123 -0
  83. package/packages/core/src/google/config.ts +60 -0
  84. package/packages/core/src/google/google.test.ts +287 -0
  85. package/packages/core/src/google/index.ts +5 -0
  86. package/packages/core/src/google/oauth.ts +144 -0
  87. package/packages/core/src/google/scopes.ts +41 -0
  88. package/packages/core/src/google/token-store.ts +33 -0
  89. package/packages/core/src/multimodal/attachment-ingest.ts +19 -4
  90. package/packages/core/src/multimodal/image-generation.ts +244 -0
  91. package/packages/core/src/storage/collections.ts +8 -8
  92. package/packages/core/src/storage/google-capabilities.ts +91 -0
  93. package/packages/core/src/storage/model-activation.ts +18 -0
  94. package/packages/core/src/storage/model-sync.ts +66 -14
  95. package/packages/core/src/storage/onboarding.ts +10 -2
  96. package/packages/core/src/storage/seed.ts +81 -18
  97. package/packages/core/src/storage/usage.ts +0 -52
  98. package/packages/core/src/tools/agents/get-available-models.ts +1 -3
  99. package/packages/core/src/tools/core/index.ts +1 -1
  100. package/packages/core/src/tools/google/calendar.ts +204 -0
  101. package/packages/core/src/tools/google/drive.ts +160 -0
  102. package/packages/core/src/tools/google/gmail.ts +579 -0
  103. package/packages/core/src/tools/google/index.ts +18 -0
  104. package/packages/core/src/tools/google/shared.ts +80 -0
  105. package/packages/core/src/tools/image/image-generate.ts +90 -0
  106. package/packages/core/src/tools/image/index.ts +13 -0
  107. package/packages/core/src/tools/image/office-leer-imagenes.ts +198 -0
  108. package/packages/core/src/tools/index.ts +27 -0
  109. package/packages/core/src/tools/office/office-images.ts +137 -0
  110. package/packages/core/src/tools/office/office-leer-docx.ts +10 -1
  111. package/packages/core/src/tools/office/office-leer-pdf.ts +1 -1
  112. package/packages/core/src/tools/office/office-leer-pptx.ts +4 -1
  113. package/packages/core/src/tools/office/office-pdf-images.ts +225 -0
  114. package/packages/core/src/tools/office/pdf-text.ts +2 -2
  115. package/packages/core/src/tools/web/browser-screenshot.ts +7 -0
  116. package/packages/core/src/voice/index.ts +123 -155
  117. package/packages/core/src/voice/local-model.ts +8 -0
  118. package/packages/core/src/voice/stt-models.ts +39 -0
  119. package/packages/skills/src/bundled/google/google_calendar/SKILL.md +51 -0
  120. package/packages/skills/src/bundled/google/google_drive/SKILL.md +50 -0
  121. package/packages/skills/src/bundled/google/google_gmail/SKILL.md +61 -0
  122. package/packages/skills/src/bundled-data.generated.ts +45 -0
  123. package/dist/ui/assets/AgentDetailPage-CyYbqzHr.js +0 -1
  124. package/dist/ui/assets/AgentsPage-CEWNs4Lt.js +0 -10
  125. package/dist/ui/assets/ChannelsPage-CmeXP-hI.js +0 -8
  126. package/dist/ui/assets/DashboardPage-C3z4kZXD.js +0 -6
  127. package/dist/ui/assets/LoginPage-DDisP8hm.js +0 -1
  128. package/dist/ui/assets/MeetingPage-CKyjxtFr.js +0 -1
  129. package/dist/ui/assets/ModelSelector-VVwpDrYF.js +0 -1
  130. package/dist/ui/assets/Office3DPage-CYxB6z2p.js +0 -727
  131. package/dist/ui/assets/ProvidersPage-CM9-E-Pf.js +0 -1
  132. package/dist/ui/assets/SettingsPage-BvD-vs5g.js +0 -9
  133. package/dist/ui/assets/VoicePage-CmudxYny.js +0 -307
  134. package/dist/ui/assets/WebChatPage-CnoXpEOl.js +0 -29
  135. package/dist/ui/assets/dist-js-jWCEHSkB.js +0 -1
  136. package/dist/ui/assets/index-C0W6p0lk.js +0 -156
  137. package/dist/ui/assets/index-DmFPF9xQ.css +0 -2
  138. package/dist/ui/assets/lock-open-v0EphssG.js +0 -1
  139. package/dist/ui/assets/select-v_3QBYrD.js +0 -1
  140. package/dist/ui/assets/terminal-BEcTK780.js +0 -1
  141. package/dist/ui/assets/useOfficeModel-BaDn7U-X.js +0 -1
  142. package/dist/ui/assets/vendor-router-DSMCk-Ka.js +0 -3
  143. package/packages/core/src/agent/jev-decisions.ts +0 -242
  144. package/packages/core/src/agent/jev-planner.ts +0 -293
  145. package/packages/core/src/gateway/tts/package.json +0 -25
  146. package/packages/core/src/gateway/tts/src/client.ts +0 -59
  147. package/packages/core/src/gateway/tts/src/index.ts +0 -15
  148. package/packages/core/src/gateway/tts/src/install.ts +0 -137
  149. package/packages/core/src/gateway/tts/src/models.ts +0 -50
  150. package/packages/core/src/gateway/tts/src/server.ts +0 -253
  151. /package/dist/ui/assets/{core-p4c5dns5.js → core-npANj14X.js} +0 -0
  152. /package/dist/ui/assets/{download-BQXrpH0m.js → download-D0aDV8Y_.js} +0 -0
  153. /package/dist/ui/assets/{ellipsis-vertical-D7uFJLGh.js → ellipsis-vertical-BOW_iEOO.js} +0 -0
  154. /package/dist/ui/assets/{external-link-6oTH9pUM.js → external-link-DNJH7epD.js} +0 -0
  155. /package/dist/ui/assets/{eye-CxvxtQT5.js → eye-BVfTWOME.js} +0 -0
  156. /package/dist/ui/assets/{file-text-D5ZJEx3E.js → file-text-ByqNMpXm.js} +0 -0
  157. /package/dist/ui/assets/{gateway-url-BALS_wVh.js → gateway-url-BzQV75Ig.js} +0 -0
  158. /package/dist/ui/assets/{gauge-CEu7PhTW.js → gauge-CB4np0Vz.js} +0 -0
  159. /package/dist/ui/assets/{history-DLK5rTlP.js → history-CbhJX41s.js} +0 -0
  160. /package/dist/ui/assets/{info-8ReWzubE.js → info-BCD3-QX9.js} +0 -0
  161. /package/dist/ui/assets/{lock-3IApZyVy.js → lock-DpBean4K.js} +0 -0
  162. /package/dist/ui/assets/{mail-vwCEHyhQ.js → mail-Biwn8WrV.js} +0 -0
  163. /package/dist/ui/assets/{mic-CpDU_2as.js → mic-Rq4BxU1R.js} +0 -0
  164. /package/dist/ui/assets/{pause-BAMsNQkh.js → pause-87NGXbsz.js} +0 -0
  165. /package/dist/ui/assets/{pencil-CKritjT_.js → pencil-BG8EFaS3.js} +0 -0
  166. /package/dist/ui/assets/{play-Cwpe4tp6.js → play-D3De6YsQ.js} +0 -0
  167. /package/dist/ui/assets/{plus-RD44ce15.js → plus-Bp8-V68t.js} +0 -0
  168. /package/dist/ui/assets/{radio-lFPMHi6-.js → radio-m7rzuDKK.js} +0 -0
  169. /package/dist/ui/assets/{refresh-cw-DtJMHRHO.js → refresh-cw-D6F1zoC6.js} +0 -0
  170. /package/dist/ui/assets/{rotate-ccw-b3E_4PoX.js → rotate-ccw-DUlEC1_D.js} +0 -0
  171. /package/dist/ui/assets/{search-z2oZt00P.js → search-CfNwwpMW.js} +0 -0
  172. /package/dist/ui/assets/{send-CpoY_2F-.js → send-CI868CBV.js} +0 -0
  173. /package/dist/ui/assets/{settings-qV3kVkeG.js → settings-AEM2uWiD.js} +0 -0
  174. /package/dist/ui/assets/{shield-CIarwBvx.js → shield-DvVIcbzd.js} +0 -0
  175. /package/dist/ui/assets/{sparkles-DVvY6jDT.js → sparkles-DRe4GbSH.js} +0 -0
  176. /package/dist/ui/assets/{square-D5zdNkAY.js → square-DTWkjTT3.js} +0 -0
  177. /package/dist/ui/assets/{trash-2-D6oziYAK.js → trash-2-BZsMCfso.js} +0 -0
  178. /package/dist/ui/assets/{utils-DEmd_M8c.js → utils-lc8H6VGT.js} +0 -0
  179. /package/dist/ui/assets/{volume-2-EaA0JRvD.js → volume-2-CBMYsuF3.js} +0 -0
  180. /package/dist/ui/assets/{volume-x-CROXNMGT.js → volume-x-vNFf2e4-.js} +0 -0
  181. /package/dist/ui/assets/{wifi-BUJuOcgP.js → wifi-DNv53AfN.js} +0 -0
  182. /package/dist/ui/assets/{zap-DSoX9NDk.js → zap-Yed86Sh8.js} +0 -0
@@ -1,25 +0,0 @@
1
- {
2
- "name": "@johpaz/hive-tts",
3
- "version": "0.1.0",
4
- "description": "Offline local TTS for Hive — Piper-based fallback when no internet providers available",
5
- "module": "src/index.ts",
6
- "main": "src/index.ts",
7
- "type": "module",
8
- "exports": {
9
- ".": "./src/index.ts",
10
- "./client": "./src/client.ts",
11
- "./server": "./src/server.ts",
12
- "./models": "./src/models.ts"
13
- },
14
- "scripts": {
15
- "postinstall": "bun run src/install.ts",
16
- "start": "bun run src/server.ts",
17
- "dev": "bun --watch src/server.ts"
18
- },
19
- "dependencies": {},
20
- "devDependencies": {
21
- "typescript": "^5.0.0"
22
- },
23
- "keywords": ["hive", "tts", "offline", "piper", "voice", "spanish"],
24
- "license": "MIT"
25
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * Hive TTS Client
3
- * No bloqueante: si TTS no está disponible, las funciones retornan null silenciosamente.
4
- */
5
-
6
- const TTS_URL = process.env.TTS_URL ?? "http://localhost:5500"
7
-
8
- export async function isTTSAvailable(): Promise<boolean> {
9
- try {
10
- const res = await fetch(`${TTS_URL}/health`, {
11
- signal: AbortSignal.timeout(500),
12
- })
13
- return res.ok
14
- } catch {
15
- return false
16
- }
17
- }
18
-
19
- export async function synthesize(
20
- text: string,
21
- voice?: string
22
- ): Promise<ArrayBuffer | null> {
23
- try {
24
- const res = await fetch(`${TTS_URL}/tts`, {
25
- method: "POST",
26
- headers: { "Content-Type": "application/json" },
27
- body: JSON.stringify({ text, voice }),
28
- signal: AbortSignal.timeout(10_000),
29
- })
30
- if (!res.ok) return null
31
- return res.arrayBuffer()
32
- } catch {
33
- return null
34
- }
35
- }
36
-
37
- export async function synthesizeToFile(
38
- text: string,
39
- outputPath: string,
40
- voice?: string
41
- ): Promise<boolean> {
42
- const audio = await synthesize(text, voice)
43
- if (!audio) return false
44
- await Bun.write(outputPath, audio)
45
- return true
46
- }
47
-
48
- export async function listVoices(): Promise<string[]> {
49
- try {
50
- const res = await fetch(`${TTS_URL}/voices`, {
51
- signal: AbortSignal.timeout(500),
52
- })
53
- if (!res.ok) return []
54
- const data = await res.json()
55
- return data.voices ?? []
56
- } catch {
57
- return []
58
- }
59
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * @johpaz/hive-tts
3
- *
4
- * Paquete standalone opcional para síntesis de voz offline en Hive.
5
- * Fallback local cuando no hay internet o no hay providers configurados.
6
- *
7
- * Iniciar servidor:
8
- * bun run packages/core/src/gateway/tts/src/server.ts
9
- *
10
- * Uso:
11
- * import { isTTSAvailable, synthesize } from "@johpaz/hive-tts/client"
12
- */
13
-
14
- export * from "./client.js"
15
- export { detectPlatform } from "./detect.js"
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * Hive TTS — instalador de Piper
4
- * Los datos se guardan en $HIVE_HOME/tts/ (por defecto ~/.hive/tts/).
5
- */
6
-
7
- import { existsSync, mkdirSync, readdirSync, renameSync, unlinkSync, rmSync } from "fs"
8
- import { join } from "path"
9
- import { homedir } from "os"
10
- import {
11
- detectPlatform,
12
- PIPER_URLS,
13
- VOICE_URLS,
14
- getPiperBinaryName,
15
- DEFAULT_VOICE,
16
- } from "./detect.js"
17
-
18
- const log = {
19
- info: (msg: string) => console.log(`[TTS] ${msg}`),
20
- warn: (msg: string) => console.warn(`[TTS] ${msg}`),
21
- error: (msg: string) => console.error(`[TTS] ${msg}`),
22
- }
23
-
24
- async function downloadFile(url: string, dest: string): Promise<void> {
25
- const filename = url.split("/").pop()!
26
- log.info(`Descargando ${filename}...`)
27
- const res = await fetch(url)
28
- if (!res.ok) throw new Error(`HTTP ${res.status} al descargar ${url}`)
29
- const buf = await res.arrayBuffer()
30
- await Bun.write(dest, buf)
31
- log.info(`${filename} — ${(buf.byteLength / 1024 / 1024).toFixed(1)} MB`)
32
- }
33
-
34
- async function extractTarGz(archivePath: string, destDir: string): Promise<void> {
35
- const code = await Bun.spawn(["tar", "-xzf", archivePath, "-C", destDir], {
36
- stdout: "inherit",
37
- stderr: "inherit",
38
- }).exited
39
- if (code !== 0) throw new Error(`tar falló con código ${code}`)
40
- unlinkSync(archivePath)
41
- }
42
-
43
- async function extractZip(archivePath: string, destDir: string): Promise<void> {
44
- let code: number
45
- if (process.platform === "win32") {
46
- code = await Bun.spawn(
47
- ["powershell", "-Command", `Expand-Archive -Path "${archivePath}" -DestinationPath "${destDir}" -Force`],
48
- { stdout: "inherit", stderr: "inherit" }
49
- ).exited
50
- } else {
51
- code = await Bun.spawn(["unzip", "-q", archivePath, "-d", destDir], {
52
- stdout: "inherit",
53
- stderr: "inherit",
54
- }).exited
55
- }
56
- if (code !== 0) throw new Error(`Extracción ZIP falló con código ${code}`)
57
- unlinkSync(archivePath)
58
- }
59
-
60
- /**
61
- * Instala Piper TTS en el directorio indicado.
62
- * Exportado para llamarse inline desde el gateway sin necesidad de un script externo.
63
- */
64
- export async function runInstall(ttsRoot: string): Promise<void> {
65
- const BIN_DIR = join(ttsRoot, "bin")
66
- const VOICES_DIR = join(ttsRoot, "voices")
67
-
68
- mkdirSync(BIN_DIR, { recursive: true })
69
- mkdirSync(VOICES_DIR, { recursive: true })
70
-
71
- // ── Piper binary ──────────────────────────────────────────────────────────
72
- const platform = detectPlatform()
73
- const binaryName = getPiperBinaryName(platform)
74
- const binaryPath = join(BIN_DIR, binaryName)
75
-
76
- if (!existsSync(binaryPath)) {
77
- const url = PIPER_URLS[platform]
78
- const archiveExt = url.endsWith(".zip") ? ".zip" : ".tar.gz"
79
- const archivePath = join(BIN_DIR, `piper${archiveExt}`)
80
-
81
- log.info(`Instalando Piper para ${platform}...`)
82
- await downloadFile(url, archivePath)
83
- log.info("Extrayendo...")
84
- if (archiveExt === ".zip") {
85
- await extractZip(archivePath, BIN_DIR)
86
- } else {
87
- await extractTarGz(archivePath, BIN_DIR)
88
- }
89
-
90
- const piperSubdir = join(BIN_DIR, "piper")
91
- if (existsSync(piperSubdir)) {
92
- const tempDir = join(BIN_DIR, "_piper_tmp")
93
- renameSync(piperSubdir, tempDir)
94
- for (const entry of readdirSync(tempDir)) {
95
- renameSync(join(tempDir, entry), join(BIN_DIR, entry))
96
- }
97
- rmSync(tempDir, { recursive: true, force: true })
98
- }
99
-
100
- if (!existsSync(binaryPath)) {
101
- throw new Error(`Binario no encontrado tras extracción: ${binaryPath}`)
102
- }
103
- if (!platform.startsWith("windows")) {
104
- await Bun.spawn(["chmod", "+x", binaryPath]).exited
105
- }
106
- log.info(`Piper instalado en ${BIN_DIR}`)
107
- } else {
108
- log.info("Piper ya instalado, omitiendo descarga.")
109
- }
110
-
111
- // ── Voice model ───────────────────────────────────────────────────────────
112
- const modelPath = join(VOICES_DIR, `${DEFAULT_VOICE}.onnx`)
113
- const configPath = join(VOICES_DIR, `${DEFAULT_VOICE}.onnx.json`)
114
-
115
- if (!existsSync(modelPath) || !existsSync(configPath)) {
116
- log.info(`Descargando modelo de voz ${DEFAULT_VOICE}...`)
117
- await downloadFile(VOICE_URLS.model, modelPath)
118
- await downloadFile(VOICE_URLS.config, configPath)
119
- log.info(`Voz instalada en ${VOICES_DIR}`)
120
- } else {
121
- log.info("Modelo de voz ya instalado, omitiendo descarga.")
122
- }
123
-
124
- log.info("Hive TTS listo.")
125
- }
126
-
127
- // Ejecución directa: bun run src/install.ts
128
- // @ts-ignore
129
- if (import.meta.main) {
130
- const ttsRoot =
131
- process.env.HIVE_TTS_ROOT ??
132
- join(process.env.HIVE_HOME ?? join(homedir(), ".hive"), "tts")
133
- runInstall(ttsRoot).catch((err) => {
134
- log.error(`Hive TTS no pudo instalarse: ${err instanceof Error ? err.message : err}`)
135
- process.exit(1)
136
- })
137
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Hive TTS — Índice de modelos disponibles
3
- * Modelos en español desde HuggingFace
4
- */
5
-
6
- export interface TTSModel {
7
- id: string
8
- name: string
9
- language: string
10
- quality: "low" | "medium" | "high"
11
- size: string
12
- modelUrl: string
13
- configUrl: string
14
- }
15
-
16
- const HF_BASE = "https://huggingface.co/spaces/HirCoir/Piper-TTS-Spanish/resolve/main"
17
-
18
- export const TTS_MODELS: TTSModel[] = [
19
- {
20
- id: "es_MX-claude-14947-epoch-high",
21
- name: "Claude (México)",
22
- language: "es-MX",
23
- quality: "high",
24
- size: "63.1 MB",
25
- modelUrl: `${HF_BASE}/es_MX-claude-14947-epoch-high.onnx`,
26
- configUrl: `${HF_BASE}/es_MX-claude-14947-epoch-high.onnx.json`,
27
- },
28
- {
29
- id: "es_MX-cortana-19669-epoch-high",
30
- name: "Cortana (México)",
31
- language: "es-MX",
32
- quality: "high",
33
- size: "63.1 MB",
34
- modelUrl: `${HF_BASE}/es_MX-cortana-19669-epoch-high.onnx`,
35
- configUrl: `${HF_BASE}/es_MX-cortana-19669-epoch-high.onnx.json`,
36
- },
37
- {
38
- id: "es_MX-gevy-10196-epoch-high",
39
- name: "Gevy (México)",
40
- language: "es-MX",
41
- quality: "high",
42
- size: "63.1 MB",
43
- modelUrl: `${HF_BASE}/es_MX-gevy-10196-epoch-high.onnx`,
44
- configUrl: `${HF_BASE}/es_MX-gevy-10196-epoch-high.onnx.json`,
45
- },
46
- ]
47
-
48
- export function getModelById(id: string): TTSModel | undefined {
49
- return TTS_MODELS.find((m) => m.id === id)
50
- }
@@ -1,253 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * Hive TTS Server
4
- * HTTP server local que expone Piper TTS como API REST
5
- * Puerto: 5500 (configurable con env TTS_PORT)
6
- *
7
- * GET /health → { ok: true, voice: string, voices: string[] }
8
- * POST /tts → audio/wav binary
9
- * GET /voices → { voices: string[] }
10
- */
11
-
12
- import { resolvePort } from "../../../utils/port";
13
- import { existsSync, readdirSync, readFileSync } from "fs"
14
- import { join } from "path"
15
- import { homedir } from "os"
16
- import { detectPlatform, getPiperBinaryName, DEFAULT_VOICE } from "./detect.js"
17
-
18
- const log = {
19
- info: (msg: string) => console.log(`[TTS] ${msg}`),
20
- warn: (msg: string) => console.warn(`[TTS] ${msg}`),
21
- error: (msg: string) => console.error(`[TTS] ${msg}`),
22
- }
23
-
24
- const TTS_ROOT =
25
- process.env.HIVE_TTS_ROOT ??
26
- join(process.env.HIVE_HOME ?? join(homedir(), ".hive"), "tts")
27
- const BIN_DIR = join(TTS_ROOT, "bin")
28
- const VOICES_DIR = join(TTS_ROOT, "voices")
29
- const PORT = resolvePort(process.env.TTS_PORT, 5500)
30
- const DEFAULT_VOICE_ENV = process.env.TTS_VOICE ?? DEFAULT_VOICE
31
-
32
- function getPiperPath(): string {
33
- const platform = detectPlatform()
34
- const binaryName = getPiperBinaryName(platform)
35
- const binaryPath = join(BIN_DIR, binaryName)
36
-
37
- if (!existsSync(binaryPath)) {
38
- throw new Error("Piper no instalado. Ejecuta: bun run src/install.ts")
39
- }
40
- return binaryPath
41
- }
42
-
43
- function listVoices(): string[] {
44
- if (!existsSync(VOICES_DIR)) return []
45
- return readdirSync(VOICES_DIR)
46
- .filter((f) => f.endsWith(".onnx"))
47
- .map((f) => f.replace(".onnx", ""))
48
- }
49
-
50
- async function synthesize(text: string, voice: string): Promise<ArrayBuffer> {
51
- const piperPath = getPiperPath()
52
- let modelPath = join(VOICES_DIR, `${voice}.onnx`)
53
- let configPath = join(VOICES_DIR, `${voice}.onnx.json`)
54
-
55
- if (!existsSync(modelPath)) {
56
- console.warn(`[TTS] Voz no encontrada: ${voice}. Usando por defecto: ${DEFAULT_VOICE}`);
57
- voice = DEFAULT_VOICE;
58
- modelPath = join(VOICES_DIR, `${voice}.onnx`);
59
- configPath = join(VOICES_DIR, `${voice}.onnx.json`);
60
-
61
- if (!existsSync(modelPath)) {
62
- throw new Error(`Ni siquiera la voz por defecto se encuentra: ${voice}`);
63
- }
64
- }
65
-
66
- // Leer configuración del modelo para obtener parámetros de inferencia
67
- let lengthScale = 0.95 // Más lento = más natural
68
- let noiseScale = 0.6 // Menos variación = más consistente
69
- let noiseW = 0.75 // Más suave = menos artefactos
70
- let sentenceSilence = 0.2 // Pausa entre frases para naturalidad
71
-
72
- if (existsSync(configPath)) {
73
- try {
74
- const config = JSON.parse(readFileSync(configPath, "utf-8"))
75
- const inference = config.inference || {}
76
-
77
- // Usar valores del modelo con ajustes para mejorar naturalidad
78
- lengthScale = (inference.length_scale ?? 1) * 0.95
79
- noiseScale = (inference.noise_scale ?? 0.667) * 0.9
80
- noiseW = (inference.noise_w ?? 0.8) * 0.95
81
- } catch (err) {
82
- log.warn(`No se pudo leer configuración del modelo: ${err}`)
83
- }
84
- }
85
-
86
- // Sobrescribir con variables de entorno si existen
87
- lengthScale = Number(process.env.PIPER_LENGTH_SCALE ?? lengthScale)
88
- noiseScale = Number(process.env.PIPER_NOISE_SCALE ?? noiseScale)
89
- noiseW = Number(process.env.PIPER_NOISE_W ?? noiseW)
90
- sentenceSilence = Number(process.env.PIPER_SENTENCE_SILENCE ?? sentenceSilence)
91
-
92
- const args = [
93
- piperPath,
94
- "--model", modelPath,
95
- "--output-raw",
96
- "--length_scale", String(lengthScale),
97
- "--noise_scale", String(noiseScale),
98
- "--noise_w", String(noiseW),
99
- "--sentence_silence", String(sentenceSilence),
100
- ]
101
-
102
- const proc = Bun.spawn(
103
- args,
104
- {
105
- stdin: "pipe",
106
- stdout: "pipe",
107
- stderr: "pipe",
108
- }
109
- )
110
-
111
- proc.stdin.write(new TextEncoder().encode(text))
112
- proc.stdin.end()
113
-
114
- const [audioBuffer, exitCode] = await Promise.all([
115
- new Response(proc.stdout).arrayBuffer(),
116
- proc.exited,
117
- ])
118
-
119
- if (exitCode !== 0) {
120
- const errText = await new Response(proc.stderr).text()
121
- throw new Error(`Piper error (exit ${exitCode}): ${errText}`)
122
- }
123
-
124
- // --output-raw devuelve PCM 16-bit LE 22050Hz mono — envolver en WAV header
125
- return wrapInWav(audioBuffer, 22050, 1, 16)
126
- }
127
-
128
- function wrapInWav(
129
- pcm: ArrayBuffer,
130
- sampleRate: number,
131
- channels: number,
132
- bitsPerSample: number
133
- ): ArrayBuffer {
134
- const dataSize = pcm.byteLength
135
- const header = new ArrayBuffer(44)
136
- const view = new DataView(header)
137
-
138
- const writeStr = (offset: number, str: string) => {
139
- for (let i = 0; i < str.length; i++)
140
- view.setUint8(offset + i, str.charCodeAt(i))
141
- }
142
-
143
- writeStr(0, "RIFF")
144
- view.setUint32(4, 36 + dataSize, true)
145
- writeStr(8, "WAVE")
146
- writeStr(12, "fmt ")
147
- view.setUint32(16, 16, true)
148
- view.setUint16(20, 1, true) // PCM
149
- view.setUint16(22, channels, true)
150
- view.setUint32(24, sampleRate, true)
151
- view.setUint32(28, (sampleRate * channels * bitsPerSample) / 8, true)
152
- view.setUint16(32, (channels * bitsPerSample) / 8, true)
153
- view.setUint16(34, bitsPerSample, true)
154
- writeStr(36, "data")
155
- view.setUint32(40, dataSize, true)
156
-
157
- const wav = new Uint8Array(44 + dataSize)
158
- wav.set(new Uint8Array(header), 0)
159
- wav.set(new Uint8Array(pcm), 44)
160
- return wav.buffer
161
- }
162
-
163
- const CORS = {
164
- "Access-Control-Allow-Origin": "*",
165
- "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
166
- "Access-Control-Allow-Headers": "Content-Type",
167
- }
168
-
169
- /**
170
- * Inicia el servidor TTS en-proceso.
171
- * Exportado para que el gateway pueda llamarlo directamente
172
- * sin necesidad de spawnar un subproceso externo.
173
- */
174
- export function startTTSServer(opts?: { port?: number }): ReturnType<typeof Bun.serve> {
175
- const listenPort = opts?.port ?? PORT
176
-
177
- const server = Bun.serve({
178
- port: listenPort,
179
- async fetch(req) {
180
- const url = new URL(req.url)
181
-
182
- if (req.method === "OPTIONS") {
183
- return new Response(null, { status: 204, headers: CORS })
184
- }
185
-
186
- if (req.method === "GET" && url.pathname === "/health") {
187
- return Response.json(
188
- { ok: true, voice: DEFAULT_VOICE_ENV, voices: listVoices() },
189
- { headers: CORS }
190
- )
191
- }
192
-
193
- if (req.method === "GET" && url.pathname === "/voices") {
194
- return Response.json({ voices: listVoices() }, { headers: CORS })
195
- }
196
-
197
- if (req.method === "POST" && url.pathname === "/tts") {
198
- let body: { text?: string; voice?: string }
199
- try {
200
- body = await req.json()
201
- } catch {
202
- return Response.json(
203
- { error: "Body JSON inválido" },
204
- { status: 400, headers: CORS }
205
- )
206
- }
207
-
208
- const { text, voice = DEFAULT_VOICE_ENV } = body
209
-
210
- if (!text || typeof text !== "string" || text.trim().length === 0) {
211
- return Response.json(
212
- { error: "Campo 'text' requerido" },
213
- { status: 400, headers: CORS }
214
- )
215
- }
216
-
217
- if (text.length > 2000) {
218
- return Response.json(
219
- { error: "Texto demasiado largo (máx 2000 chars)" },
220
- { status: 400, headers: CORS }
221
- )
222
- }
223
-
224
- try {
225
- const audio = await synthesize(text.trim(), voice)
226
- return new Response(audio, {
227
- headers: {
228
- ...CORS,
229
- "Content-Type": "audio/wav",
230
- "Content-Length": String(audio.byteLength),
231
- },
232
- })
233
- } catch (err) {
234
- const message = err instanceof Error ? err.message : "Error interno"
235
- return Response.json({ error: message }, { status: 500, headers: CORS })
236
- }
237
- }
238
-
239
- return Response.json({ error: "Not found" }, { status: 404, headers: CORS })
240
- },
241
- })
242
-
243
- log.info(`Hive TTS Server escuchando en http://localhost:${listenPort}`)
244
- log.info(`Voz por defecto: ${DEFAULT_VOICE_ENV}`)
245
- log.info(`Voces disponibles: ${listVoices().join(", ") || "ninguna (ejecuta install.ts primero)"}`)
246
- return server
247
- }
248
-
249
- // Ejecución directa: bun run src/server.ts
250
- // @ts-ignore
251
- if (import.meta.main) {
252
- startTTSServer()
253
- }