@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.
- package/README.md +4 -10
- package/dist/hive.js +218257 -148718
- package/dist/tool-worker.js +68422 -1622
- package/dist/ui/assets/{A2UIPage-Dr3p75oE.js → A2UIPage-v-VggXW3.js} +4 -4
- package/dist/ui/assets/{AgentCreateForm-DqYhH_gm.js → AgentCreateForm-Dr1l4Cvg.js} +1 -1
- package/dist/ui/assets/AgentDetailPage-Dsh_grrr.js +1 -0
- package/dist/ui/assets/{AgentNewPage-BRpFxJIT.js → AgentNewPage-D7557C0J.js} +1 -1
- package/dist/ui/assets/AgentsPage-C_Z56LL1.js +10 -0
- package/dist/ui/assets/{ApiClientPage-R9UDWfR2.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-DICMU_7m.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-Blms3NBa.js → RecoverPage-B6qvBBIl.js} +1 -1
- package/dist/ui/assets/SettingsPage-Br4PfWuc.js +9 -0
- package/dist/ui/assets/{SetupPage-CAjLseE_.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-DhM07qYi.js → conversationsStore-D6XgjMr1.js} +1 -1
- package/dist/ui/assets/{dialog-BP3GTCPn.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-zj0fuGwZ.js → useAudioDevices-wZArmV3m.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-Cd9p-bjs.js → useHiveAgentsModelLoad-CqJkzTOT.js} +1 -1
- package/dist/ui/assets/useOfficeModel-DZvwZRCw.js +1 -0
- package/dist/ui/assets/{useProviders-Dj1k5PCk.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/cli/src/commands/onboard.ts +3 -2
- 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/minimal-loadout.ts +1 -0
- package/packages/core/src/agent/prompt-builder.ts +17 -1
- package/packages/core/src/agent/tool-selector.ts +12 -0
- package/packages/core/src/artifacts/store.ts +73 -9
- package/packages/core/src/canvas/emitter.ts +0 -19
- package/packages/core/src/channels/base.ts +26 -0
- package/packages/core/src/channels/discord.ts +18 -2
- package/packages/core/src/channels/slack.ts +37 -7
- package/packages/core/src/channels/telegram.ts +39 -11
- package/packages/core/src/channels/whatsapp.ts +16 -1
- package/packages/core/src/gateway/channel-notify.ts +42 -0
- 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/artifacts.ts +4 -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 +38 -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 +97 -48
- 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/gateway/webchat-turn.ts +15 -13
- 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 +190 -0
- package/packages/core/src/multimodal/image-generation.ts +244 -0
- package/packages/core/src/multimodal/vision-analyzer.ts +94 -0
- package/packages/core/src/multimodal/vision-service.ts +25 -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 +107 -24
- package/packages/core/src/storage/usage.ts +0 -52
- package/packages/core/src/tool-runtime/index.ts +2 -0
- package/packages/core/src/tools/agents/get-available-models.ts +1 -3
- package/packages/core/src/tools/core/index.ts +80 -2
- 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/index.ts +9 -0
- package/packages/core/src/tools/office/office-editar-docx.ts +184 -0
- package/packages/core/src/tools/office/office-editar-pptx.ts +126 -0
- package/packages/core/src/tools/office/office-editar-xlsx.ts +122 -0
- package/packages/core/src/tools/office/office-escribir-docx.ts +3 -2
- package/packages/core/src/tools/office/office-escribir-pdf.ts +3 -2
- package/packages/core/src/tools/office/office-escribir-pptx.ts +3 -2
- package/packages/core/src/tools/office/office-escribir-xlsx.ts +3 -2
- package/packages/core/src/tools/office/office-images.ts +137 -0
- package/packages/core/src/tools/office/office-leer-docx.ts +16 -3
- package/packages/core/src/tools/office/office-leer-pdf.ts +41 -57
- package/packages/core/src/tools/office/office-leer-pptx.ts +54 -88
- package/packages/core/src/tools/office/office-leer-xlsx.ts +6 -2
- package/packages/core/src/tools/office/office-pdf-images.ts +225 -0
- package/packages/core/src/tools/office/pdf-text.ts +186 -0
- package/packages/core/src/tools/office/pptx-slides.ts +83 -0
- package/packages/core/src/tools/office/resolve-input.ts +49 -0
- 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-BVtE88U5.js +0 -1
- package/dist/ui/assets/AgentsPage-BOIJ55cj.js +0 -10
- package/dist/ui/assets/ChannelsPage-C5V2BmjL.js +0 -8
- package/dist/ui/assets/DashboardPage-B18gMzNj.js +0 -6
- package/dist/ui/assets/LoginPage-nrsYF9AY.js +0 -1
- package/dist/ui/assets/MeetingPage-xslJGfIz.js +0 -1
- package/dist/ui/assets/ModelSelector-BX4IvuYY.js +0 -1
- package/dist/ui/assets/Office3DPage-a6cuzt5X.js +0 -727
- package/dist/ui/assets/ProvidersPage-C8-xGoeh.js +0 -1
- package/dist/ui/assets/SettingsPage-BBeeq_QS.js +0 -9
- package/dist/ui/assets/VoicePage-BeSSYstD.js +0 -307
- package/dist/ui/assets/WebChatPage-Bat7uUfd.js +0 -29
- package/dist/ui/assets/dist-js-jWCEHSkB.js +0 -1
- package/dist/ui/assets/index-BG3nUPKq.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
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracción de texto de PDF sin modelos: solo la capa de texto del archivo
|
|
3
|
+
* (pdfjs). Reconstruye renglones y columnas a partir de las posiciones, en vez
|
|
4
|
+
* de aplastar todo en una línea, para que tablas y párrafos sigan legibles.
|
|
5
|
+
*
|
|
6
|
+
* Un PDF escaneado no tiene capa de texto: aquí se informa como tal
|
|
7
|
+
* (`sinTexto`) y no se intenta adivinar con un modelo.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface PdfTextResult {
|
|
11
|
+
totalPaginas: number
|
|
12
|
+
paginasLeidas: number
|
|
13
|
+
titulo?: string
|
|
14
|
+
texto: string
|
|
15
|
+
/** Caracteres de texto por página leída (sirve para ver cuáles están vacías). */
|
|
16
|
+
caracteresPorPagina: number[]
|
|
17
|
+
/** true si ninguna de las páginas leídas tiene texto extraíble (PDF escaneado o solo imágenes). */
|
|
18
|
+
sinTexto: boolean
|
|
19
|
+
/** true si se cortó por el tope de caracteres. */
|
|
20
|
+
truncado: boolean
|
|
21
|
+
/** Primera página que no se llegó a leer (para continuar), si hubo corte o rango. */
|
|
22
|
+
siguientePagina?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MAX_PDF_BYTES = 100 * 1024 * 1024
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* pdfjs v5 sin worker real monta uno "falso" en el mismo hilo, y para eso exige
|
|
29
|
+
* `workerSrc` no vacío o el módulo ya cargado en `globalThis.pdfjsWorker`. Dejar
|
|
30
|
+
* `workerSrc = ""` (como hacía la tool) lo rompe: "No GlobalWorkerOptions.workerSrc
|
|
31
|
+
* specified". Registrar el módulo evita depender de rutas de archivo, que además
|
|
32
|
+
* cambian en el binario empaquetado.
|
|
33
|
+
*/
|
|
34
|
+
let workerListo = false
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* pdfjs hace referencia a DOMMatrix, ImageData y Path2D al cargarse. En desarrollo se
|
|
38
|
+
* las presta `@napi-rs/canvas`, pero en el ejecutable compilado (app de escritorio,
|
|
39
|
+
* paquete) ese módulo no existe y la carga muere con «DOMMatrix is not defined». Para
|
|
40
|
+
* extraer texto no hace falta dibujar nada: bastan clases mínimas, solo si faltan.
|
|
41
|
+
*/
|
|
42
|
+
export function instalarPolyfillsPdf(): void {
|
|
43
|
+
const g = globalThis as any
|
|
44
|
+
if (typeof g.DOMMatrix === "undefined") {
|
|
45
|
+
g.DOMMatrix = class DOMMatrix {
|
|
46
|
+
a = 1; b = 0; c = 0; d = 1; e = 0; f = 0
|
|
47
|
+
constructor(init?: ArrayLike<number> | string) {
|
|
48
|
+
if (init && typeof init !== "string" && init.length >= 6) {
|
|
49
|
+
[this.a, this.b, this.c, this.d, this.e, this.f] = Array.from(init)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
multiplySelf(): this { return this }
|
|
53
|
+
preMultiplySelf(): this { return this }
|
|
54
|
+
translateSelf(): this { return this }
|
|
55
|
+
scaleSelf(): this { return this }
|
|
56
|
+
invertSelf(): this { return this }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (typeof g.ImageData === "undefined") {
|
|
60
|
+
g.ImageData = class ImageData { constructor(public width = 0, public height = 0, public data: Uint8ClampedArray = new Uint8ClampedArray(0)) {} }
|
|
61
|
+
}
|
|
62
|
+
if (typeof g.Path2D === "undefined") {
|
|
63
|
+
g.Path2D = class Path2D {}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function registrarWorker(lib: any): Promise<void> {
|
|
68
|
+
if (workerListo) return
|
|
69
|
+
const g = globalThis as any
|
|
70
|
+
if (!g.pdfjsWorker) {
|
|
71
|
+
g.pdfjsWorker = await import("pdfjs-dist/legacy/build/pdf.worker.mjs" as any)
|
|
72
|
+
}
|
|
73
|
+
if (lib.GlobalWorkerOptions && !lib.GlobalWorkerOptions.workerSrc) {
|
|
74
|
+
try { lib.GlobalWorkerOptions.workerSrc = import.meta.resolve("pdfjs-dist/legacy/build/pdf.worker.mjs") } catch { /* basta con pdfjsWorker */ }
|
|
75
|
+
}
|
|
76
|
+
workerListo = true
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function textoDePagina(items: any[]): string {
|
|
80
|
+
const lineas: string[] = []
|
|
81
|
+
let actual = ""
|
|
82
|
+
let prevY: number | null = null
|
|
83
|
+
let prevFin = 0
|
|
84
|
+
|
|
85
|
+
const cerrar = (blanco: boolean) => {
|
|
86
|
+
if (actual.trim()) lineas.push(actual.replace(/[ \t]+$/g, ""))
|
|
87
|
+
if (blanco && lineas.length && lineas[lineas.length - 1] !== "") lineas.push("")
|
|
88
|
+
actual = ""
|
|
89
|
+
prevFin = 0
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const it of items) {
|
|
93
|
+
if (typeof it?.str !== "string") continue
|
|
94
|
+
const x: number | undefined = it.transform?.[4]
|
|
95
|
+
const y: number | undefined = it.transform?.[5]
|
|
96
|
+
const alto = Math.abs(it.transform?.[3] ?? it.height ?? 10) || 10
|
|
97
|
+
|
|
98
|
+
if (prevY !== null && y !== undefined) {
|
|
99
|
+
const salto = Math.abs(y - prevY)
|
|
100
|
+
if (salto > alto * 0.5) cerrar(salto > alto * 1.9)
|
|
101
|
+
}
|
|
102
|
+
if (actual && x !== undefined && it.str) {
|
|
103
|
+
const hueco = x - prevFin
|
|
104
|
+
if (hueco > alto * 1.5) actual += " " // columna distinta
|
|
105
|
+
else if (hueco > alto * 0.15 && !/\s$/.test(actual) && !/^\s/.test(it.str)) actual += " "
|
|
106
|
+
}
|
|
107
|
+
actual += it.str
|
|
108
|
+
if (x !== undefined) prevFin = x + (it.width ?? 0)
|
|
109
|
+
if (y !== undefined) prevY = y
|
|
110
|
+
if (it.hasEOL) { cerrar(false); prevY = null }
|
|
111
|
+
}
|
|
112
|
+
cerrar(false)
|
|
113
|
+
return lineas.join("\n").replace(/\n{3,}/g, "\n\n").trim()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function extraerTextoPdf(
|
|
117
|
+
bytes: Uint8Array,
|
|
118
|
+
opts: { desde?: number; hasta?: number; maxCaracteres?: number } = {},
|
|
119
|
+
): Promise<PdfTextResult> {
|
|
120
|
+
if (bytes.byteLength > MAX_PDF_BYTES) {
|
|
121
|
+
throw new Error(`El PDF pesa ${(bytes.byteLength / 1048576).toFixed(0)} MB; el máximo es ${MAX_PDF_BYTES / 1048576} MB.`)
|
|
122
|
+
}
|
|
123
|
+
instalarPolyfillsPdf()
|
|
124
|
+
const pdfjs: any = await import("pdfjs-dist/legacy/build/pdf.mjs" as any).catch(() => import("pdfjs-dist" as any))
|
|
125
|
+
const lib = pdfjs.default ?? pdfjs
|
|
126
|
+
await registrarWorker(lib)
|
|
127
|
+
|
|
128
|
+
let doc: any
|
|
129
|
+
try {
|
|
130
|
+
doc = await lib.getDocument({ data: new Uint8Array(bytes), disableWorker: true }).promise
|
|
131
|
+
} catch (err: any) {
|
|
132
|
+
if (err?.name === "PasswordException") throw new Error("El PDF está protegido con contraseña.")
|
|
133
|
+
if (err?.name === "InvalidPDFException") throw new Error("El archivo no es un PDF válido o está dañado.")
|
|
134
|
+
throw err
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const total: number = doc.numPages
|
|
138
|
+
const desde = Math.min(Math.max(1, Math.floor(opts.desde ?? 1)), total)
|
|
139
|
+
const hasta = Math.min(Math.max(desde, Math.floor(opts.hasta ?? total)), total)
|
|
140
|
+
const tope = opts.maxCaracteres ?? Infinity
|
|
141
|
+
|
|
142
|
+
let titulo: string | undefined
|
|
143
|
+
try { titulo = (await doc.getMetadata())?.info?.Title || undefined } catch { /* metadata opcional */ }
|
|
144
|
+
|
|
145
|
+
const bloques: string[] = []
|
|
146
|
+
const caracteres: number[] = []
|
|
147
|
+
let usados = 0
|
|
148
|
+
let truncado = false
|
|
149
|
+
let siguiente: number | undefined
|
|
150
|
+
let ultimaLeida = desde - 1
|
|
151
|
+
|
|
152
|
+
for (let n = desde; n <= hasta; n++) {
|
|
153
|
+
const texto = textoDePagina((await (await doc.getPage(n)).getTextContent()).items as any[])
|
|
154
|
+
const bloque = `--- Página ${n} ---\n${texto}`
|
|
155
|
+
if (usados > 0 && usados + bloque.length > tope) { truncado = true; siguiente = n; break }
|
|
156
|
+
if (bloque.length > tope) {
|
|
157
|
+
// Una sola página ya excede el tope: se recorta, pero siempre se entrega algo.
|
|
158
|
+
bloques.push(bloque.slice(0, tope))
|
|
159
|
+
caracteres.push(texto.length)
|
|
160
|
+
ultimaLeida = n
|
|
161
|
+
truncado = true
|
|
162
|
+
siguiente = n < total ? n + 1 : undefined
|
|
163
|
+
usados += tope
|
|
164
|
+
break
|
|
165
|
+
}
|
|
166
|
+
bloques.push(bloque)
|
|
167
|
+
caracteres.push(texto.length)
|
|
168
|
+
usados += bloque.length
|
|
169
|
+
ultimaLeida = n
|
|
170
|
+
}
|
|
171
|
+
if (!truncado && ultimaLeida < total) siguiente = ultimaLeida + 1
|
|
172
|
+
|
|
173
|
+
try { await doc.destroy() } catch { /* best effort */ }
|
|
174
|
+
|
|
175
|
+
const sinTexto = caracteres.length > 0 && caracteres.every((c) => c === 0)
|
|
176
|
+
return {
|
|
177
|
+
totalPaginas: total,
|
|
178
|
+
paginasLeidas: caracteres.length,
|
|
179
|
+
titulo,
|
|
180
|
+
texto: bloques.join("\n\n"),
|
|
181
|
+
caracteresPorPagina: caracteres,
|
|
182
|
+
sinTexto,
|
|
183
|
+
truncado,
|
|
184
|
+
...(siguiente !== undefined && siguiente <= total ? { siguientePagina: siguiente } : {}),
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilidades de PowerPoint (.pptx) sobre su XML: orden real de diapositivas,
|
|
3
|
+
* texto por párrafo y notas del orador. Sin modelos.
|
|
4
|
+
*
|
|
5
|
+
* El número de archivo (slide7.xml) NO es la posición: al reordenar en
|
|
6
|
+
* PowerPoint los archivos conservan su nombre. El orden de verdad está en
|
|
7
|
+
* `ppt/presentation.xml` (sldIdLst) resuelto con `ppt/_rels/presentation.xml.rels`.
|
|
8
|
+
*/
|
|
9
|
+
import type JSZip from "jszip"
|
|
10
|
+
|
|
11
|
+
export interface SlideRef {
|
|
12
|
+
/** Posición en la presentación, desde 1. */
|
|
13
|
+
numero: number
|
|
14
|
+
/** Ruta dentro del zip, p. ej. ppt/slides/slide7.xml. */
|
|
15
|
+
archivo: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const unescapeXml = (s: string) =>
|
|
19
|
+
s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&")
|
|
20
|
+
|
|
21
|
+
export async function listarSlides(zip: JSZip): Promise<SlideRef[]> {
|
|
22
|
+
const porNumeroDeArchivo = () =>
|
|
23
|
+
Object.keys(zip.files)
|
|
24
|
+
.filter((n) => /^ppt\/slides\/slide\d+\.xml$/i.test(n))
|
|
25
|
+
.sort((a, b) => Number(a.match(/slide(\d+)/)![1]) - Number(b.match(/slide(\d+)/)![1]))
|
|
26
|
+
.map((archivo, i) => ({ numero: i + 1, archivo }))
|
|
27
|
+
|
|
28
|
+
const pres = await zip.file("ppt/presentation.xml")?.async("string")
|
|
29
|
+
const rels = await zip.file("ppt/_rels/presentation.xml.rels")?.async("string")
|
|
30
|
+
if (!pres || !rels) return porNumeroDeArchivo()
|
|
31
|
+
|
|
32
|
+
const destinos = new Map<string, string>()
|
|
33
|
+
for (const m of rels.matchAll(/<Relationship\b[^>]*>/g)) {
|
|
34
|
+
const id = m[0].match(/\bId="([^"]+)"/)?.[1]
|
|
35
|
+
const target = m[0].match(/\bTarget="([^"]+)"/)?.[1]
|
|
36
|
+
if (id && target) destinos.set(id, target)
|
|
37
|
+
}
|
|
38
|
+
const ordenados: SlideRef[] = []
|
|
39
|
+
for (const m of pres.matchAll(/<p:sldId\b[^>]*\br:id="([^"]+)"/g)) {
|
|
40
|
+
const target = destinos.get(m[1])
|
|
41
|
+
if (!target) continue
|
|
42
|
+
const archivo = target.startsWith("/") ? target.slice(1) : `ppt/${target.replace(/^\.\//, "")}`
|
|
43
|
+
if (zip.file(archivo)) ordenados.push({ numero: ordenados.length + 1, archivo })
|
|
44
|
+
}
|
|
45
|
+
return ordenados.length ? ordenados : porNumeroDeArchivo()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Texto de un XML de diapositiva o de notas: un párrafo por línea. */
|
|
49
|
+
export function textoDeXml(xml: string): string {
|
|
50
|
+
const parrafos: string[] = []
|
|
51
|
+
for (const p of xml.matchAll(/<a:p[ >][\s\S]*?<\/a:p>/g)) {
|
|
52
|
+
const partes = [...p[0].matchAll(/<a:t(?:\s[^>]*)?>([^<]*)<\/a:t>|<a:br\s*\/>/g)]
|
|
53
|
+
.map((m) => (m[1] === undefined ? "\n" : unescapeXml(m[1])))
|
|
54
|
+
const linea = partes.join("").trim()
|
|
55
|
+
if (linea) parrafos.push(linea)
|
|
56
|
+
}
|
|
57
|
+
return parrafos.join("\n")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Título: primer texto del shape cuyo placeholder es title/ctrTitle; si no hay, la primera línea. */
|
|
61
|
+
export function tituloDeXml(xml: string, texto: string): string | undefined {
|
|
62
|
+
for (const sp of xml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
63
|
+
if (/<p:ph\b[^>]*\btype="(?:title|ctrTitle)"/.test(sp[0])) {
|
|
64
|
+
const t = textoDeXml(sp[0])
|
|
65
|
+
if (t) return t.split("\n")[0]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return texto.split("\n")[0] || undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Ruta del XML de notas de una diapositiva, si tiene. */
|
|
72
|
+
export async function archivoDeNotas(zip: JSZip, slide: SlideRef): Promise<string | null> {
|
|
73
|
+
const relsPath = slide.archivo.replace(/slides\/(slide\d+\.xml)$/, "slides/_rels/$1.rels")
|
|
74
|
+
const rels = await zip.file(relsPath)?.async("string")
|
|
75
|
+
const target = rels?.match(/<Relationship\b[^>]*\bType="[^"]*\/notesSlide"[^>]*>/)?.[0].match(/\bTarget="([^"]+)"/)?.[1]
|
|
76
|
+
if (!target) return null
|
|
77
|
+
const base = slide.archivo.split("/").slice(0, -1)
|
|
78
|
+
const partes = target.startsWith("/") ? target.slice(1).split("/") : [...base, ...target.split("/")]
|
|
79
|
+
const resueltas: string[] = []
|
|
80
|
+
for (const p of partes) { if (p === "..") resueltas.pop(); else if (p !== ".") resueltas.push(p) }
|
|
81
|
+
const ruta = resueltas.join("/")
|
|
82
|
+
return zip.file(ruta) ? ruta : null
|
|
83
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resuelve el archivo de entrada de las tools office_*: acepta la `ruta` de siempre
|
|
3
|
+
* o el `artifact_id` que aparece en el aviso de un adjunto.
|
|
4
|
+
*
|
|
5
|
+
* IMPORTANTE: estas tools corren en el worker de herramientas, que no puede tocar
|
|
6
|
+
* HiveDB (el bundle del worker no debe contener el binding nativo; ver
|
|
7
|
+
* tool-runtime/worker-tools.ts y scripts/build-gateway.ts). Por eso el artifact se
|
|
8
|
+
* localiza en disco por su id —`<hive>/artifacts/<día>/<id>.<ext>`, como lo escribe
|
|
9
|
+
* artifacts/store.ts— y no consultando la colección `artifacts`.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readdirSync } from "node:fs"
|
|
12
|
+
import { join } from "node:path"
|
|
13
|
+
import { getHiveDir } from "../../config/loader.ts"
|
|
14
|
+
|
|
15
|
+
export const ARTIFACT_ID_PARAM = {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "ID de un archivo adjunto por el usuario (aparece como artifact_id en el aviso del adjunto). Alternativa a 'ruta'.",
|
|
18
|
+
} as const
|
|
19
|
+
|
|
20
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
21
|
+
|
|
22
|
+
/** Ruta en disco del artifact `id`, o null si no existe. El id se valida como UUID: nunca forma parte de una ruta sin pasar por ahí. */
|
|
23
|
+
export function buscarArtifactEnDisco(id: string, raiz = join(getHiveDir(), "artifacts")): string | null {
|
|
24
|
+
if (!UUID.test(id) || !existsSync(raiz)) return null
|
|
25
|
+
for (const dia of readdirSync(raiz)) {
|
|
26
|
+
const dir = join(raiz, dia)
|
|
27
|
+
try {
|
|
28
|
+
const archivo = readdirSync(dir).find((nombre) => nombre.startsWith(`${id}.`))
|
|
29
|
+
if (archivo) return join(dir, archivo)
|
|
30
|
+
} catch { /* no es una carpeta de día */ }
|
|
31
|
+
}
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function resolveOfficeInput(
|
|
36
|
+
params: Record<string, unknown>,
|
|
37
|
+
): Promise<{ ruta: string } | { error: string }> {
|
|
38
|
+
const artifactId = typeof params.artifact_id === "string" ? params.artifact_id.trim() : ""
|
|
39
|
+
if (artifactId) {
|
|
40
|
+
const ruta = buscarArtifactEnDisco(artifactId)
|
|
41
|
+
if (!ruta) {
|
|
42
|
+
return { error: `El adjunto ${artifactId} no existe o ya expiró (se conservan 7 días). Pídele al usuario que lo reenvíe.` }
|
|
43
|
+
}
|
|
44
|
+
return { ruta }
|
|
45
|
+
}
|
|
46
|
+
const ruta = typeof params.ruta === "string" ? params.ruta.trim() : ""
|
|
47
|
+
if (!ruta) return { error: "Indica 'ruta' o 'artifact_id'." }
|
|
48
|
+
return { ruta }
|
|
49
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { Tool } from "../types.ts";
|
|
10
10
|
import { logger } from "../../utils/logger.ts";
|
|
11
11
|
import { getBrowserService, screenshotElement } from "./browser-service.ts";
|
|
12
|
+
import { getWorkspace } from "../filesystem/workspace-guard.ts";
|
|
12
13
|
import { createArtifact } from "../../artifacts/store.ts";
|
|
13
14
|
|
|
14
15
|
const log = logger.child("browser-screenshot");
|
|
@@ -16,6 +17,11 @@ const log = logger.child("browser-screenshot");
|
|
|
16
17
|
// Default viewport for screenshots — keeps base64 small (~30-60KB vs ~300KB)
|
|
17
18
|
const DEFAULT_VIEWPORT = { width: 1280, height: 720 };
|
|
18
19
|
|
|
20
|
+
/** Nombre del archivo de la captura: el dominio de la página (about:blank u otros sin host → "captura"). */
|
|
21
|
+
function hostLabel(url: string | undefined): string {
|
|
22
|
+
try { return new URL(url || "").hostname || "captura" } catch { return "captura" }
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
export const browserScreenshotTool: Tool = {
|
|
20
26
|
name: "browser_screenshot",
|
|
21
27
|
description: "Take screenshot of current browser page. Returns JPEG by default for smaller size. Spanish: captura de pantalla, screenshot, imagen de página",
|
|
@@ -119,6 +125,7 @@ export const browserScreenshotTool: Tool = {
|
|
|
119
125
|
runId: configurable.run_id ? String(configurable.run_id) : null,
|
|
120
126
|
taskId: configurable.task_id ? String(configurable.task_id) : null,
|
|
121
127
|
rootDir: configurable.artifact_dir ? String(configurable.artifact_dir) : undefined,
|
|
128
|
+
visible: { workspace: getWorkspace(config), folder: "capturas", label: hostLabel(currentUrl) },
|
|
122
129
|
width,
|
|
123
130
|
height,
|
|
124
131
|
});
|