@johpaz/hive-sdk 0.4.3 → 0.4.5

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 (49) hide show
  1. package/CHANGELOG.md +20 -4
  2. package/README.md +48 -7
  3. package/SECURITY.md +17 -0
  4. package/docs/API-AGENTS.md +430 -0
  5. package/docs/API-ARTIFACTS.md +55 -0
  6. package/docs/API-CONTEXT-COMPILER.md +285 -0
  7. package/docs/API-CRON.md +188 -0
  8. package/docs/API-DAG-SCHEDULER.md +291 -0
  9. package/docs/API-HOOKS.md +147 -0
  10. package/docs/API-RESILIENCE.md +45 -0
  11. package/docs/API-SERVICES.md +458 -0
  12. package/docs/API-SESSIONS.md +146 -0
  13. package/docs/API-TOOLS-SKILLS-CHANNELS.md +499 -0
  14. package/docs/API-WORKERS-EVENTS.md +311 -0
  15. package/docs/HIVE-HARNESS.md +232 -0
  16. package/docs/INDEX.md +198 -0
  17. package/docs/SECURITY-GUARDRAILS.md +87 -0
  18. package/docs/TEMPLATE-HIVE-APP.md +360 -0
  19. package/docs/UPGRADING.md +65 -0
  20. package/docs/assets/logoblack.png +0 -0
  21. package/docs/assets/logocolor-dark.png +0 -0
  22. package/docs/assets/logocolorbg.png +0 -0
  23. package/docs/plans/2026-09-05-office-dependency-hardening-design.md +28 -0
  24. package/docs/plans/2026-09-06-dependency-audit-remediation-design.md +25 -0
  25. package/docs/plans/2026-09-06-pptx-image-size-remediation-design.md +54 -0
  26. package/docs/plans/2026-09-06-typescript7-bun142-documentation-design.md +48 -0
  27. package/package.json +9 -8
  28. package/packages/cli/templates/hive-app/package.json +3 -0
  29. package/packages/core/src/agent/llm-providers/hiveagents.ts +2 -2
  30. package/packages/core/src/agent/providers/index.ts +17 -1
  31. package/packages/core/src/api/createAgent.ts +4 -2
  32. package/packages/core/src/config/loader.ts +2 -1
  33. package/packages/core/src/gateway/server.ts +1 -1
  34. package/packages/core/src/mcp/transports/sse.ts +22 -8
  35. package/packages/core/src/mcp/transports/websocket.ts +11 -9
  36. package/packages/core/src/scheduler/CronScheduler.ts +4 -2
  37. package/packages/core/src/scheduler/cron/job.ts +2 -1
  38. package/packages/core/src/scheduler/cron/zoned-time.ts +2 -1
  39. package/packages/core/src/tool-runtime/tool-worker.ts +3 -1
  40. package/packages/core/src/tools/office/office-escribir-pptx.ts +3 -1
  41. package/packages/core/src/tools/office/office-leer-pdf.ts +93 -44
  42. package/packages/core/src/tools/office/office-leer-xlsx.ts +36 -10
  43. package/packages/core/src/tools/office/security-limits.ts +28 -0
  44. package/packages/core/src/utils/port.ts +33 -0
  45. package/packages/core/src/vendor/pptxgenjs/LICENSE +21 -0
  46. package/packages/core/src/vendor/pptxgenjs/README.md +17 -0
  47. package/packages/core/src/vendor/pptxgenjs/pptxgen.es.d.ts +17 -0
  48. package/packages/core/src/vendor/pptxgenjs/pptxgen.es.js +7368 -0
  49. package/packages/core/src/voice/index.ts +6 -5
@@ -11,6 +11,14 @@ import { logger } from "../../utils/logger.ts";
11
11
  import * as fs from "node:fs";
12
12
  import * as path from "node:path";
13
13
  import { cargarXlsx } from "./xlsx-loader.ts";
14
+ import {
15
+ assertBeforeDeadline,
16
+ MAX_XLSX_INPUT_BYTES,
17
+ MAX_XLSX_ROWS_PER_SHEET,
18
+ MAX_XLSX_SHEETS,
19
+ OFFICE_PROCESSING_TIMEOUT_MS,
20
+ validateOfficeInput,
21
+ } from "./security-limits.ts";
14
22
 
15
23
  const log = logger.child("office-leer-xlsx");
16
24
 
@@ -56,32 +64,43 @@ export const officeLeerXlsxTool: Tool = {
56
64
  return { ok: false, error: `Archivo no encontrado: ${rutaAbsoluta}` };
57
65
  }
58
66
 
67
+ const inputError = validateOfficeInput(
68
+ rutaAbsoluta,
69
+ MAX_XLSX_INPUT_BYTES,
70
+ "El XLSX",
71
+ );
72
+ if (inputError) return { ok: false, error: inputError };
73
+
59
74
  const XLSX = await cargarXlsx();
60
75
  const buffer = fs.readFileSync(rutaAbsoluta);
61
- const workbook = XLSX.read(buffer, { type: "buffer" });
76
+ const deadline = Date.now() + OFFICE_PROCESSING_TIMEOUT_MS;
77
+ const workbook = XLSX.read(buffer, {
78
+ type: "buffer",
79
+ sheetRows: MAX_XLSX_ROWS_PER_SHEET + 2,
80
+ sheets: hojaFiltro,
81
+ });
62
82
 
63
83
  const nombresHojas = hojaFiltro
64
84
  ? [hojaFiltro]
65
85
  : workbook.SheetNames;
66
86
 
87
+ if (nombresHojas.length > MAX_XLSX_SHEETS) {
88
+ return {
89
+ ok: false,
90
+ error: `El XLSX contiene más de ${MAX_XLSX_SHEETS} hojas`,
91
+ };
92
+ }
93
+
67
94
  const hojas: Record<string, any[]> = {};
68
95
 
69
96
  for (const nombreHoja of nombresHojas) {
97
+ assertBeforeDeadline(deadline, "La lectura del XLSX");
70
98
  const hoja = workbook.Sheets[nombreHoja];
71
99
  if (!hoja) {
72
100
  log.warn(`Hoja '${nombreHoja}' no encontrada en el archivo`);
73
101
  continue;
74
102
  }
75
103
 
76
- const opciones: any = {
77
- header: incluirEncabezados ? 1 : 1,
78
- defval: "",
79
- };
80
-
81
- if (rango) {
82
- opciones.range = rango;
83
- }
84
-
85
104
  if (incluirEncabezados) {
86
105
  // La primera fila se usa como encabezados
87
106
  hojas[nombreHoja] = XLSX.utils.sheet_to_json(hoja, {
@@ -96,6 +115,13 @@ export const officeLeerXlsxTool: Tool = {
96
115
  range: rango,
97
116
  });
98
117
  }
118
+
119
+ if (hojas[nombreHoja].length > MAX_XLSX_ROWS_PER_SHEET) {
120
+ return {
121
+ ok: false,
122
+ error: `La hoja '${nombreHoja}' supera el máximo de 10.000 filas`,
123
+ };
124
+ }
99
125
  }
100
126
 
101
127
  const totalFilas = Object.values(hojas).reduce(
@@ -0,0 +1,28 @@
1
+ import { statSync } from "node:fs";
2
+
3
+ export const MAX_PDF_INPUT_BYTES = 25 * 1024 * 1024;
4
+ export const MAX_XLSX_INPUT_BYTES = 15 * 1024 * 1024;
5
+ export const MAX_PDF_PAGES_PER_REQUEST = 200;
6
+ export const MAX_XLSX_SHEETS = 50;
7
+ export const MAX_XLSX_ROWS_PER_SHEET = 10_000;
8
+ export const OFFICE_PROCESSING_TIMEOUT_MS = 30_000;
9
+
10
+ export function validateOfficeInput(
11
+ filePath: string,
12
+ maxBytes: number,
13
+ label: string,
14
+ ): string | null {
15
+ const stat = statSync(filePath);
16
+ if (!stat.isFile()) return `${label} debe ser un archivo regular`;
17
+ if (stat.size > maxBytes) {
18
+ const maxMiB = maxBytes / (1024 * 1024);
19
+ return `${label} excede el límite de ${maxMiB} MiB`;
20
+ }
21
+ return null;
22
+ }
23
+
24
+ export function assertBeforeDeadline(deadline: number, label: string): void {
25
+ if (Date.now() > deadline) {
26
+ throw new Error(`${label} excedió el límite de procesamiento de 30 segundos`);
27
+ }
28
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Resolución de puertos desde el entorno.
3
+ *
4
+ * Bun 1.4 endureció `Bun.serve`: un puerto fuera de `[0, 65535]` —o `NaN`, que
5
+ * es lo que devuelve `parseInt("no-es-un-numero")`— ahora lanza `RangeError` en
6
+ * vez de recortar el valor. Un `HIVE_PORT` mal escrito dejó de degradar y pasó a
7
+ * tumbar el arranque con una excepción sin capturar:
8
+ *
9
+ * RangeError: The value of "options.port" is out of range.
10
+ * It must be an integer. Received NaN
11
+ *
12
+ * Este helper vuelve a la degradación explícita: avisa y sigue con el puerto por
13
+ * defecto, que para una variable de entorno mal tipeada es el comportamiento
14
+ * útil. El `0` se deja pasar a propósito: `Bun.serve` lo interpreta como "asigná
15
+ * un puerto libre" y hay código que se apoya en eso.
16
+ *
17
+ * Avisa con `console.warn` y no con el logger del proyecto a propósito: esto lo
18
+ * usa `config/loader.ts`, y el logger importa `config/loader.ts` para saber
19
+ * dónde escribir. Importarlo acá cierra el ciclo y rompe con "Cannot access
20
+ * 'logger' before initialization". Además, cuando se resuelve un puerto el
21
+ * logger todavía no está configurado.
22
+ */
23
+
24
+ export function resolvePort(raw: unknown, fallback: number): number {
25
+ if (raw === undefined || raw === null || raw === "") return fallback
26
+
27
+ const n = typeof raw === "number" ? raw : Number(String(raw).trim())
28
+ if (!Number.isInteger(n) || n < 0 || n > 65535) {
29
+ console.warn(`[config] Puerto inválido ${JSON.stringify(raw)}; se usa ${fallback}`)
30
+ return fallback
31
+ }
32
+ return n
33
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2022 Brent Ely
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ # PptxGenJS vendorizado
2
+
3
+ - Proyecto: PptxGenJS
4
+ - Versión: 4.0.1
5
+ - Fuente: https://www.npmjs.com/package/pptxgenjs/v/4.0.1
6
+ - Repositorio: https://github.com/gitbrent/PptxGenJS/tree/v4.0.1
7
+ - Licencia: MIT (`LICENSE`)
8
+ - Artefacto: `dist/pptxgen.es.js` de la distribución oficial
9
+ - SHA-256: `05844c5625e2cda3b449eb967c2246dd57ca57341886a7c28eeebca263b29bd4`
10
+
11
+ Hive conserva únicamente el artefacto ESM, que importa `jszip` y no importa
12
+ `image-size`. No copie el `package.json` upstream: declara `image-size` para las
13
+ funciones de imágenes que Hive no expone.
14
+
15
+ Para actualizar esta copia, descargue una versión oficial, compruebe su licencia
16
+ y procedencia, reemplace el artefacto, actualice el hash y ejecute la prueba de
17
+ `office_escribir_pptx`, el typecheck y `bun audit`.
@@ -0,0 +1,17 @@
1
+ interface TextRun {
2
+ text: string;
3
+ options?: Record<string, unknown>;
4
+ }
5
+
6
+ interface Slide {
7
+ addText(text: string | TextRun[], options?: Record<string, unknown>): void;
8
+ addNotes(notes: string | string[]): void;
9
+ }
10
+
11
+ declare class PptxGenJS {
12
+ layout: string;
13
+ addSlide(): Slide;
14
+ writeFile(options: { fileName: string }): Promise<string>;
15
+ }
16
+
17
+ export default PptxGenJS;