@johpaz/hive-agents 0.0.36 → 0.0.38

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 (70) hide show
  1. package/README.md +16 -16
  2. package/dist/hive.js +214 -193
  3. package/dist/tool-worker.js +218395 -0
  4. package/dist/ui/assets/{AgentCreateForm-tJZv9FZC.js → AgentCreateForm-0oFbN3gj.js} +1 -1
  5. package/dist/ui/assets/{AgentDetailPage-Du-mRcAX.js → AgentDetailPage-BJ4L2fNJ.js} +1 -1
  6. package/dist/ui/assets/AgentNewPage-B3n0LUck.js +1 -0
  7. package/dist/ui/{dist/assets/AgentsPage-YvSgWRiw.js → assets/AgentsPage-DGNLDXjR.js} +1 -1
  8. package/dist/ui/assets/{CanvasPage-DtMwGvxf.js → CanvasPage-CnMO1FN8.js} +1 -1
  9. package/dist/ui/assets/{ChannelsPage-BdBXWHjj.js → ChannelsPage-fbF8K4MR.js} +1 -1
  10. package/dist/ui/{dist/assets/DashboardPage-ghl1ZguH.js → assets/DashboardPage-VyXXp3U1.js} +1 -1
  11. package/dist/ui/assets/{LoginPage-CAmSI9Vy.js → LoginPage-DPj2s2Qq.js} +1 -1
  12. package/dist/ui/{dist/assets/LogsPage-DAPBHkwK.js → assets/LogsPage-B2lY9maY.js} +1 -1
  13. package/dist/ui/{dist/assets/MeetingPage-WjjGOqqU.js → assets/MeetingPage-2ky_hKiG.js} +1 -1
  14. package/dist/ui/{dist/assets/ProvidersPage-Ct6HsAi1.js → assets/ProvidersPage-CEyUM2tD.js} +1 -1
  15. package/dist/ui/{dist/assets/RecoverPage-DpW3l-yv.js → assets/RecoverPage-B-hDZUM2.js} +1 -1
  16. package/dist/ui/{dist/assets/SettingsPage-DBJ7_E6C.js → assets/SettingsPage-eO0i3g8p.js} +1 -1
  17. package/dist/ui/assets/{SetupPage-DKmLVUaj.js → SetupPage-ByYqTELb.js} +1 -1
  18. package/dist/ui/assets/WebChatPage-BuGT2AL0.js +16 -0
  19. package/dist/ui/assets/{alert-C-NE-P3s.js → alert-Bq6awLlW.js} +1 -1
  20. package/dist/ui/{dist/assets/alert-dialog-C5mzbHdP.js → assets/alert-dialog-DQvltYmf.js} +1 -1
  21. package/dist/ui/assets/{badge-ChpACfWO.js → badge-DXUDdTed.js} +1 -1
  22. package/dist/ui/assets/{dialog-QnZ0ad8O.js → dialog-bI9jImCS.js} +1 -1
  23. package/dist/ui/assets/{es-NQNoaWDx.js → es-Cg8zdT52.js} +1 -1
  24. package/dist/ui/{dist/assets/index-DMCjjdqf.js → assets/index-CQ7fn00w.js} +2 -2
  25. package/dist/ui/assets/{label-D2H1IR_J.js → label-CrH0Jj3v.js} +1 -1
  26. package/dist/ui/assets/useProviders-CnlC_qCS.js +1 -0
  27. package/dist/ui/dist/assets/{AgentCreateForm-tJZv9FZC.js → AgentCreateForm-0oFbN3gj.js} +1 -1
  28. package/dist/ui/dist/assets/{AgentDetailPage-Du-mRcAX.js → AgentDetailPage-BJ4L2fNJ.js} +1 -1
  29. package/dist/ui/dist/assets/AgentNewPage-B3n0LUck.js +1 -0
  30. package/dist/ui/{assets/AgentsPage-YvSgWRiw.js → dist/assets/AgentsPage-DGNLDXjR.js} +1 -1
  31. package/dist/ui/dist/assets/{CanvasPage-DtMwGvxf.js → CanvasPage-CnMO1FN8.js} +1 -1
  32. package/dist/ui/dist/assets/{ChannelsPage-BdBXWHjj.js → ChannelsPage-fbF8K4MR.js} +1 -1
  33. package/dist/ui/{assets/DashboardPage-ghl1ZguH.js → dist/assets/DashboardPage-VyXXp3U1.js} +1 -1
  34. package/dist/ui/dist/assets/{LoginPage-CAmSI9Vy.js → LoginPage-DPj2s2Qq.js} +1 -1
  35. package/dist/ui/{assets/LogsPage-DAPBHkwK.js → dist/assets/LogsPage-B2lY9maY.js} +1 -1
  36. package/dist/ui/{assets/MeetingPage-WjjGOqqU.js → dist/assets/MeetingPage-2ky_hKiG.js} +1 -1
  37. package/dist/ui/{assets/ProvidersPage-Ct6HsAi1.js → dist/assets/ProvidersPage-CEyUM2tD.js} +1 -1
  38. package/dist/ui/{assets/RecoverPage-DpW3l-yv.js → dist/assets/RecoverPage-B-hDZUM2.js} +1 -1
  39. package/dist/ui/{assets/SettingsPage-DBJ7_E6C.js → dist/assets/SettingsPage-eO0i3g8p.js} +1 -1
  40. package/dist/ui/dist/assets/{SetupPage-DKmLVUaj.js → SetupPage-ByYqTELb.js} +1 -1
  41. package/dist/ui/dist/assets/WebChatPage-BuGT2AL0.js +16 -0
  42. package/dist/ui/dist/assets/{alert-C-NE-P3s.js → alert-Bq6awLlW.js} +1 -1
  43. package/dist/ui/{assets/alert-dialog-C5mzbHdP.js → dist/assets/alert-dialog-DQvltYmf.js} +1 -1
  44. package/dist/ui/dist/assets/{badge-ChpACfWO.js → badge-DXUDdTed.js} +1 -1
  45. package/dist/ui/dist/assets/{dialog-QnZ0ad8O.js → dialog-bI9jImCS.js} +1 -1
  46. package/dist/ui/dist/assets/{es-NQNoaWDx.js → es-Cg8zdT52.js} +1 -1
  47. package/dist/ui/{assets/index-DMCjjdqf.js → dist/assets/index-CQ7fn00w.js} +2 -2
  48. package/dist/ui/dist/assets/{label-D2H1IR_J.js → label-CrH0Jj3v.js} +1 -1
  49. package/dist/ui/dist/assets/useProviders-CnlC_qCS.js +1 -0
  50. package/dist/ui/dist/index.html +1 -1
  51. package/dist/ui/index.html +1 -1
  52. package/package.json +3 -2
  53. package/packages/cli/src/commands/gateway.ts +1 -1
  54. package/packages/cli/src/commands/onboard.ts +1 -1
  55. package/packages/core/src/agent/agent-loop.ts +4 -14
  56. package/packages/core/src/agent/context-compiler.ts +1 -1
  57. package/packages/core/src/agent/conversation-store.ts +4 -5
  58. package/packages/core/src/agent/providers/index.ts +3 -4
  59. package/packages/core/src/agent/tool-selector.ts +3 -4
  60. package/packages/core/src/gateway/resolver.ts +5 -1
  61. package/packages/core/src/gateway/routes/chat.ts +16 -16
  62. package/packages/core/src/gateway/server.ts +44 -45
  63. package/packages/core/src/storage/seed.ts +39 -33
  64. package/packages/core/src/tool-runtime/index.ts +49 -3
  65. package/dist/ui/assets/AgentNewPage-DIFYd_Ys.js +0 -1
  66. package/dist/ui/assets/WebChatPage-CVRcKept.js +0 -16
  67. package/dist/ui/assets/useProviders-C6_QHsEi.js +0 -1
  68. package/dist/ui/dist/assets/AgentNewPage-DIFYd_Ys.js +0 -1
  69. package/dist/ui/dist/assets/WebChatPage-CVRcKept.js +0 -16
  70. package/dist/ui/dist/assets/useProviders-C6_QHsEi.js +0 -1
package/dist/hive.js CHANGED
@@ -20069,23 +20069,39 @@ function seedAllData() {
20069
20069
  log2.info(`[seed] \u2705 ${channelCount} channels procesados`);
20070
20070
  db.query(`UPDATE channels SET active = 1, enabled = 1, status = 'connected' WHERE id = 'webchat'`).run();
20071
20071
  log2.info("[seed] \u2705 webchat activado por defecto");
20072
+ db.query(`DELETE FROM playbook WHERE rule = ?`).run("Al crear proyectos, divide las tareas en pasos at\xF3micos que puedan ejecutarse independientemente");
20072
20073
  let playbookCount = 0;
20073
20074
  for (const rule of INITIAL_PLAYBOOK_RULES) {
20074
- db.query(`
20075
- INSERT OR REPLACE INTO playbook (rule, category, applicable_to, helpful_count, harmful_count, active)
20076
- VALUES (?, ?, ?, 1, 0, 1)
20077
- `).run(rule.rule, rule.category, rule.applicable_to);
20075
+ const existing = db.query(`SELECT id FROM playbook WHERE rule = ?`).get(rule.rule);
20076
+ if (existing) {
20077
+ db.query(`
20078
+ UPDATE playbook
20079
+ SET category = ?, applicable_to = ?, active = 1, updated_at = unixepoch()
20080
+ WHERE id = ?
20081
+ `).run(rule.category, rule.applicable_to, existing.id);
20082
+ } else {
20083
+ db.query(`
20084
+ INSERT INTO playbook (rule, category, applicable_to, helpful_count, harmful_count, active)
20085
+ VALUES (?, ?, ?, 1, 0, 1)
20086
+ `).run(rule.rule, rule.category, rule.applicable_to);
20087
+ }
20078
20088
  playbookCount++;
20079
20089
  }
20080
20090
  log2.info(`[seed] \u2705 ${playbookCount} ACE playbook rules seeded`);
20091
+ db.run(`DELETE FROM playbook_fts`);
20092
+ const activePlaybook = db.query(`
20093
+ SELECT id, rule, category, applicable_to
20094
+ FROM playbook
20095
+ WHERE active = 1
20096
+ `).all();
20081
20097
  const insertPlaybookFts = db.prepare(`
20082
- INSERT OR REPLACE INTO playbook_fts(rule, category, applicable_to)
20083
- VALUES (?, ?, ?)
20098
+ INSERT OR REPLACE INTO playbook_fts(rowid, rule, category, applicable_to)
20099
+ VALUES (?, ?, ?, ?)
20084
20100
  `);
20085
- for (const rule of INITIAL_PLAYBOOK_RULES) {
20086
- insertPlaybookFts.run(rule.rule, rule.category, rule.applicable_to);
20101
+ for (const rule of activePlaybook) {
20102
+ insertPlaybookFts.run(rule.id, rule.rule, rule.category, rule.applicable_to);
20087
20103
  }
20088
- log2.info(`[seed] \u2705 ${playbookCount} reglas playbook sincronizadas a playbook_fts`);
20104
+ log2.info(`[seed] \u2705 ${activePlaybook.length} reglas playbook sincronizadas a playbook_fts`);
20089
20105
  log2.info("[seed] \u2728 Seed completado exitosamente.");
20090
20106
  } catch (err) {
20091
20107
  log2.error("[seed] \u274C Error durante el seed:", err.message);
@@ -20137,14 +20153,6 @@ var init_seed = __esm(() => {
20137
20153
  { id: "browser_extract", name: "browser_extract", category: "web", description: "Extraer texto, enlaces o datos estructurados usando selectores CSS o XPath. Sin\xF3nimos: obtener datos, scraping, selectores, extraer informaci\xF3n" },
20138
20154
  { id: "browser_script", name: "browser_script", category: "web", description: "Ejecutar JavaScript arbitrario en el navegador y obtener resultado. Sin\xF3nimos: ejecutar javascript, script, c\xF3digo, funci\xF3n, evaluar" },
20139
20155
  { id: "browser_wait", name: "browser_wait", category: "web", description: "Esperar a que aparezca un elemento o se cumpla una condici\xF3n. Sin\xF3nimos: esperar, condici\xF3n, elemento, selector, pausa" },
20140
- { id: "project_create", name: "project_create", category: "projects", description: "Crear un nuevo proyecto con tareas en la base de datos. Sin\xF3nimos: nuevo proyecto, iniciar plan, crear proyecto" },
20141
- { id: "project_list", name: "project_list", category: "projects", description: "Listar todos los proyectos con su estado. Sin\xF3nimos: ver proyectos, historial, listar proyectos, mostrar proyectos" },
20142
- { id: "project_update", name: "project_update", category: "projects", description: "Actualizar progreso o metadatos del proyecto. Sin\xF3nimos: avance, porcentaje, estado, actualizar proyecto" },
20143
- { id: "project_done", name: "project_done", category: "projects", description: "Marcar proyecto como completado y archivarlo. Sin\xF3nimos: proyecto terminado, cerrar proyecto, completado, finalizar" },
20144
- { id: "project_fail", name: "project_fail", category: "projects", description: "Marcar proyecto como fallido y registrar raz\xF3n. Sin\xF3nimos: proyecto fallido, marcar fracaso, error, fall\xF3 proyecto" },
20145
- { id: "task_create", name: "task_create", category: "projects", description: "Agregar una tarea o subtarea a un proyecto existente. Sin\xF3nimos: crear tarea, agregar tarea, subtarea, pendiente" },
20146
- { id: "task_update", name: "task_update", category: "projects", description: "Actualizar estado de tarea (pendiente, en_progreso, hecho). Sin\xF3nimos: actualizar tarea, marcar completa, en progreso" },
20147
- { id: "task_evaluate", name: "task_evaluate", category: "projects", description: "Evaluar resultado de tarea contra criterios de aceptaci\xF3n. Sin\xF3nimos: validar resultado, criterios de aceptaci\xF3n, revisar tarea" },
20148
20156
  { id: "cron.create", name: "cron.create", category: "cron", description: "Crear tarea programada: recurrente (expresi\xF3n cron) o \xFAnica (fire_at). Requiere campo 'task' con instrucci\xF3n para el agente. Sin\xF3nimos: programar tarea, crear recordatorio, agendar, automatizar horario, tarea recurrente, una vez" },
20149
20157
  { id: "cron.list", name: "cron.list", category: "cron", description: "Listar todas las tareas programadas con pr\xF3ximos horarios de ejecuci\xF3n. Sin\xF3nimos: ver tareas programadas, listar cronograma, pr\xF3ximas ejecuciones" },
20150
20158
  { id: "cron.update", name: "cron.update", category: "cron", description: "Actualizar tarea programada existente: cambiar expresi\xF3n, instrucci\xF3n, canal, ventana temporal. Sin\xF3nimos: modificar cron, editar recordatorio, cambiar horario, actualizar tarea" },
@@ -20168,7 +20176,6 @@ var init_seed = __esm(() => {
20168
20176
  { id: "task_status", name: "task_status", category: "agents", description: "Obtener estado de ejecuci\xF3n de tareas delegadas. Sin\xF3nimos: estado tarea delegada, verificar progreso, consultar tarea" },
20169
20177
  { id: "bus_publish", name: "bus_publish", category: "agents", description: "Publicar mensaje en el Agent Bus para comunicaci\xF3n worker-to-worker. Sin\xF3nimos: publicar mensaje, comunicar workers, enviar bus" },
20170
20178
  { id: "bus_read", name: "bus_read", category: "agents", description: "Leer mensajes no le\xEDdos del Agent Bus. Sin\xF3nimos: leer mensajes bus, recibir mensajes, verificar bus" },
20171
- { id: "project_updates", name: "project_updates", category: "agents", description: "Obtener actualizaciones recientes de workers en el mismo proyecto. Sin\xF3nimos: actualizaciones proyecto, estado workers, progreso equipo" },
20172
20179
  { id: "canvas_render", name: "canvas_render", category: "canvas", description: "Renderizar un componente o visualizaci\xF3n en el canvas. Sin\xF3nimos: renderizar, visualizar, gr\xE1fico, diagrama" },
20173
20180
  { id: "canvas_ask", name: "canvas_ask", category: "canvas", description: "Mostrar formulario interactivo y esperar input del usuario. Sin\xF3nimos: formulario interactivo, preguntar usuario, input" },
20174
20181
  { id: "canvas_confirm", name: "canvas_confirm", category: "canvas", description: "Mostrar di\xE1logo de confirmaci\xF3n antes de ejecutar una acci\xF3n. Sin\xF3nimos: confirmar acci\xF3n, di\xE1logo, aprobar" },
@@ -20363,9 +20370,9 @@ Estos lineamientos tienen M\xC1XIMA prioridad sobre cualquier otra instrucci\xF3
20363
20370
  applicable_to: JSON.stringify(["code", "development"])
20364
20371
  },
20365
20372
  {
20366
- rule: "Al crear proyectos, divide las tareas en pasos at\xF3micos que puedan ejecutarse independientemente",
20373
+ rule: "Al delegar trabajo complejo a workers, divide el objetivo en pasos at\xF3micos que puedan ejecutarse independientemente",
20367
20374
  category: "agent_creation",
20368
- applicable_to: JSON.stringify(["project_management", "tasks"])
20375
+ applicable_to: JSON.stringify(["delegation", "workers", "tasks"])
20369
20376
  },
20370
20377
  {
20371
20378
  rule: "Guarda las preferencias importantes del usuario en el scratchpad usando la herramienta save_note para persistencia entre sesiones",
@@ -23245,7 +23252,8 @@ function resolveContext(options2) {
23245
23252
  }
23246
23253
  const coordinatorAgent = db.query("SELECT id FROM agents WHERE role = 'coordinator' LIMIT 1").get();
23247
23254
  const agentId = coordinatorAgent?.id || "bee";
23248
- return { userId, agentId, isNewUser };
23255
+ const threadId = userId;
23256
+ return { userId, threadId, agentId, isNewUser };
23249
23257
  }
23250
23258
  var init_resolver = __esm(() => {
23251
23259
  init_sqlite();
@@ -66997,7 +67005,7 @@ function getRecentMessages(threadId, n) {
66997
67005
  const db = getDb();
66998
67006
  const rows = db.query(`
66999
67007
  SELECT * FROM conversations
67000
- WHERE thread_id = ?
67008
+ WHERE thread_id = ? AND role != 'tool'
67001
67009
  ORDER BY id DESC
67002
67010
  LIMIT ?
67003
67011
  `).all(threadId, n);
@@ -67042,13 +67050,6 @@ function toAPIMessages(rows) {
67042
67050
  } catch {}
67043
67051
  }
67044
67052
  const msg = { role: r.role, content };
67045
- if (r.tool_calls_json) {
67046
- try {
67047
- msg.tool_calls = JSON.parse(r.tool_calls_json);
67048
- } catch {}
67049
- }
67050
- if (r.tool_call_id)
67051
- msg.tool_call_id = r.tool_call_id;
67052
67053
  if (r.reasoning_content)
67053
67054
  msg.reasoning_content = r.reasoning_content;
67054
67055
  return msg;
@@ -67595,10 +67596,10 @@ function enrichToolDescription(tool) {
67595
67596
  const extra = keywordsByCategory[tool.category] ?? "";
67596
67597
  return `${tool.description} ${extra}`;
67597
67598
  }
67598
- function mcpToolFullName(_serverName, toolName) {
67599
+ function mcpToolFullName(serverName, toolName) {
67599
67600
  const safe = (s) => s.replace(/\s+/g, "_").replace(/[^a-zA-Z0-9_\-]/g, "_");
67600
- const sanitized = safe(toolName);
67601
- const trimmed = sanitized.length > 64 ? sanitized.substring(0, 64) : sanitized;
67601
+ const full = `${safe(serverName)}__${safe(toolName)}`;
67602
+ const trimmed = full.length > 64 ? full.substring(0, 64) : full;
67602
67603
  return /^[a-zA-Z_]/.test(trimmed) ? trimmed : `_${trimmed}`.substring(0, 64);
67603
67604
  }
67604
67605
  var log25, STOPWORDS, CORE_TOOL_CATALOG;
@@ -231321,7 +231322,7 @@ Focus ONLY on this task. Do not deviate.`;
231321
231322
  skills: allSkills
231322
231323
  };
231323
231324
  }
231324
- var log62, KEEP_LAST_N_MESSAGES2 = 15, DEFAULT_CONTEXT_WINDOW = 250000, COMPACT_RATIO = 0.8, MAX_SYSTEM_PROMPT_CHARS_CAP = 128000, MINIMAL_TOOLS, MINIMAL_SKILL_NAMES2;
231325
+ var log62, KEEP_LAST_N_MESSAGES2 = 30, DEFAULT_CONTEXT_WINDOW = 250000, COMPACT_RATIO = 0.8, MAX_SYSTEM_PROMPT_CHARS_CAP = 128000, MINIMAL_TOOLS, MINIMAL_SKILL_NAMES2;
231325
231326
  var init_context_compiler = __esm(() => {
231326
231327
  init_sqlite();
231327
231328
  init_logger();
@@ -231350,7 +231351,23 @@ var init_context_compiler = __esm(() => {
231350
231351
  });
231351
231352
 
231352
231353
  // packages/core/src/tool-runtime/index.ts
231354
+ import { existsSync as existsSync23 } from "fs";
231355
+ import { fileURLToPath } from "url";
231353
231356
  import { availableParallelism as availableParallelism2 } from "os";
231357
+ function resolveWorkerEntry() {
231358
+ const candidates = [
231359
+ new URL("./tool-worker.js", import.meta.url),
231360
+ new URL("./tool-worker.ts", import.meta.url),
231361
+ new URL("../packages/core/src/tool-runtime/tool-worker.js", import.meta.url),
231362
+ new URL("../packages/core/src/tool-runtime/tool-worker.ts", import.meta.url)
231363
+ ];
231364
+ for (const candidate of candidates) {
231365
+ if (existsSync23(fileURLToPath(candidate))) {
231366
+ return candidate.href;
231367
+ }
231368
+ }
231369
+ throw new Error(`Tool worker entry not found. Tried: ${candidates.map((candidate) => fileURLToPath(candidate)).join(", ")}`);
231370
+ }
231354
231371
  function serializeError(error54) {
231355
231372
  const err = error54 instanceof Error ? error54 : new Error(String(error54));
231356
231373
  return {
@@ -231462,7 +231479,7 @@ class ToolWorkerPool {
231462
231479
  return slot;
231463
231480
  }
231464
231481
  createSlot() {
231465
- const worker = new Worker(new URL("./tool-worker.ts", import.meta.url).href, { type: "module" });
231482
+ const worker = new Worker(resolveWorkerEntry(), { type: "module" });
231466
231483
  const slot = { worker, busy: false };
231467
231484
  worker.onmessage = (event) => {
231468
231485
  const message = event.data;
@@ -231486,13 +231503,15 @@ class ToolWorkerPool {
231486
231503
  const job = slot.job;
231487
231504
  if (!job)
231488
231505
  return;
231506
+ const location = [event.filename, event.lineno, event.colno].filter(Boolean).join(":");
231507
+ const message = location ? `${event.message || "Tool worker failed"} (${location})` : event.message || "Tool worker failed";
231489
231508
  this.finishJob(slot, {
231490
231509
  toolCall: job.toolCall,
231491
231510
  toolName: job.toolCall.function.name,
231492
- result: toolErrorResult(job.toolCall.function.name, event.message || "Tool worker failed"),
231511
+ result: toolErrorResult(job.toolCall.function.name, message),
231493
231512
  ok: false,
231494
231513
  durationMs: Math.round(performance.now() - job.startedAt),
231495
- error: { name: "WorkerError", message: event.message || "Tool worker failed" }
231514
+ error: { name: "WorkerError", message }
231496
231515
  }, true);
231497
231516
  };
231498
231517
  return slot;
@@ -231650,6 +231669,24 @@ var DEFAULT_MAIN_THREAD_TOOL_NAMES, sharedPool = null, sharedPoolSize = 0;
231650
231669
  var init_tool_runtime = __esm(() => {
231651
231670
  init_loader();
231652
231671
  DEFAULT_MAIN_THREAD_TOOL_NAMES = new Set([
231672
+ "search_knowledge",
231673
+ "save_note",
231674
+ "memory_write",
231675
+ "memory_read",
231676
+ "memory_list",
231677
+ "memory_search",
231678
+ "memory_delete",
231679
+ "agent_create",
231680
+ "agent_find",
231681
+ "agent_archive",
231682
+ "task_status",
231683
+ "bus_publish",
231684
+ "bus_read",
231685
+ "get_available_models",
231686
+ "meeting_start",
231687
+ "meeting_add_segment",
231688
+ "meeting_stop",
231689
+ "meeting_report",
231653
231690
  "browser_navigate",
231654
231691
  "browser_screenshot",
231655
231692
  "browser_click",
@@ -231775,13 +231812,6 @@ async function* runAgent(opts) {
231775
231812
  tool_calls: response.tool_calls,
231776
231813
  reasoning_content: response.reasoning_content
231777
231814
  });
231778
- if (!opts.isolated) {
231779
- addMessage(opts.threadId, "assistant", response.content || "", {
231780
- channel: opts.channel,
231781
- tool_calls: response.tool_calls,
231782
- reasoning_content: response.reasoning_content
231783
- });
231784
- }
231785
231815
  for (const tc of response.tool_calls) {
231786
231816
  const toolName = tc.function.name;
231787
231817
  emitCanvas("canvas:node_update", {
@@ -231845,12 +231875,6 @@ async function* runAgent(opts) {
231845
231875
  content: toolResultLLM,
231846
231876
  tool_call_id: tc.id
231847
231877
  });
231848
- if (!opts.isolated) {
231849
- addMessage(opts.threadId, "tool", toolResultLLM, {
231850
- channel: opts.channel,
231851
- tool_call_id: tc.id
231852
- });
231853
- }
231854
231878
  if (toolName === "search_knowledge") {
231855
231879
  try {
231856
231880
  const result = toolResultJS;
@@ -232171,8 +232195,7 @@ class AgentRunner {
232171
232195
  this.config = config2;
232172
232196
  }
232173
232197
  async generate(options2) {
232174
- const db = getDb();
232175
- const agentId = resolveAgentId(null) || "main";
232198
+ const agentId = options2.agentId || resolveAgentId(null) || "main";
232176
232199
  const userId = options2.userId || resolveUserId({});
232177
232200
  if (!userId) {
232178
232201
  throw new Error("No userId provided. Please complete onboarding first.");
@@ -232279,7 +232302,6 @@ class AgentRunner {
232279
232302
  }
232280
232303
  var init_providers = __esm(() => {
232281
232304
  init_logger();
232282
- init_sqlite();
232283
232305
  init_agent_loop();
232284
232306
  init_onboarding();
232285
232307
  });
@@ -245615,7 +245637,7 @@ var require_dist8 = __commonJS((exports2, module2) => {
245615
245637
  }
245616
245638
  __name(getDefaultStrategy, "getDefaultStrategy");
245617
245639
  var import_node_http = __require("http");
245618
- var import_node_url = __require("url");
245640
+ var import_node_url2 = __require("url");
245619
245641
  var import_node_util3 = __require("util");
245620
245642
  var import_undici = __require("undici");
245621
245643
  async function makeRequest(url2, init) {
@@ -245654,7 +245676,7 @@ var require_dist8 = __commonJS((exports2, module2) => {
245654
245676
  return body;
245655
245677
  } else if (import_node_util3.types.isArrayBuffer(body)) {
245656
245678
  return new Uint8Array(body);
245657
- } else if (body instanceof import_node_url.URLSearchParams) {
245679
+ } else if (body instanceof import_node_url2.URLSearchParams) {
245658
245680
  return body.toString();
245659
245681
  } else if (body instanceof DataView) {
245660
245682
  return new Uint8Array(body.buffer);
@@ -268299,7 +268321,7 @@ var require_dist12 = __commonJS((exports2, module2) => {
268299
268321
  var import_node_events2 = __require("events");
268300
268322
  var import_node_timers = __require("timers");
268301
268323
  var import_promises22 = __require("timers/promises");
268302
- var import_node_url = __require("url");
268324
+ var import_node_url2 = __require("url");
268303
268325
  var import_node_util3 = __require("util");
268304
268326
  var import_node_zlib = __require("zlib");
268305
268327
  var import_collection5 = require_dist5();
@@ -268484,7 +268506,7 @@ var require_dist12 = __commonJS((exports2, module2) => {
268484
268506
  throw new Error("Tried to connect a shard that wasn't idle");
268485
268507
  }
268486
268508
  const { version: version22, encoding, compression } = this.strategy.options;
268487
- const params = new import_node_url.URLSearchParams({ v: version22, encoding });
268509
+ const params = new import_node_url2.URLSearchParams({ v: version22, encoding });
268488
268510
  if (compression) {
268489
268511
  const zlib = await getZlibSync();
268490
268512
  if (zlib) {
@@ -418130,7 +418152,7 @@ var require_main = __commonJS((exports2, module2) => {
418130
418152
  });
418131
418153
 
418132
418154
  // packages/core/src/channels/whatsapp.ts
418133
- import { existsSync as existsSync23, mkdirSync as mkdirSync11, rmSync as rmSync2 } from "fs";
418155
+ import { existsSync as existsSync24, mkdirSync as mkdirSync11, rmSync as rmSync2 } from "fs";
418134
418156
  import * as path21 from "path";
418135
418157
  function createWhatsAppChannel(config2) {
418136
418158
  return new WhatsAppChannel(config2);
@@ -418171,7 +418193,7 @@ var init_whatsapp = __esm(() => {
418171
418193
  getAuthPath(agentId, accountId) {
418172
418194
  const baseDir = process.env.HOME ?? "";
418173
418195
  const authDir = path21.join(baseDir, ".hive", "agents", agentId, "whatsapp", accountId);
418174
- if (!existsSync23(authDir)) {
418196
+ if (!existsSync24(authDir)) {
418175
418197
  mkdirSync11(authDir, { recursive: true });
418176
418198
  }
418177
418199
  return authDir;
@@ -418273,7 +418295,7 @@ var init_whatsapp = __esm(() => {
418273
418295
  }
418274
418296
  hasCredentials() {
418275
418297
  const credsFile = path21.join(this.authPath, "creds.json");
418276
- return existsSync23(credsFile);
418298
+ return existsSync24(credsFile);
418277
418299
  }
418278
418300
  getConnectionState() {
418279
418301
  return { ...this.connectionState };
@@ -477264,10 +477286,10 @@ var init_migrate = __esm(() => {
477264
477286
  });
477265
477287
 
477266
477288
  // packages/core/src/gateway/initializer.ts
477267
- import { mkdirSync as mkdirSync12, existsSync as existsSync24 } from "fs";
477289
+ import { mkdirSync as mkdirSync12, existsSync as existsSync25 } from "fs";
477268
477290
  import * as path23 from "path";
477269
477291
  async function verifyDatabaseUsers() {
477270
- if (!existsSync24(getDbPathLazy())) {
477292
+ if (!existsSync25(getDbPathLazy())) {
477271
477293
  log67.info("Setup mode: no database found \u2014 gateway will serve web setup at /setup");
477272
477294
  return;
477273
477295
  }
@@ -479426,7 +479448,7 @@ class ParallelStrategy {
479426
479448
  }
479427
479449
 
479428
479450
  // packages/core/src/scheduler/dag/DAGScheduler.ts
479429
- import { writeFileSync as writeFileSync9, mkdirSync as mkdirSync14, existsSync as existsSync25 } from "fs";
479451
+ import { writeFileSync as writeFileSync9, mkdirSync as mkdirSync14, existsSync as existsSync26 } from "fs";
479430
479452
  import * as path26 from "path";
479431
479453
 
479432
479454
  class DAGScheduler {
@@ -479567,7 +479589,7 @@ class DAGScheduler {
479567
479589
  if (!silent) {
479568
479590
  try {
479569
479591
  const logDir = path26.join(process.cwd(), "packages", "core", "logs");
479570
- if (!existsSync25(logDir))
479592
+ if (!existsSync26(logDir))
479571
479593
  mkdirSync14(logDir, { recursive: true });
479572
479594
  const logFile = path26.join(logDir, `dag-${sessionId.slice(0, 8)}.log`);
479573
479595
  writeFileSync9(logFile, output + `
@@ -481004,7 +481026,7 @@ var init_detect = __esm(() => {
481004
481026
  });
481005
481027
 
481006
481028
  // packages/core/src/gateway/tts/src/install.ts
481007
- import { existsSync as existsSync26, mkdirSync as mkdirSync15, readdirSync as readdirSync4, renameSync as renameSync2 } from "fs";
481029
+ import { existsSync as existsSync27, mkdirSync as mkdirSync15, readdirSync as readdirSync4, renameSync as renameSync2 } from "fs";
481008
481030
  import { join as join18 } from "path";
481009
481031
  async function downloadFile3(url2, dest) {
481010
481032
  const filename = url2.split("/").pop();
@@ -481042,7 +481064,7 @@ async function runInstall(ttsRoot) {
481042
481064
  const platform2 = detectPlatform2();
481043
481065
  const binaryName = getPiperBinaryName(platform2);
481044
481066
  const binaryPath = join18(BIN_DIR2, binaryName);
481045
- if (!existsSync26(binaryPath)) {
481067
+ if (!existsSync27(binaryPath)) {
481046
481068
  const url2 = PIPER_URLS[platform2];
481047
481069
  const archiveExt = url2.endsWith(".zip") ? ".zip" : ".tar.gz";
481048
481070
  const archivePath = join18(BIN_DIR2, `piper${archiveExt}`);
@@ -481055,7 +481077,7 @@ async function runInstall(ttsRoot) {
481055
481077
  await extractTarGz(archivePath, BIN_DIR2);
481056
481078
  }
481057
481079
  const piperSubdir = join18(BIN_DIR2, "piper");
481058
- if (existsSync26(piperSubdir)) {
481080
+ if (existsSync27(piperSubdir)) {
481059
481081
  const tempDir = join18(BIN_DIR2, "_piper_tmp");
481060
481082
  renameSync2(piperSubdir, tempDir);
481061
481083
  for (const entry of readdirSync4(tempDir)) {
@@ -481063,7 +481085,7 @@ async function runInstall(ttsRoot) {
481063
481085
  }
481064
481086
  await Bun.spawn(["rm", "-rf", tempDir]).exited;
481065
481087
  }
481066
- if (!existsSync26(binaryPath)) {
481088
+ if (!existsSync27(binaryPath)) {
481067
481089
  throw new Error(`Binario no encontrado tras extracci\xF3n: ${binaryPath}`);
481068
481090
  }
481069
481091
  if (!platform2.startsWith("windows")) {
@@ -481075,7 +481097,7 @@ async function runInstall(ttsRoot) {
481075
481097
  }
481076
481098
  const modelPath = join18(VOICES_DIR, `${DEFAULT_VOICE}.onnx`);
481077
481099
  const configPath = join18(VOICES_DIR, `${DEFAULT_VOICE}.onnx.json`);
481078
- if (!existsSync26(modelPath) || !existsSync26(configPath)) {
481100
+ if (!existsSync27(modelPath) || !existsSync27(configPath)) {
481079
481101
  log71.info(`Descargando modelo de voz ${DEFAULT_VOICE}...`);
481080
481102
  await downloadFile3(VOICE_URLS.model, modelPath);
481081
481103
  await downloadFile3(VOICE_URLS.config, configPath);
@@ -481097,20 +481119,20 @@ var init_install = __esm(() => {
481097
481119
  });
481098
481120
 
481099
481121
  // packages/core/src/gateway/tts/src/server.ts
481100
- import { existsSync as existsSync27, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "fs";
481122
+ import { existsSync as existsSync28, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "fs";
481101
481123
  import { join as join19 } from "path";
481102
481124
  import { homedir as homedir3 } from "os";
481103
481125
  function getPiperPath() {
481104
481126
  const platform2 = detectPlatform2();
481105
481127
  const binaryName = getPiperBinaryName(platform2);
481106
481128
  const binaryPath = join19(BIN_DIR2, binaryName);
481107
- if (!existsSync27(binaryPath)) {
481129
+ if (!existsSync28(binaryPath)) {
481108
481130
  throw new Error("Piper no instalado. Ejecuta: bun run src/install.ts");
481109
481131
  }
481110
481132
  return binaryPath;
481111
481133
  }
481112
481134
  function listVoices() {
481113
- if (!existsSync27(VOICES_DIR))
481135
+ if (!existsSync28(VOICES_DIR))
481114
481136
  return [];
481115
481137
  return readdirSync5(VOICES_DIR).filter((f2) => f2.endsWith(".onnx")).map((f2) => f2.replace(".onnx", ""));
481116
481138
  }
@@ -481118,12 +481140,12 @@ async function synthesize(text2, voice) {
481118
481140
  const piperPath = getPiperPath();
481119
481141
  let modelPath = join19(VOICES_DIR, `${voice}.onnx`);
481120
481142
  let configPath = join19(VOICES_DIR, `${voice}.onnx.json`);
481121
- if (!existsSync27(modelPath)) {
481143
+ if (!existsSync28(modelPath)) {
481122
481144
  console.warn(`[TTS] Voz no encontrada: ${voice}. Usando por defecto: ${DEFAULT_VOICE}`);
481123
481145
  voice = DEFAULT_VOICE;
481124
481146
  modelPath = join19(VOICES_DIR, `${voice}.onnx`);
481125
481147
  configPath = join19(VOICES_DIR, `${voice}.onnx.json`);
481126
- if (!existsSync27(modelPath)) {
481148
+ if (!existsSync28(modelPath)) {
481127
481149
  throw new Error(`Ni siquiera la voz por defecto se encuentra: ${voice}`);
481128
481150
  }
481129
481151
  }
@@ -481131,7 +481153,7 @@ async function synthesize(text2, voice) {
481131
481153
  let noiseScale = 0.6;
481132
481154
  let noiseW = 0.75;
481133
481155
  let sentenceSilence = 0.2;
481134
- if (existsSync27(configPath)) {
481156
+ if (existsSync28(configPath)) {
481135
481157
  try {
481136
481158
  const config2 = JSON.parse(readFileSync11(configPath, "utf-8"));
481137
481159
  const inference = config2.inference || {};
@@ -481276,16 +481298,16 @@ var init_server = __esm(() => {
481276
481298
  });
481277
481299
 
481278
481300
  // packages/core/src/gateway/routes/tts-local.ts
481279
- import { existsSync as existsSync28, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "fs";
481301
+ import { existsSync as existsSync29, readdirSync as readdirSync6, readFileSync as readFileSync12 } from "fs";
481280
481302
  import { join as join20 } from "path";
481281
481303
  import { homedir as homedir4 } from "os";
481282
481304
  function isInstalled() {
481283
- const piperExists = existsSync28(BIN_PATH);
481305
+ const piperExists = existsSync29(BIN_PATH);
481284
481306
  const voiceExists = getInstalledVoices().length > 0;
481285
481307
  return { piperExists, voiceExists, installed: piperExists && voiceExists };
481286
481308
  }
481287
481309
  function getInstalledVoices() {
481288
- if (!existsSync28(VOICES_DIR2))
481310
+ if (!existsSync29(VOICES_DIR2))
481289
481311
  return [];
481290
481312
  const files = readdirSync6(VOICES_DIR2);
481291
481313
  return files.filter((f2) => f2.endsWith(".onnx")).map((f2) => f2.replace(".onnx", ""));
@@ -481463,7 +481485,7 @@ async function handleGetInstalledVoices(req, addCors) {
481463
481485
  const model = getModelById(id);
481464
481486
  let inferenceConfig = { length_scale: 1, noise_scale: 0.667, noise_w: 0.8 };
481465
481487
  const configPath = join20(VOICES_DIR2, `${id}.onnx.json`);
481466
- if (existsSync28(configPath)) {
481488
+ if (existsSync29(configPath)) {
481467
481489
  try {
481468
481490
  const config2 = JSON.parse(readFileSync12(configPath, "utf-8"));
481469
481491
  inferenceConfig = { ...inferenceConfig, ...config2.inference };
@@ -481557,7 +481579,7 @@ var init_tts_local = __esm(() => {
481557
481579
  });
481558
481580
 
481559
481581
  // packages/core/src/gateway/routes/llm-local.ts
481560
- import { existsSync as existsSync29 } from "fs";
481582
+ import { existsSync as existsSync30 } from "fs";
481561
481583
  import { join as join21 } from "path";
481562
481584
  import { homedir as homedir5 } from "os";
481563
481585
  async function getInstalledStatus() {
@@ -481565,7 +481587,7 @@ async function getInstalledStatus() {
481565
481587
  const gpu = await detectGPU();
481566
481588
  const ext = process.platform === "win32" ? ".exe" : "";
481567
481589
  const binaryPath = join21(BIN_DIR_PATH, `llama-${LLAMA_CPP_DEFAULT_VER2}/llama-server${ext}`);
481568
- const binaryExists = existsSync29(binaryPath);
481590
+ const binaryExists = existsSync30(binaryPath);
481569
481591
  const models = listLocalModels();
481570
481592
  const anyModelExists = models.some((m2) => m2.downloaded);
481571
481593
  const activeServers = llamaManager.getStatus();
@@ -481866,7 +481888,7 @@ var package_default;
481866
481888
  var init_package = __esm(() => {
481867
481889
  package_default = {
481868
481890
  name: "@johpaz/hive-agents",
481869
- version: "0.0.36",
481891
+ version: "0.0.38",
481870
481892
  description: "Tu colmena de agentes IA. Local-first. Multi-canal. Open source. Construido desde Colombia para el mundo.",
481871
481893
  private: false,
481872
481894
  bin: {
@@ -481930,6 +481952,7 @@ var init_package = __esm(() => {
481930
481952
  },
481931
481953
  files: [
481932
481954
  "dist/hive.js",
481955
+ "dist/tool-worker.js",
481933
481956
  "dist/hive.cmd",
481934
481957
  "dist/hive.ps1",
481935
481958
  "dist/ui",
@@ -481969,7 +481992,7 @@ var init_package = __esm(() => {
481969
481992
  "doctor:dev": "HIVE_HOME=$HOME/.hive-dev HIVE_DEV=true bun run packages/cli/src/index.ts doctor",
481970
481993
  "dev:keep": "HIVE_HOME=$HOME/.hive-dev HIVE_DEV=true HIVE_DEV_CLEAN=false bun run packages/cli/src/index.ts dev",
481971
481994
  start: "bun run packages/cli/src/index.ts start",
481972
- build: "bun packages/skills/scripts/generate-bundle.ts && bun build packages/cli/src/index.ts --bundle --outfile dist/hive.js --target bun && cd packages/hive-ui && bun run build && cd ../.. && cp -r packages/hive-ui/dist dist/ui && bun packages/cli/scripts/postbuild.ts",
481995
+ build: "bun packages/skills/scripts/generate-bundle.ts && bun build packages/cli/src/index.ts --bundle --outfile dist/hive.js --target bun && bun build packages/core/src/tool-runtime/tool-worker.ts --outfile dist/tool-worker.js --target bun && cd packages/hive-ui && bun run build && cd ../.. && cp -r packages/hive-ui/dist dist/ui && bun packages/cli/scripts/postbuild.ts",
481973
481996
  "build:binary": "cd packages/hive-ui && bun run build && cd ../cli && bun scripts/generate-ui-bundle.ts && bun build src/index.ts --compile --outfile ../../dist/hive-binary",
481974
481997
  prepublishOnly: "bun run build",
481975
481998
  test: "bun test",
@@ -482351,6 +482374,10 @@ var init_providers3 = __esm(() => {
482351
482374
  });
482352
482375
 
482353
482376
  // packages/core/src/gateway/routes/chat.ts
482377
+ function resolveChatThreadId(finalUserId, requestedThreadId) {
482378
+ const trimmedThreadId = requestedThreadId?.trim();
482379
+ return trimmedThreadId || finalUserId || "default";
482380
+ }
482354
482381
  async function handleChat(req, addCorsHeaders) {
482355
482382
  try {
482356
482383
  const body = await req.json();
@@ -482364,7 +482391,7 @@ async function handleChat(req, addCorsHeaders) {
482364
482391
  const db = getDb();
482365
482392
  const finalUserId = userId || resolveUserId({ channel }) || "default";
482366
482393
  const finalAgentId = agentId || resolveAgentId(null) || "main";
482367
- const threadId = thread_id || `${finalUserId}-${Date.now()}`;
482394
+ const threadId = resolveChatThreadId(finalUserId, thread_id);
482368
482395
  log74.info(`[chat] Processing message from user=${finalUserId} agent=${finalAgentId} thread=${threadId}`);
482369
482396
  const userRow = db.query("SELECT timezone FROM users WHERE id = ?").get(finalUserId);
482370
482397
  const userTimezone = userRow?.timezone || "UTC";
@@ -482381,14 +482408,7 @@ async function handleChat(req, addCorsHeaders) {
482381
482408
  }
482382
482409
  const messageContent = `[Timestamp: ${exactTime} (${userTimezone})]
482383
482410
  ${message}`;
482384
- const history2 = getRecentMessages(threadId, 15);
482385
- const messages2 = [
482386
- ...history2.map((row) => ({
482387
- role: row.role,
482388
- content: row.content
482389
- })),
482390
- { role: "user", content: messageContent }
482391
- ];
482411
+ const messages2 = [{ role: "user", content: messageContent }];
482392
482412
  const agent = db.query("SELECT provider_id, model_id FROM agents WHERE id = ?").get(finalAgentId);
482393
482413
  const provider = agent?.provider_id || "gemini";
482394
482414
  const runner = new AgentRunner({});
@@ -482407,6 +482427,7 @@ ${message}`;
482407
482427
  maxSteps: 15,
482408
482428
  threadId,
482409
482429
  userId: finalUserId,
482430
+ agentId: finalAgentId,
482410
482431
  channel,
482411
482432
  onStep: async (step) => {
482412
482433
  if (step.type === "text" && step.message) {
@@ -482460,11 +482481,11 @@ ${message}`;
482460
482481
  async function handleGetChatHistory(req, addCorsHeaders) {
482461
482482
  const url2 = new URL(req.url);
482462
482483
  const threadId = url2.searchParams.get("sessionId") || url2.searchParams.get("threadId") || "default";
482463
- const limit2 = parseInt(url2.searchParams.get("limit") || "15");
482484
+ const limit2 = parseInt(url2.searchParams.get("limit") || String(DEFAULT_CHAT_HISTORY_LIMIT));
482464
482485
  const messages2 = getDb().query(`
482465
482486
  SELECT id, thread_id, channel, role, content, tool_calls_json, tool_call_id, reasoning_content, token_count, created_at, updated_at FROM conversations
482466
482487
  WHERE thread_id = ? AND role IN ('user', 'assistant')
482467
- ORDER BY created_at DESC
482488
+ ORDER BY id DESC
482468
482489
  LIMIT ?
482469
482490
  `).all(threadId, limit2);
482470
482491
  return addCorsHeaders(Response.json({ messages: messages2.reverse() }), req);
@@ -482478,12 +482499,11 @@ async function handleGetNotes(req, addCorsHeaders) {
482478
482499
  `).all();
482479
482500
  return addCorsHeaders(Response.json({ notes }), req);
482480
482501
  }
482481
- var log74;
482502
+ var log74, DEFAULT_CHAT_HISTORY_LIMIT = 40;
482482
482503
  var init_chat3 = __esm(() => {
482483
482504
  init_sqlite();
482484
482505
  init_onboarding();
482485
482506
  init_lane_queue();
482486
- init_conversation_store();
482487
482507
  init_providers3();
482488
482508
  init_logger();
482489
482509
  log74 = logger.child("api:chat");
@@ -482542,7 +482562,7 @@ async function handleGetConfig(req, addCorsHeaders, config2) {
482542
482562
  var init_config = () => {};
482543
482563
 
482544
482564
  // packages/core/src/gateway/routes/workspace.ts
482545
- import { mkdirSync as mkdirSync16, existsSync as existsSync30, accessSync, constants as constants2 } from "fs";
482565
+ import { mkdirSync as mkdirSync16, existsSync as existsSync31, accessSync, constants as constants2 } from "fs";
482546
482566
  import * as path27 from "path";
482547
482567
  import { exec as exec2 } from "child_process";
482548
482568
  import { promisify as promisify4 } from "util";
@@ -482568,7 +482588,7 @@ async function handleValidateWorkspace(req, addCorsHeaders) {
482568
482588
  isAbsolute: false
482569
482589
  }), req);
482570
482590
  }
482571
- const exists = existsSync30(workspacePath);
482591
+ const exists = existsSync31(workspacePath);
482572
482592
  if (!exists) {
482573
482593
  return addCorsHeaders(Response.json({
482574
482594
  ok: true,
@@ -482650,7 +482670,7 @@ async function handleOpenWorkspace(req, addCorsHeaders) {
482650
482670
  error: "El path debe ser absoluto"
482651
482671
  }), req);
482652
482672
  }
482653
- if (!existsSync30(workspacePath)) {
482673
+ if (!existsSync31(workspacePath)) {
482654
482674
  return addCorsHeaders(Response.json({
482655
482675
  ok: false,
482656
482676
  error: "El directorio no existe"
@@ -482931,7 +482951,7 @@ var init_server2 = __esm(() => {
482931
482951
  });
482932
482952
 
482933
482953
  // packages/core/src/gateway/server.ts
482934
- import { mkdirSync as mkdirSync17, unlinkSync as unlinkSync4, existsSync as existsSync31, writeFileSync as writeFileSync10, readFileSync as readFileSync13 } from "fs";
482954
+ import { mkdirSync as mkdirSync17, unlinkSync as unlinkSync4, existsSync as existsSync32, writeFileSync as writeFileSync10, readFileSync as readFileSync13 } from "fs";
482935
482955
  import * as path29 from "path";
482936
482956
  import { cpus as osCpus } from "os";
482937
482957
  import { randomUUID as randomUUID2 } from "crypto";
@@ -482947,7 +482967,7 @@ async function startGateway(config2) {
482947
482967
  log75.info(`Starting gateway on ${host}:${port}`);
482948
482968
  const tokenFile = path29.join(getHiveDir(), ".auth_token");
482949
482969
  if (!process.env.HIVE_AUTH_TOKEN) {
482950
- if (existsSync31(tokenFile)) {
482970
+ if (existsSync32(tokenFile)) {
482951
482971
  process.env.HIVE_AUTH_TOKEN = readFileSync13(tokenFile, "utf-8").trim();
482952
482972
  log75.info("\uD83D\uDD11 Auth token loaded from persistent storage");
482953
482973
  } else {
@@ -483146,7 +483166,7 @@ ${messageContent || ""}` : messageContent || "";
483146
483166
  }
483147
483167
  }
483148
483168
  log75.info(` Content: ${messageContent.substring(0, 150)}${messageContent.length > 150 ? "..." : ""}`);
483149
- const { userId } = resolveContext({
483169
+ const { userId, threadId: conversationThreadId } = resolveContext({
483150
483170
  channel: message.channel,
483151
483171
  channelUserId: message.sessionId
483152
483172
  });
@@ -483156,7 +483176,7 @@ ${messageContent || ""}` : messageContent || "";
483156
483176
  channelManager.markAsRead(message.channel, message.sessionId, messageId),
483157
483177
  channelManager.startTyping(message.channel, message.sessionId)
483158
483178
  ]);
483159
- const unifiedSessionId = userId;
483179
+ const unifiedSessionId = conversationThreadId;
483160
483180
  const routingSessionId = message.sessionId;
483161
483181
  const userMetadata = inputType === "audio_transcribed" ? { input_type: "audio_transcribed", stt_provider: sttProviderUsed, channel: message.channel } : inputType === "image" || inputType === "document" ? { input_type: inputType, ocr_provider: visionConfig.ocrProvider, channel: message.channel } : { input_type: "text", channel: message.channel };
483162
483182
  const userRow = getDb().query("SELECT * FROM users WHERE id = ?").get(userId);
@@ -483414,7 +483434,7 @@ ${messageContent}`;
483414
483434
  if (isDev) {
483415
483435
  const uiDir2 = path29.join(process.cwd(), "packages/hive-ui/dist");
483416
483436
  const indexPath = path29.join(uiDir2, "index.html");
483417
- if (!existsSync31(indexPath)) {
483437
+ if (!existsSync32(indexPath)) {
483418
483438
  return new Response(`UI build not found. Please run: cd packages/hive-ui && bun run build
483419
483439
 
483420
483440
  ` + "Or use: bun run dev (from root) which builds automatically.", { status: 503, headers: { "Content-Type": "text/plain" } });
@@ -483454,7 +483474,7 @@ ${messageContent}`;
483454
483474
  const uiDirFromHive = path29.join(getHiveDir(), "ui");
483455
483475
  const uiDirFromDist = process.env.HIVE_DIST_DIR ? path29.join(process.env.HIVE_DIST_DIR, "ui") : null;
483456
483476
  const uiDirFromCwd = path29.join(process.cwd(), "packages/hive-ui/dist");
483457
- const uiDir = uiDirFromEnv || (existsSync31(path29.join(uiDirFromHive, "index.html")) ? uiDirFromHive : uiDirFromDist && existsSync31(path29.join(uiDirFromDist, "index.html")) ? uiDirFromDist : uiDirFromCwd);
483477
+ const uiDir = uiDirFromEnv || (existsSync32(path29.join(uiDirFromHive, "index.html")) ? uiDirFromHive : uiDirFromDist && existsSync32(path29.join(uiDirFromDist, "index.html")) ? uiDirFromDist : uiDirFromCwd);
483458
483478
  let subPath = url2.pathname;
483459
483479
  if (gatewaySetupMode && (subPath === "/" || subPath === "/ui" || subPath === "/ui/")) {
483460
483480
  const _publicBase = process.env.HIVE_PUBLIC_URL?.replace(/\/$/, "") ?? `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
@@ -484318,7 +484338,7 @@ ${messageContent}`;
484318
484338
  return;
484319
484339
  }
484320
484340
  try {
484321
- const { userId } = resolveContext({ channel: "webchat", channelUserId: sessionId });
484341
+ const { userId, threadId: conversationThreadId } = resolveContext({ channel: "webchat", channelUserId: sessionId });
484322
484342
  const messages2 = [{ role: "user", content: interactionMsg }];
484323
484343
  let streamedContent = "";
484324
484344
  const messageId = crypto.randomUUID();
@@ -484326,9 +484346,9 @@ ${messageContent}`;
484326
484346
  provider: dbProvider,
484327
484347
  messages: messages2,
484328
484348
  maxTokens: 4096,
484329
- tools: prepareTools(agent, sessionId),
484349
+ tools: prepareTools(agent, conversationThreadId),
484330
484350
  maxSteps: 15,
484331
- threadId: sessionId,
484351
+ threadId: conversationThreadId,
484332
484352
  userId,
484333
484353
  onToken: async (token) => {
484334
484354
  if (signal2.aborted)
@@ -484380,7 +484400,7 @@ ${messageContent}`;
484380
484400
  return;
484381
484401
  }
484382
484402
  try {
484383
- const { userId } = resolveContext({ channel: "webchat", channelUserId: sessionId });
484403
+ const { userId, threadId: conversationThreadId } = resolveContext({ channel: "webchat", channelUserId: sessionId });
484384
484404
  const messages2 = [{ role: "user", content: interactionMsg }];
484385
484405
  let streamedContent = "";
484386
484406
  const messageId = crypto.randomUUID();
@@ -484388,9 +484408,9 @@ ${messageContent}`;
484388
484408
  provider: dbProvider,
484389
484409
  messages: messages2,
484390
484410
  maxTokens: 4096,
484391
- tools: prepareTools(agent, sessionId),
484411
+ tools: prepareTools(agent, conversationThreadId),
484392
484412
  maxSteps: 15,
484393
- threadId: sessionId,
484413
+ threadId: conversationThreadId,
484394
484414
  userId,
484395
484415
  onToken: async (token) => {
484396
484416
  if (signal2.aborted)
@@ -484500,13 +484520,14 @@ ${messageContent}`;
484500
484520
  return;
484501
484521
  }
484502
484522
  try {
484503
- const unifiedSessionId = msg.sessionId;
484504
- const messages2 = [{ role: "user", content: messageContent }];
484505
- log75.info(`Generating response for session ${unifiedSessionId}...`);
484506
- const { userId } = resolveContext({
484523
+ const { userId, threadId: conversationThreadId } = resolveContext({
484507
484524
  channel: "webchat",
484508
484525
  channelUserId: msg.sessionId
484509
484526
  });
484527
+ const unifiedSessionId = conversationThreadId;
484528
+ const routingSessionId = msg.sessionId;
484529
+ const messages2 = [{ role: "user", content: messageContent }];
484530
+ log75.info(`Generating response for session ${unifiedSessionId}...`);
484510
484531
  let streamedContent = "";
484511
484532
  let messageId = crypto.randomUUID();
484512
484533
  const response = await runner.generate({
@@ -484524,7 +484545,7 @@ ${messageContent}`;
484524
484545
  ws.send(JSON.stringify({
484525
484546
  type: "message",
484526
484547
  id: messageId,
484527
- sessionId: unifiedSessionId,
484548
+ sessionId: routingSessionId,
484528
484549
  content: token,
484529
484550
  isChunk: true,
484530
484551
  isStep: false
@@ -484538,7 +484559,7 @@ ${messageContent}`;
484538
484559
  if (trimmedMessage) {
484539
484560
  ws.send(JSON.stringify({
484540
484561
  type: "progress",
484541
- sessionId: unifiedSessionId,
484562
+ sessionId: routingSessionId,
484542
484563
  content: trimmedMessage
484543
484564
  }));
484544
484565
  }
@@ -484548,7 +484569,7 @@ ${messageContent}`;
484548
484569
  const narration = getNarration(step.toolName);
484549
484570
  ws.send(JSON.stringify({
484550
484571
  type: "progress",
484551
- sessionId: unifiedSessionId,
484572
+ sessionId: routingSessionId,
484552
484573
  content: narration
484553
484574
  }));
484554
484575
  return;
@@ -484561,7 +484582,7 @@ ${messageContent}`;
484561
484582
  if (userMessage) {
484562
484583
  ws.send(JSON.stringify({
484563
484584
  type: "progress",
484564
- sessionId: unifiedSessionId,
484585
+ sessionId: routingSessionId,
484565
484586
  content: userMessage
484566
484587
  }));
484567
484588
  }
@@ -484578,14 +484599,14 @@ ${messageContent}`;
484578
484599
  let responseType = "text";
484579
484600
  let ttsProviderUsed = null;
484580
484601
  let ttsMimeType = null;
484581
- ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: unifiedSessionId }));
484602
+ ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: routingSessionId }));
484582
484603
  const alreadyStreamed = streamedContent.length > 0;
484583
484604
  if (content && !alreadyStreamed) {
484584
484605
  if (shouldSpeak) {
484585
484606
  if (!voiceCfg.ttsProvider) {
484586
484607
  ws.send(JSON.stringify({
484587
484608
  type: "message",
484588
- sessionId: unifiedSessionId,
484609
+ sessionId: routingSessionId,
484589
484610
  content: `${content}
484590
484611
 
484591
484612
  \uD83D\uDD0A Para recibir respuestas en audio, configura el proveedor TTS en Configuraci\xF3n > Canales > WebChat (ej: elevenlabs)`,
@@ -484602,7 +484623,7 @@ ${messageContent}`;
484602
484623
  log75.info(`Audio generated: ${base64Audio.length} bytes, mimeType: ${audioOutput.mimeType}`);
484603
484624
  ws.send(JSON.stringify({
484604
484625
  type: "message",
484605
- sessionId: unifiedSessionId,
484626
+ sessionId: routingSessionId,
484606
484627
  content,
484607
484628
  audio: base64Audio,
484608
484629
  mimeType: audioOutput.mimeType,
@@ -484610,11 +484631,11 @@ ${messageContent}`;
484610
484631
  }));
484611
484632
  } catch (ttsError) {
484612
484633
  log75.error(`TTS failed: ${ttsError.message}), sending text instead`);
484613
- ws.send(JSON.stringify({ type: "message", sessionId: unifiedSessionId, content, isStep: false }));
484634
+ ws.send(JSON.stringify({ type: "message", sessionId: routingSessionId, content, isStep: false }));
484614
484635
  }
484615
484636
  }
484616
484637
  } else {
484617
- ws.send(JSON.stringify({ type: "message", sessionId: unifiedSessionId, content, isStep: false }));
484638
+ ws.send(JSON.stringify({ type: "message", sessionId: routingSessionId, content, isStep: false }));
484618
484639
  }
484619
484640
  } else if (alreadyStreamed && shouldSpeak && voiceCfg.ttsProvider) {
484620
484641
  try {
@@ -484624,7 +484645,7 @@ ${messageContent}`;
484624
484645
  log75.info(`Audio generated after streaming: ${base64Audio.length} bytes`);
484625
484646
  ws.send(JSON.stringify({
484626
484647
  type: "message",
484627
- sessionId: unifiedSessionId,
484648
+ sessionId: routingSessionId,
484628
484649
  content,
484629
484650
  audio: base64Audio,
484630
484651
  mimeType: audioOutput.mimeType,
@@ -484672,7 +484693,12 @@ ${messageContent}`;
484672
484693
  return;
484673
484694
  }
484674
484695
  try {
484675
- const unifiedSessionId = msg.sessionId;
484696
+ const { userId, threadId: conversationThreadId } = resolveContext({
484697
+ channel: "webchat",
484698
+ channelUserId: msg.sessionId
484699
+ });
484700
+ const unifiedSessionId = conversationThreadId;
484701
+ const routingSessionId = msg.sessionId;
484676
484702
  let finalMessageContent = msg.content;
484677
484703
  let contentParts = undefined;
484678
484704
  const visionConfig = multimodalService.getChannelVisionConfig("webchat");
@@ -484729,10 +484755,6 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484729
484755
  }
484730
484756
  const messages2 = contentParts ? [{ role: "user", content: contentParts }] : [{ role: "user", content: finalMessageContent }];
484731
484757
  log75.info(`Generating response for session ${unifiedSessionId} (multimodal: ${!!(msg.image || msg.document)})...`);
484732
- const { userId } = resolveContext({
484733
- channel: "webchat",
484734
- channelUserId: msg.sessionId
484735
- });
484736
484758
  let streamedContent = "";
484737
484759
  let messageId = crypto.randomUUID();
484738
484760
  const response = await runner.generate({
@@ -484751,7 +484773,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484751
484773
  ws.send(JSON.stringify({
484752
484774
  type: "message",
484753
484775
  id: messageId,
484754
- sessionId: unifiedSessionId,
484776
+ sessionId: routingSessionId,
484755
484777
  content: token,
484756
484778
  isChunk: true,
484757
484779
  isStep: false
@@ -484765,7 +484787,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484765
484787
  if (trimmedMessage) {
484766
484788
  ws.send(JSON.stringify({
484767
484789
  type: "progress",
484768
- sessionId: unifiedSessionId,
484790
+ sessionId: routingSessionId,
484769
484791
  content: trimmedMessage
484770
484792
  }));
484771
484793
  }
@@ -484775,7 +484797,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484775
484797
  const narration = getNarration(step.toolName);
484776
484798
  ws.send(JSON.stringify({
484777
484799
  type: "progress",
484778
- sessionId: unifiedSessionId,
484800
+ sessionId: routingSessionId,
484779
484801
  content: narration
484780
484802
  }));
484781
484803
  return;
@@ -484788,7 +484810,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484788
484810
  if (userMessage) {
484789
484811
  ws.send(JSON.stringify({
484790
484812
  type: "progress",
484791
- sessionId: unifiedSessionId,
484813
+ sessionId: routingSessionId,
484792
484814
  content: userMessage
484793
484815
  }));
484794
484816
  }
@@ -484805,14 +484827,14 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484805
484827
  let responseType = "text";
484806
484828
  let ttsProviderUsed = null;
484807
484829
  let ttsMimeType = null;
484808
- ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: unifiedSessionId }));
484830
+ ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: routingSessionId }));
484809
484831
  const alreadyStreamed = streamedContent.length > 0;
484810
484832
  if (content && !alreadyStreamed) {
484811
484833
  if (shouldSpeak) {
484812
484834
  if (!voiceConfig.ttsProvider) {
484813
484835
  ws.send(JSON.stringify({
484814
484836
  type: "message",
484815
- sessionId: unifiedSessionId,
484837
+ sessionId: routingSessionId,
484816
484838
  content: `${content}
484817
484839
 
484818
484840
  \uD83D\uDD0A Para recibir respuestas en audio, configura el proveedor TTS en Configuraci\xF3n > Canales > WebChat (ej: elevenlabs)`,
@@ -484828,7 +484850,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484828
484850
  const base64Audio = audioOutput.data.toString("base64");
484829
484851
  ws.send(JSON.stringify({
484830
484852
  type: "message",
484831
- sessionId: unifiedSessionId,
484853
+ sessionId: routingSessionId,
484832
484854
  content,
484833
484855
  audio: base64Audio,
484834
484856
  mimeType: audioOutput.mimeType,
@@ -484836,11 +484858,11 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484836
484858
  }));
484837
484859
  } catch (ttsError) {
484838
484860
  log75.error(`TTS failed: ${ttsError.message}), sending text instead`);
484839
- ws.send(JSON.stringify({ type: "message", sessionId: unifiedSessionId, content, isStep: false }));
484861
+ ws.send(JSON.stringify({ type: "message", sessionId: routingSessionId, content, isStep: false }));
484840
484862
  }
484841
484863
  }
484842
484864
  } else {
484843
- ws.send(JSON.stringify({ type: "message", sessionId: unifiedSessionId, content, isStep: false }));
484865
+ ws.send(JSON.stringify({ type: "message", sessionId: routingSessionId, content, isStep: false }));
484844
484866
  }
484845
484867
  } else if (alreadyStreamed && shouldSpeak && voiceConfig.ttsProvider) {
484846
484868
  try {
@@ -484850,7 +484872,7 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484850
484872
  log75.info(`Audio generated after streaming: ${base64Audio.length} bytes`);
484851
484873
  ws.send(JSON.stringify({
484852
484874
  type: "message",
484853
- sessionId: unifiedSessionId,
484875
+ sessionId: routingSessionId,
484854
484876
  content,
484855
484877
  audio: base64Audio,
484856
484878
  mimeType: audioOutput.mimeType,
@@ -484861,14 +484883,13 @@ ${finalMessageContent || ""}` : finalMessageContent || "";
484861
484883
  }
484862
484884
  }
484863
484885
  } catch (error54) {
484864
- const unifiedSessionId = msg.sessionId;
484865
- ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: unifiedSessionId }));
484886
+ ws.send(JSON.stringify({ type: "typing", isTyping: false, sessionId: msg.sessionId }));
484866
484887
  ws.send(JSON.stringify({
484867
484888
  type: "error",
484868
- sessionId: unifiedSessionId,
484889
+ sessionId: msg.sessionId,
484869
484890
  error: error54.message
484870
484891
  }));
484871
- log75.error(`Error for session ${unifiedSessionId}: ${error54.message}`);
484892
+ log75.error(`Error for session ${msg.sessionId}: ${error54.message}`);
484872
484893
  }
484873
484894
  });
484874
484895
  return;
@@ -486502,7 +486523,7 @@ var init_circuit_breaker = __esm(() => {
486502
486523
  circuitBreakerRegistry = new CircuitBreakerRegistry;
486503
486524
  });
486504
486525
  // packages/core/src/plugins/loader.ts
486505
- import { mkdirSync as mkdirSync18, readdirSync as readdirSync8, existsSync as existsSync32 } from "fs";
486526
+ import { mkdirSync as mkdirSync18, readdirSync as readdirSync8, existsSync as existsSync33 } from "fs";
486506
486527
  import * as path30 from "path";
486507
486528
 
486508
486529
  class PluginLoader {
@@ -486516,7 +486537,7 @@ class PluginLoader {
486516
486537
  log = logger.child("plugins");
486517
486538
  constructor(options2) {
486518
486539
  this.options = options2;
486519
- if (!existsSync32(options2.pluginDir)) {
486540
+ if (!existsSync33(options2.pluginDir)) {
486520
486541
  mkdirSync18(options2.pluginDir, { recursive: true });
486521
486542
  }
486522
486543
  }
@@ -486528,7 +486549,7 @@ class PluginLoader {
486528
486549
  for (const entry of entries) {
486529
486550
  if (entry.isDirectory()) {
486530
486551
  const manifestPath = path30.join(pluginDir, entry.name, "manifest.json");
486531
- if (existsSync32(manifestPath)) {
486552
+ if (existsSync33(manifestPath)) {
486532
486553
  discovered.push(entry.name);
486533
486554
  }
486534
486555
  }
@@ -486904,7 +486925,7 @@ var init_types6 = __esm(() => {
486904
486925
 
486905
486926
  // packages/cli/src/adapters/config.ts
486906
486927
  import * as path31 from "path";
486907
- import { existsSync as existsSync33, readFileSync as readFileSync14 } from "fs";
486928
+ import { existsSync as existsSync34, readFileSync as readFileSync14 } from "fs";
486908
486929
  function getHiveDir2(customDir) {
486909
486930
  if (customDir) {
486910
486931
  return path31.resolve(customDir);
@@ -486932,7 +486953,7 @@ function getDefaultPaths(hiveDir) {
486932
486953
  }
486933
486954
  function loadEnvFile(envPath) {
486934
486955
  const filePath = envPath || path31.join(process.cwd(), ".env");
486935
- if (!existsSync33(filePath)) {
486956
+ if (!existsSync34(filePath)) {
486936
486957
  return {};
486937
486958
  }
486938
486959
  try {
@@ -487004,7 +487025,7 @@ function getDistDir() {
487004
487025
  return dir;
487005
487026
  }
487006
487027
  const distPath = path31.join(dir, "dist");
487007
- if (existsSync33(distPath)) {
487028
+ if (existsSync34(distPath)) {
487008
487029
  return distPath;
487009
487030
  }
487010
487031
  return null;
@@ -487026,7 +487047,7 @@ __export(exports_docker, {
487026
487047
  });
487027
487048
  import { spawn as spawn3, execSync } from "child_process";
487028
487049
  import * as path32 from "path";
487029
- import { existsSync as existsSync34 } from "fs";
487050
+ import { existsSync as existsSync35 } from "fs";
487030
487051
 
487031
487052
  class DockerAdapter {
487032
487053
  type = "docker";
@@ -487046,7 +487067,7 @@ class DockerAdapter {
487046
487067
  path32.join(process.env.HOME || "", ".hive", "docker-compose.yml")
487047
487068
  ];
487048
487069
  for (const composePath of standardPaths) {
487049
- if (existsSync34(composePath)) {
487070
+ if (existsSync35(composePath)) {
487050
487071
  return composePath;
487051
487072
  }
487052
487073
  }
@@ -487056,7 +487077,7 @@ class DockerAdapter {
487056
487077
  try {
487057
487078
  execSync("docker --version", { stdio: "ignore" });
487058
487079
  execSync("docker compose version", { stdio: "ignore" });
487059
- if (!existsSync34(this.composeFile)) {
487080
+ if (!existsSync35(this.composeFile)) {
487060
487081
  return false;
487061
487082
  }
487062
487083
  try {
@@ -487188,7 +487209,7 @@ class DockerAdapter {
487188
487209
  } catch {
487189
487210
  errors6.push("Docker Compose is not installed");
487190
487211
  }
487191
- if (!existsSync34(this.composeFile)) {
487212
+ if (!existsSync35(this.composeFile)) {
487192
487213
  errors6.push(`docker-compose.yml not found at ${this.composeFile}`);
487193
487214
  } else {
487194
487215
  info3.push(`Compose file: ${this.composeFile}`);
@@ -487228,7 +487249,7 @@ var init_docker = __esm(() => {
487228
487249
  // packages/cli/src/adapters/bun-global.ts
487229
487250
  import { spawn as spawn4, execSync as execSync2 } from "child_process";
487230
487251
  import * as path33 from "path";
487231
- import { existsSync as existsSync35, readFileSync as readFileSync15, unlinkSync as unlinkSync5 } from "fs";
487252
+ import { existsSync as existsSync36, readFileSync as readFileSync15, unlinkSync as unlinkSync5 } from "fs";
487232
487253
 
487233
487254
  class BunGlobalAdapter {
487234
487255
  type = "bun-global";
@@ -487248,7 +487269,7 @@ class BunGlobalAdapter {
487248
487269
  stdio: ["ignore", "pipe", "ignore"]
487249
487270
  });
487250
487271
  const hivePath = output.trim();
487251
- if (hivePath && existsSync35(hivePath)) {
487272
+ if (hivePath && existsSync36(hivePath)) {
487252
487273
  return true;
487253
487274
  }
487254
487275
  } catch {
@@ -487276,13 +487297,13 @@ class BunGlobalAdapter {
487276
487297
  }).trim();
487277
487298
  const distDir = path33.dirname(hivePath);
487278
487299
  const potentialUiDir = path33.join(distDir, "ui");
487279
- if (existsSync35(potentialUiDir)) {
487300
+ if (existsSync36(potentialUiDir)) {
487280
487301
  uiDir = potentialUiDir;
487281
487302
  }
487282
487303
  } catch {}
487283
487304
  if (!uiDir) {
487284
487305
  const cwdUiDir = path33.join(process.cwd(), "packages/hive-ui/dist");
487285
- if (existsSync35(cwdUiDir)) {
487306
+ if (existsSync36(cwdUiDir)) {
487286
487307
  uiDir = cwdUiDir;
487287
487308
  }
487288
487309
  }
@@ -487333,7 +487354,7 @@ class BunGlobalAdapter {
487333
487354
  }
487334
487355
  async stop() {
487335
487356
  try {
487336
- if (existsSync35(this.pidFile)) {
487357
+ if (existsSync36(this.pidFile)) {
487337
487358
  const pid = parseInt(readFileSync15(this.pidFile, "utf-8").trim(), 10);
487338
487359
  if (!isNaN(pid)) {
487339
487360
  try {
@@ -487366,7 +487387,7 @@ class BunGlobalAdapter {
487366
487387
  }
487367
487388
  async isRunning() {
487368
487389
  try {
487369
- if (existsSync35(this.pidFile)) {
487390
+ if (existsSync36(this.pidFile)) {
487370
487391
  const pid = parseInt(readFileSync15(this.pidFile, "utf-8").trim(), 10);
487371
487392
  if (!isNaN(pid)) {
487372
487393
  try {
@@ -487388,7 +487409,7 @@ class BunGlobalAdapter {
487388
487409
  }
487389
487410
  async getPid() {
487390
487411
  try {
487391
- if (existsSync35(this.pidFile)) {
487412
+ if (existsSync36(this.pidFile)) {
487392
487413
  const pid = parseInt(readFileSync15(this.pidFile, "utf-8").trim(), 10);
487393
487414
  if (!isNaN(pid) && pid > 0) {
487394
487415
  try {
@@ -487430,11 +487451,11 @@ class BunGlobalAdapter {
487430
487451
  encoding: "utf-8",
487431
487452
  stdio: ["ignore", "pipe", "ignore"]
487432
487453
  }).trim();
487433
- if (hivePath && existsSync35(hivePath)) {
487454
+ if (hivePath && existsSync36(hivePath)) {
487434
487455
  info3.push(`Hive binary: ${hivePath}`);
487435
487456
  const distDir = path33.dirname(hivePath);
487436
487457
  const uiDir = path33.join(distDir, "ui");
487437
- if (existsSync35(uiDir)) {
487458
+ if (existsSync36(uiDir)) {
487438
487459
  info3.push(`UI directory: ${uiDir}`);
487439
487460
  } else {
487440
487461
  warnings.push("UI directory not found - may use embedded UI");
@@ -487445,7 +487466,7 @@ class BunGlobalAdapter {
487445
487466
  } catch {
487446
487467
  errors6.push("Hive is not installed globally (try: bun install -g @johpaz/hive-agents)");
487447
487468
  }
487448
- if (existsSync35(this.hiveDir)) {
487469
+ if (existsSync36(this.hiveDir)) {
487449
487470
  info3.push(`Hive home: ${this.hiveDir}`);
487450
487471
  } else {
487451
487472
  warnings.push(`Hive home directory does not exist: ${this.hiveDir}`);
@@ -487487,7 +487508,7 @@ var init_bun_global = __esm(() => {
487487
487508
  // packages/cli/src/adapters/binary.ts
487488
487509
  import { spawn as spawn5, execSync as execSync3 } from "child_process";
487489
487510
  import * as path34 from "path";
487490
- import { existsSync as existsSync36, readFileSync as readFileSync16, unlinkSync as unlinkSync6 } from "fs";
487511
+ import { existsSync as existsSync37, readFileSync as readFileSync16, unlinkSync as unlinkSync6 } from "fs";
487491
487512
 
487492
487513
  class BinaryAdapter {
487493
487514
  type = "binary";
@@ -487499,7 +487520,7 @@ class BinaryAdapter {
487499
487520
  this.hiveDir = options2?.hiveDir || getHiveDir2();
487500
487521
  this.pidFile = path34.join(this.hiveDir, "gateway.pid");
487501
487522
  this.binaryPath = options2?.binaryPath || this.findBinary();
487502
- this.isDockerContainer = process.env.HIVE_UI_DIR === "/app/ui" || process.env.HIVE_HOST === "0.0.0.0" || existsSync36("/.dockerenv");
487523
+ this.isDockerContainer = process.env.HIVE_UI_DIR === "/app/ui" || process.env.HIVE_HOST === "0.0.0.0" || existsSync37("/.dockerenv");
487503
487524
  }
487504
487525
  get name() {
487505
487526
  return this.isDockerContainer ? "Docker Container" : "Standalone Binary";
@@ -487510,15 +487531,15 @@ class BinaryAdapter {
487510
487531
  const dir = path34.dirname(scriptPath);
487511
487532
  if (path34.basename(dir) === "dist") {
487512
487533
  const binaryInDist = path34.join(dir, "hive");
487513
- if (existsSync36(binaryInDist)) {
487534
+ if (existsSync37(binaryInDist)) {
487514
487535
  return binaryInDist;
487515
487536
  }
487516
487537
  const binaryWindows = path34.join(dir, "hive.exe");
487517
- if (existsSync36(binaryWindows)) {
487538
+ if (existsSync37(binaryWindows)) {
487518
487539
  return binaryWindows;
487519
487540
  }
487520
487541
  }
487521
- if (existsSync36(scriptPath) && !scriptPath.endsWith(".ts")) {
487542
+ if (existsSync37(scriptPath) && !scriptPath.endsWith(".ts")) {
487522
487543
  return scriptPath;
487523
487544
  }
487524
487545
  }
@@ -487531,7 +487552,7 @@ class BinaryAdapter {
487531
487552
  path34.join(process.env.HOME || "", ".bun", "bin", "hive")
487532
487553
  ];
487533
487554
  for (const binaryPath of commonPaths) {
487534
- if (existsSync36(binaryPath)) {
487555
+ if (existsSync37(binaryPath)) {
487535
487556
  return binaryPath;
487536
487557
  }
487537
487558
  }
@@ -487545,7 +487566,7 @@ class BinaryAdapter {
487545
487566
  if (scriptPath.endsWith(".ts")) {
487546
487567
  return false;
487547
487568
  }
487548
- if (existsSync36(this.binaryPath)) {
487569
+ if (existsSync37(this.binaryPath)) {
487549
487570
  return true;
487550
487571
  }
487551
487572
  try {
@@ -487557,7 +487578,7 @@ class BinaryAdapter {
487557
487578
  const distDir = getDistDir();
487558
487579
  if (distDir) {
487559
487580
  const uiDir = path34.join(distDir, "ui");
487560
- if (existsSync36(uiDir)) {
487581
+ if (existsSync37(uiDir)) {
487561
487582
  return true;
487562
487583
  }
487563
487584
  }
@@ -487573,7 +487594,7 @@ class BinaryAdapter {
487573
487594
  const distDir = getDistDir();
487574
487595
  if (distDir) {
487575
487596
  const uiDir = path34.join(distDir, "ui");
487576
- if (existsSync36(uiDir)) {
487597
+ if (existsSync37(uiDir)) {
487577
487598
  paths.uiDir = uiDir;
487578
487599
  }
487579
487600
  }
@@ -487640,7 +487661,7 @@ class BinaryAdapter {
487640
487661
  }
487641
487662
  async stop() {
487642
487663
  try {
487643
- if (existsSync36(this.pidFile)) {
487664
+ if (existsSync37(this.pidFile)) {
487644
487665
  const pid = parseInt(readFileSync16(this.pidFile, "utf-8").trim(), 10);
487645
487666
  if (!isNaN(pid)) {
487646
487667
  try {
@@ -487674,7 +487695,7 @@ class BinaryAdapter {
487674
487695
  }
487675
487696
  async isRunning() {
487676
487697
  try {
487677
- if (existsSync36(this.pidFile)) {
487698
+ if (existsSync37(this.pidFile)) {
487678
487699
  const pid = parseInt(readFileSync16(this.pidFile, "utf-8").trim(), 10);
487679
487700
  if (!isNaN(pid)) {
487680
487701
  try {
@@ -487696,7 +487717,7 @@ class BinaryAdapter {
487696
487717
  }
487697
487718
  async getPid() {
487698
487719
  try {
487699
- if (existsSync36(this.pidFile)) {
487720
+ if (existsSync37(this.pidFile)) {
487700
487721
  const pid = parseInt(readFileSync16(this.pidFile, "utf-8").trim(), 10);
487701
487722
  if (!isNaN(pid) && pid > 0) {
487702
487723
  try {
@@ -487729,7 +487750,7 @@ class BinaryAdapter {
487729
487750
  const errors6 = [];
487730
487751
  const warnings = [];
487731
487752
  const info3 = [];
487732
- if (existsSync36(this.binaryPath)) {
487753
+ if (existsSync37(this.binaryPath)) {
487733
487754
  info3.push(`Binary: ${this.binaryPath}`);
487734
487755
  try {
487735
487756
  const stat3 = await import("fs/promises").then((m2) => m2.stat(this.binaryPath));
@@ -487752,13 +487773,13 @@ class BinaryAdapter {
487752
487773
  const distDir = getDistDir();
487753
487774
  if (distDir) {
487754
487775
  const uiDir = path34.join(distDir, "ui");
487755
- if (existsSync36(uiDir)) {
487776
+ if (existsSync37(uiDir)) {
487756
487777
  info3.push(`UI directory: ${uiDir}`);
487757
487778
  } else if (!hasEmbeddedUI) {
487758
487779
  warnings.push("UI directory not found and no embedded UI");
487759
487780
  }
487760
487781
  }
487761
- if (existsSync36(this.hiveDir)) {
487782
+ if (existsSync37(this.hiveDir)) {
487762
487783
  info3.push(`Hive home: ${this.hiveDir}`);
487763
487784
  } else {
487764
487785
  warnings.push(`Hive home directory does not exist: ${this.hiveDir}`);
@@ -487776,7 +487797,7 @@ class BinaryAdapter {
487776
487797
  } else {
487777
487798
  warnings.push("Hive Gateway is not running");
487778
487799
  }
487779
- if (process.platform !== "win32" && existsSync36(this.binaryPath)) {
487800
+ if (process.platform !== "win32" && existsSync37(this.binaryPath)) {
487780
487801
  try {
487781
487802
  execSync3(`test -x "${this.binaryPath}"`, { stdio: "ignore" });
487782
487803
  info3.push("Binary is executable");
@@ -487882,7 +487903,7 @@ __export(exports_gateway, {
487882
487903
  resetAdapter: () => resetAdapter,
487883
487904
  reload: () => reload
487884
487905
  });
487885
- import { existsSync as existsSync37, mkdirSync as mkdirSync19, writeFileSync as writeFileSync11, readFileSync as readFileSync17, unlinkSync as unlinkSync7, openSync } from "fs";
487906
+ import { existsSync as existsSync38, mkdirSync as mkdirSync19, writeFileSync as writeFileSync11, readFileSync as readFileSync17, unlinkSync as unlinkSync7, openSync } from "fs";
487886
487907
  import * as path35 from "path";
487887
487908
  import { spawn as spawn6 } from "child_process";
487888
487909
  async function getAdapter() {
@@ -487925,7 +487946,7 @@ async function getPidFile() {
487925
487946
  }
487926
487947
  function ensureLogDir() {
487927
487948
  const logDir = path35.dirname(getLogFile());
487928
- if (!existsSync37(logDir)) {
487949
+ if (!existsSync38(logDir)) {
487929
487950
  mkdirSync19(logDir, { recursive: true });
487930
487951
  }
487931
487952
  }
@@ -487958,7 +487979,7 @@ function openBrowser(url2) {
487958
487979
  async function isSetupMode2() {
487959
487980
  const hiveDir = getHiveDir();
487960
487981
  const dbPath = path35.join(hiveDir, "data", "hive.db");
487961
- return !existsSync37(dbPath);
487982
+ return !existsSync38(dbPath);
487962
487983
  }
487963
487984
  async function isRunning2() {
487964
487985
  try {
@@ -487969,7 +487990,7 @@ async function isRunning2() {
487969
487990
  }
487970
487991
  } catch {}
487971
487992
  const pidFile = await getPidFile();
487972
- if (!existsSync37(pidFile))
487993
+ if (!existsSync38(pidFile))
487973
487994
  return false;
487974
487995
  const pid = parseInt(readFileSync17(pidFile, "utf-8").trim(), 10);
487975
487996
  if (isNaN(pid))
@@ -488033,7 +488054,7 @@ async function start(flags3) {
488033
488054
  \u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2551
488034
488055
  \u2551 \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u2551
488035
488056
  \u2551 \u2551
488036
- \u2551 Personal Swarm AI Gateway \u2014 v0.0.36 \u2551
488057
+ \u2551 Personal Swarm AI Gateway \u2014 v0.0.38 \u2551
488037
488058
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
488038
488059
 
488039
488060
  \uD83D\uDCE6 Installation: ${adapter.name}
@@ -488067,7 +488088,7 @@ async function handleDevMode(adapter, gatewayConfig, daemon) {
488067
488088
  return;
488068
488089
  }
488069
488090
  const hiveUiPath = path35.join(process.cwd(), "packages/hive-ui");
488070
- const hasVite = existsSync37(path35.join(hiveUiPath, "package.json"));
488091
+ const hasVite = existsSync38(path35.join(hiveUiPath, "package.json"));
488071
488092
  if (hasVite) {
488072
488093
  console.log(`\uD83C\uDFA8 Iniciando Vite (UI)...
488073
488094
  `);
@@ -488252,7 +488273,7 @@ async function handleProductionMode(adapter, gatewayConfig, daemon) {
488252
488273
  } catch {
488253
488274
  const hiveDir = getHiveDir();
488254
488275
  const dbPath = path35.join(hiveDir, "data", "hive.db");
488255
- needsSetup = !existsSync37(dbPath);
488276
+ needsSetup = !existsSync38(dbPath);
488256
488277
  }
488257
488278
  const url2 = needsSetup ? `http://localhost:${uiPort}/setup` : `http://localhost:${uiPort}`;
488258
488279
  if (needsSetup) {
@@ -489092,11 +489113,11 @@ async function updateSkills() {
489092
489113
  } else {
489093
489114
  console.log(` \u2705 Todas las skills est\xE1n actualizadas`);
489094
489115
  }
489095
- const { existsSync: existsSync41 } = await import("fs");
489116
+ const { existsSync: existsSync42 } = await import("fs");
489096
489117
  const { getHiveDir: getHiveDir3 } = await Promise.resolve().then(() => (init_loader(), exports_loader));
489097
489118
  const path39 = await import("path");
489098
489119
  const pidFile = path39.join(getHiveDir3(), "gateway.pid");
489099
- if (existsSync41(pidFile)) {
489120
+ if (existsSync42(pidFile)) {
489100
489121
  console.log(`
489101
489122
  \uD83D\uDCA1 El gateway est\xE1 corriendo. Ejecuta 'hive reload' para aplicar cambios.`);
489102
489123
  }
@@ -490291,8 +490312,8 @@ var MAIN_PACKAGE = "@johpaz/hive-agents";
490291
490312
  async function update() {
490292
490313
  console.log(`\uD83D\uDD04 Actualizando Hive...
490293
490314
  `);
490294
- const { existsSync: existsSync47 } = await import("fs");
490295
- const isGitRepo = existsSync47(".git") && existsSync47("package.json");
490315
+ const { existsSync: existsSync48 } = await import("fs");
490316
+ const isGitRepo = existsSync48(".git") && existsSync48("package.json");
490296
490317
  if (isGitRepo) {
490297
490318
  await updateFromGitRepo();
490298
490319
  } else {
@@ -490394,11 +490415,11 @@ Descargando ${MAIN_PACKAGE}@latest (via ${packageManager})...`);
490394
490415
  }
490395
490416
  }
490396
490417
  async function applyDatabaseUpdates() {
490397
- const { existsSync: existsSync47 } = await import("fs");
490418
+ const { existsSync: existsSync48 } = await import("fs");
490398
490419
  const { getHiveDir: getHiveDir3 } = await Promise.resolve().then(() => (init_loader(), exports_loader));
490399
490420
  const path44 = await import("path");
490400
490421
  const dbPath = path44.join(getHiveDir3(), "data", "hive.db");
490401
- if (!existsSync47(dbPath)) {
490422
+ if (!existsSync48(dbPath)) {
490402
490423
  console.log(` \u2139\uFE0F No se encontr\xF3 base de datos existente. Se crear\xE1 en el pr\xF3ximo 'hive start'.`);
490403
490424
  return;
490404
490425
  }
@@ -490436,7 +490457,7 @@ async function applyDatabaseUpdates() {
490436
490457
  }
490437
490458
  const hiveDir = getHiveDir3();
490438
490459
  const pidFile = path44.join(hiveDir, "gateway.pid");
490439
- if (existsSync47(pidFile)) {
490460
+ if (existsSync48(pidFile)) {
490440
490461
  console.log(`
490441
490462
  \uD83D\uDCA1 El gateway est\xE1 corriendo. Ejecuta 'hive reload' para aplicar cambios.`);
490442
490463
  }