@johpaz/hive-sdk 0.4.4 → 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.
- package/CHANGELOG.md +20 -4
- package/README.md +48 -7
- package/SECURITY.md +17 -0
- package/docs/API-AGENTS.md +430 -0
- package/docs/API-ARTIFACTS.md +55 -0
- package/docs/API-CONTEXT-COMPILER.md +285 -0
- package/docs/API-CRON.md +188 -0
- package/docs/API-DAG-SCHEDULER.md +291 -0
- package/docs/API-HOOKS.md +147 -0
- package/docs/API-RESILIENCE.md +45 -0
- package/docs/API-SERVICES.md +458 -0
- package/docs/API-SESSIONS.md +146 -0
- package/docs/API-TOOLS-SKILLS-CHANNELS.md +499 -0
- package/docs/API-WORKERS-EVENTS.md +311 -0
- package/docs/HIVE-HARNESS.md +232 -0
- package/docs/INDEX.md +198 -0
- package/docs/SECURITY-GUARDRAILS.md +87 -0
- package/docs/TEMPLATE-HIVE-APP.md +360 -0
- package/docs/UPGRADING.md +65 -0
- package/docs/assets/logoblack.png +0 -0
- package/docs/assets/logocolor-dark.png +0 -0
- package/docs/assets/logocolorbg.png +0 -0
- package/docs/plans/2026-09-05-office-dependency-hardening-design.md +28 -0
- package/docs/plans/2026-09-06-dependency-audit-remediation-design.md +25 -0
- package/docs/plans/2026-09-06-pptx-image-size-remediation-design.md +54 -0
- package/docs/plans/2026-09-06-typescript7-bun142-documentation-design.md +48 -0
- package/package.json +5 -4
- package/packages/core/src/agent/llm-providers/hiveagents.ts +2 -2
- package/packages/core/src/agent/providers/index.ts +17 -1
- package/packages/core/src/api/createAgent.ts +4 -2
- package/packages/core/src/gateway/server.ts +1 -1
- package/packages/core/src/mcp/transports/sse.ts +11 -3
- package/packages/core/src/mcp/transports/websocket.ts +11 -9
- package/packages/core/src/tool-runtime/tool-worker.ts +3 -1
- package/packages/core/src/tools/office/office-escribir-pptx.ts +3 -1
- package/packages/core/src/vendor/pptxgenjs/LICENSE +21 -0
- package/packages/core/src/vendor/pptxgenjs/README.md +17 -0
- package/packages/core/src/vendor/pptxgenjs/pptxgen.es.d.ts +17 -0
- package/packages/core/src/vendor/pptxgenjs/pptxgen.es.js +7368 -0
- package/packages/core/src/voice/index.ts +4 -4
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# API Reference — Tools, Skills, MCP, Gateway, Channels y Storage
|
|
2
|
+
|
|
3
|
+
## Índice
|
|
4
|
+
|
|
5
|
+
1. [Tools](#tools)
|
|
6
|
+
2. [Skills](#skills)
|
|
7
|
+
3. [MCP](#mcp)
|
|
8
|
+
4. [Gateway](#gateway)
|
|
9
|
+
5. [Channels](#channels)
|
|
10
|
+
6. [Tool Runtime](#tool-runtime)
|
|
11
|
+
7. [Canvas](#canvas)
|
|
12
|
+
8. [Storage](#storage)
|
|
13
|
+
9. [Config](#config)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Tools
|
|
18
|
+
|
|
19
|
+
### defineTool
|
|
20
|
+
|
|
21
|
+
Función para definir herramientas que el agente puede invocar.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { defineTool } from "@johpaz/hive-sdk";
|
|
25
|
+
|
|
26
|
+
const tool = defineTool({
|
|
27
|
+
name: "saludar",
|
|
28
|
+
description: "Saluda a alguien por su nombre",
|
|
29
|
+
execute: async (args: { nombre: string }) => {
|
|
30
|
+
return { mensaje: `¡Hola ${args.nombre}!` };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### ToolRegistry
|
|
36
|
+
|
|
37
|
+
Registro central de herramientas.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { ToolRegistry, defineTool } from "@johpaz/hive-sdk";
|
|
41
|
+
|
|
42
|
+
const reg = new ToolRegistry();
|
|
43
|
+
|
|
44
|
+
reg.register(defineTool({ name: "t1", description: "...", execute: async () => ({}) }));
|
|
45
|
+
|
|
46
|
+
reg.has("t1"); // true
|
|
47
|
+
reg.get("t1"); // ToolDefinition
|
|
48
|
+
reg.list(); // ToolDefinition[]
|
|
49
|
+
reg.getByCategory("web"); // Filtrar por categoría
|
|
50
|
+
reg.getNames(); // ["t1"]
|
|
51
|
+
reg.size(); // 1
|
|
52
|
+
reg.merge(otherRegistry);
|
|
53
|
+
reg.clear();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### ToolExecutor
|
|
57
|
+
|
|
58
|
+
Ejecutor de herramientas con validación Zod.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { ToolRegistry, ToolExecutor, defineTool } from "@johpaz/hive-sdk";
|
|
62
|
+
|
|
63
|
+
const reg = new ToolRegistry();
|
|
64
|
+
reg.register(defineTool({
|
|
65
|
+
name: "echo",
|
|
66
|
+
description: "Echo",
|
|
67
|
+
execute: async (args) => args,
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
const exec = new ToolExecutor(reg);
|
|
71
|
+
const result = await exec.execute("echo", { msg: "hola" });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Tool Selection (BM25)
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { selectTools, CORE_TOOL_CATALOG } from "@johpaz/hive-sdk";
|
|
78
|
+
|
|
79
|
+
const tools = selectTools("Buscar archivos en el proyecto");
|
|
80
|
+
const webTools = tools.filter(t => t.category === "web");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Built-in Web + API Tools
|
|
84
|
+
|
|
85
|
+
El SDK expone herramientas web/browser listas para usar:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import {
|
|
89
|
+
webSearchTool,
|
|
90
|
+
webFetchTool,
|
|
91
|
+
apiRequestTool,
|
|
92
|
+
browserNavigateTool,
|
|
93
|
+
browserScreenshotTool,
|
|
94
|
+
browserClickTool,
|
|
95
|
+
browserTypeTool,
|
|
96
|
+
browserExtractTool,
|
|
97
|
+
browserScriptTool,
|
|
98
|
+
browserWaitTool,
|
|
99
|
+
} from "@johpaz/hive-sdk";
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Browser automation (`Bun.WebView`)
|
|
103
|
+
|
|
104
|
+
Las herramientas `browser_*` hablan con `BrowserBackend`, que hoy tiene una sola
|
|
105
|
+
implementación: `Bun.WebView` in-process sobre un Chromium del sistema. No se
|
|
106
|
+
instala ni se descarga nada — sólo hace falta un Chromium (o `BUN_CHROME_PATH`)
|
|
107
|
+
y **Bun ≥ 1.4.2**, porque es el que lanza el navegador con `--headless` y permite
|
|
108
|
+
correr en un servidor sin pantalla.
|
|
109
|
+
|
|
110
|
+
> Antes existía un segundo backend por CLI (`agent-browser`). Se retiró: medido
|
|
111
|
+
> en Bun 1.4.2 el WebView sí corre headless, que era la única razón para
|
|
112
|
+
> mantenerlo, y lo que quedaba era su costo —~40 ms de `Bun.spawn` por operación
|
|
113
|
+
> contra ~0,3 ms, ~88 MB con su propia copia de Chrome, y un
|
|
114
|
+
> `bun add agent-browser@latest` ejecutado **en el entorno del consumidor** al
|
|
115
|
+
> primer uso. La clave de configuración `tools.browser.backend` sobrevive:
|
|
116
|
+
> `"agent-browser"` se acepta, avisa una vez y usa el WebView.
|
|
117
|
+
|
|
118
|
+
Las cookies se guardan y restauran a mano (`tools/web/browser-session.ts`)
|
|
119
|
+
porque el perfil de Chrome que abre Bun es efímero: sin eso, cada reinicio
|
|
120
|
+
empezaría sin sesiones iniciadas. Se controla con `tools.browser.persistSession`.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { initializeBrowserService, getBrowserService } from "@johpaz/hive-sdk/tools";
|
|
124
|
+
|
|
125
|
+
const browserService = initializeBrowserService(config);
|
|
126
|
+
const view = await browserService.getView();
|
|
127
|
+
await view.navigate("https://example.com");
|
|
128
|
+
const snapshot = await view.snapshot({ compact: true, depth: 3 });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### API del backend de navegador
|
|
132
|
+
|
|
133
|
+
Todo esto sale de `@johpaz/hive-sdk/tools`.
|
|
134
|
+
|
|
135
|
+
| | |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `initializeBrowserService(config)` | Arranca el servicio. Las browser tools están en el catálogo desde el seed pero no operan hasta que alguien lo levanta. |
|
|
138
|
+
| `getBrowserService()` | La instancia viva, o `null`. |
|
|
139
|
+
| `shutdownBrowser()` | Cierra la vista y libera el proceso del navegador. |
|
|
140
|
+
| `isWebViewSupported()` | Si este entorno puede abrir un navegador. **Ojo**: comprueba que exista un binario de Chromium, no que arranque — en un contenedor sin sandbox el binario está y Chromium muere igual. |
|
|
141
|
+
| `findChrome()` | Dónde está el Chromium que se va a usar. |
|
|
142
|
+
| `resolveBackendKind(pref)` | Traduce `tools.browser.backend` a un backend real. Acepta `"agent-browser"` por compatibilidad: avisa una vez y devuelve WebView. |
|
|
143
|
+
| `resolveWebViewEngine(pref)` | `chrome` (con CDP, headless real) o el WebKit del sistema en macOS, que no tiene CDP y por eso ofrece menos. |
|
|
144
|
+
| `browserInstallHint()` | Qué decirle a alguien que no tiene navegador instalado. |
|
|
145
|
+
|
|
146
|
+
Helpers sobre una vista abierta: `waitForSelector` · `waitForCondition` ·
|
|
147
|
+
`screenshotElement` · `clicEnPunto` · `hoverEnPunto` — los dos últimos operan por
|
|
148
|
+
coordenadas, que es lo que usa `computer_use_task` cuando no hay un selector CSS
|
|
149
|
+
estable (canvas, UIs generadas, visores embebidos).
|
|
150
|
+
|
|
151
|
+
`reducirCaptura` y `podarCapturas` recortan las capturas antes de que lleguen al
|
|
152
|
+
modelo. Una captura de pantalla completa son cientos de miles de tokens si viaja
|
|
153
|
+
en crudo; ver también `@johpaz/hive-sdk/images`, que hace lo propio con las
|
|
154
|
+
imágenes que manda el usuario.
|
|
155
|
+
|
|
156
|
+
#### Sesión del navegador
|
|
157
|
+
|
|
158
|
+
El perfil de Chrome que abre Bun es **efímero** —su ruta lleva un hash que cambia
|
|
159
|
+
entre procesos— así que las cookies se guardan y restauran a mano. Sin esto, cada
|
|
160
|
+
reinicio empezaría sin ninguna sesión iniciada y el agente tendría que volver a
|
|
161
|
+
autenticarse en todos lados.
|
|
162
|
+
|
|
163
|
+
| | |
|
|
164
|
+
|---|---|
|
|
165
|
+
| `sessionPersistenceEnabled()` | Si está activo (`tools.browser.persistSession`, encendido por defecto). |
|
|
166
|
+
| `storeCookies(cookies)` / `loadStoredCookies()` | Guardar y restaurar. Van cifradas, como cualquier otro secreto. |
|
|
167
|
+
| `normalizeCookies(raw)` | Normaliza lo que devuelve CDP a una forma estable. |
|
|
168
|
+
| `clearStoredSession()` | Cerrar la sesión: olvida los logins guardados. |
|
|
169
|
+
|
|
170
|
+
#### api_request
|
|
171
|
+
|
|
172
|
+
Conecta APIs REST con autenticación y métodos HTTP:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const result = await apiRequestTool.execute({
|
|
176
|
+
method: "POST",
|
|
177
|
+
url: "https://api.example.com/items",
|
|
178
|
+
headers: {
|
|
179
|
+
"Content-Type": "application/json",
|
|
180
|
+
Authorization: `Bearer ${process.env.API_TOKEN}`,
|
|
181
|
+
},
|
|
182
|
+
body: JSON.stringify({ name: "example" }),
|
|
183
|
+
query_params: { verbose: "1" },
|
|
184
|
+
timeout_ms: 30000,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// → { ok, status, statusText, headers, body, contentType, url }
|
|
188
|
+
// `body` viene parseado si la respuesta es JSON, y como string si no.
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Nunca lanza: un fallo de red o un método inválido vuelven como
|
|
192
|
+
`{ ok: false, error }`. No tiene helpers de autenticación — la credencial va
|
|
193
|
+
como un header más.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Skills
|
|
198
|
+
|
|
199
|
+
### defineSkill
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { defineSkill } from "@johpaz/hive-sdk";
|
|
203
|
+
|
|
204
|
+
const skill = defineSkill({
|
|
205
|
+
name: "file-manager",
|
|
206
|
+
description: "Gestiona archivos y directorios",
|
|
207
|
+
steps: [
|
|
208
|
+
{ action: "fs_list", instruction: "Listar archivos" },
|
|
209
|
+
{ action: "fs_read", instruction: "Leer archivo" },
|
|
210
|
+
],
|
|
211
|
+
tools: ["fs_list", "fs_read"],
|
|
212
|
+
triggers: ["archivo", "directorio", "listar"],
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### SkillLoader
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { SkillLoader } from "@johpaz/hive-sdk";
|
|
220
|
+
|
|
221
|
+
const loader = new SkillLoader({
|
|
222
|
+
allowBundled: ["file-manager", "web-researcher"],
|
|
223
|
+
managedDir: "./skills",
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const skills = loader.list();
|
|
227
|
+
const skill = loader.get("file-manager");
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Skills empaquetadas
|
|
231
|
+
|
|
232
|
+
El SDK incluye 23 skills empaquetadas. Algunas útiles para web y APIs:
|
|
233
|
+
|
|
234
|
+
- `web_research` — búsqueda y síntesis con `web_search` + `web_fetch`.
|
|
235
|
+
- `browser_scrape` — captura de contenido renderizado con screenshots.
|
|
236
|
+
- `browser_automate` — automatización de flujos web (clicks, formularios).
|
|
237
|
+
- `api_client` — consumo de APIs REST con `api_request`.
|
|
238
|
+
- `capability_discovery` — la skill mínima: enseña al agente a encontrar el resto.
|
|
239
|
+
|
|
240
|
+
Se generan desde los `SKILL.md` de `packages/core/src/skills/bundled/`:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
bun run skills:bundle
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
En 0.1.5 se retiraron 21 skills que invocaban tools inexistentes (`voice_*`,
|
|
247
|
+
`meeting_transcription`, `canvas_*`, `code_*`, `project_*`): el selector se las
|
|
248
|
+
podía ofrecer al modelo y la ejecución moría sin ejecutor. Hay un test que falla
|
|
249
|
+
si alguna vuelve a declarar una tool que no está en el registry.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## MCP
|
|
254
|
+
|
|
255
|
+
Model Context Protocol — herramientas externas via STDIO/SSE/WebSocket.
|
|
256
|
+
|
|
257
|
+
### MCPClientManager
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
import { MCPClientManager } from "@johpaz/hive-sdk";
|
|
261
|
+
|
|
262
|
+
const mcp = new MCPClientManager({
|
|
263
|
+
servers: {
|
|
264
|
+
"filesystem": {
|
|
265
|
+
transport: "stdio",
|
|
266
|
+
command: "npx",
|
|
267
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", "./data"],
|
|
268
|
+
enabled: true,
|
|
269
|
+
},
|
|
270
|
+
"weather-api": {
|
|
271
|
+
transport: "sse",
|
|
272
|
+
url: "https://api.weather.com/mcp",
|
|
273
|
+
enabled: true,
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
await mcp.initialize();
|
|
279
|
+
const tools = mcp.getTools("filesystem");
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Transports
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import { createTransport, SSETransport, WebSocketTransport } from "@johpaz/hive-sdk";
|
|
286
|
+
|
|
287
|
+
const transport = createTransport({
|
|
288
|
+
type: "stdio",
|
|
289
|
+
stdio: { command: "npx", args: ["-y", "server"], env: {} },
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Gateway
|
|
296
|
+
|
|
297
|
+
Servidor HTTP/WebSocket simplificado para exponer el agente como API.
|
|
298
|
+
|
|
299
|
+
### startGateway
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { startGateway } from "@johpaz/hive-sdk";
|
|
303
|
+
|
|
304
|
+
const server = await startGateway({
|
|
305
|
+
host: "127.0.0.1",
|
|
306
|
+
port: 18790,
|
|
307
|
+
agentId: "coordinator",
|
|
308
|
+
mcpManager: null,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
console.log(`Gateway at http://127.0.0.1:18790`);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Endpoints
|
|
315
|
+
|
|
316
|
+
| Método | Ruta | Descripción |
|
|
317
|
+
|--------|------|-------------|
|
|
318
|
+
| GET | `/status` | Health check |
|
|
319
|
+
| POST | `/chat` | Chat con el agente |
|
|
320
|
+
| WS | `/ws` | WebSocket streaming |
|
|
321
|
+
|
|
322
|
+
### Ejemplo: Chat HTTP
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
const res = await fetch("http://127.0.0.1:18790/chat", {
|
|
326
|
+
method: "POST",
|
|
327
|
+
headers: { "Content-Type": "application/json" },
|
|
328
|
+
body: JSON.stringify({ message: "Hello!", threadId: "t1" }),
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const data = await res.json();
|
|
332
|
+
console.log(data.response);
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Channels
|
|
338
|
+
|
|
339
|
+
Integraciones con plataformas de mensajería.
|
|
340
|
+
|
|
341
|
+
### ChannelManager
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
import { ChannelManager } from "@johpaz/hive-sdk";
|
|
345
|
+
|
|
346
|
+
const manager = new ChannelManager(config);
|
|
347
|
+
await manager.initialize();
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Canales soportados
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import {
|
|
354
|
+
TelegramChannel,
|
|
355
|
+
DiscordChannel,
|
|
356
|
+
WhatsAppChannel,
|
|
357
|
+
SlackChannel,
|
|
358
|
+
WebChatChannel,
|
|
359
|
+
} from "@johpaz/hive-sdk";
|
|
360
|
+
|
|
361
|
+
// Telegram
|
|
362
|
+
const telegram = new TelegramChannel({ botToken: process.env.TELEGRAM_BOT_TOKEN! });
|
|
363
|
+
|
|
364
|
+
// Discord
|
|
365
|
+
const discord = new DiscordChannel({ botToken: process.env.DISCORD_BOT_TOKEN! });
|
|
366
|
+
|
|
367
|
+
// WhatsApp
|
|
368
|
+
const whatsapp = new WhatsAppChannel();
|
|
369
|
+
|
|
370
|
+
// Slack
|
|
371
|
+
const slack = new SlackChannel({ botToken: process.env.SLACK_BOT_TOKEN! });
|
|
372
|
+
|
|
373
|
+
// Webchat
|
|
374
|
+
const webchat = new WebChatChannel();
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## Tool Runtime
|
|
380
|
+
|
|
381
|
+
Ejecución paralela de herramientas vía Bun Workers.
|
|
382
|
+
|
|
383
|
+
### executeToolBatch
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import { executeToolBatch, shutdownToolRuntime } from "@johpaz/hive-sdk";
|
|
387
|
+
|
|
388
|
+
const results = await executeToolBatch({
|
|
389
|
+
toolCalls: [
|
|
390
|
+
{ id: "1", function: { name: "search", arguments: JSON.stringify({ q: "AI" }) } },
|
|
391
|
+
{ id: "2", function: { name: "fetch", arguments: JSON.stringify({ url: "..." }) } },
|
|
392
|
+
],
|
|
393
|
+
allTools: [searchTool, fetchTool],
|
|
394
|
+
toolConfig: { user_id: "u1", thread_id: "t1" },
|
|
395
|
+
hiveConfig: loadConfig(),
|
|
396
|
+
workerPool: {
|
|
397
|
+
enabled: true,
|
|
398
|
+
maxWorkers: 4,
|
|
399
|
+
toolTimeoutMs: 30000,
|
|
400
|
+
parallelToolCalls: true,
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Limpieza
|
|
405
|
+
shutdownToolRuntime();
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### ToolBatchResult
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
interface ToolBatchResult {
|
|
412
|
+
toolCall: ToolCallLike;
|
|
413
|
+
toolName: string;
|
|
414
|
+
result: unknown;
|
|
415
|
+
ok: boolean;
|
|
416
|
+
durationMs: number;
|
|
417
|
+
error?: SerializedError;
|
|
418
|
+
timedOut?: boolean;
|
|
419
|
+
aborted?: boolean;
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
## Canvas
|
|
426
|
+
|
|
427
|
+
Visualización en tiempo real del estado de agentes.
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
import { emitCanvas, subscribeCanvas, unsubscribeCanvas } from "@johpaz/hive-sdk";
|
|
431
|
+
|
|
432
|
+
const handler = (data: any) => console.log("Canvas:", data);
|
|
433
|
+
subscribeCanvas(handler);
|
|
434
|
+
|
|
435
|
+
emitCanvas("canvas:node_update", {
|
|
436
|
+
nodeId: "agent-1",
|
|
437
|
+
changes: { status: "running", currentTool: "web_search" },
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
unsubscribeCanvas(handler);
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
## Storage
|
|
446
|
+
|
|
447
|
+
HiveDB (`@johpaz/hive-db`), un motor embebido con colecciones de documentos e
|
|
448
|
+
índice BM25. Reemplazó a SQLite + FTS5 en 0.1.5.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
import { ensureHiveDb, col } from "@johpaz/hive-sdk";
|
|
452
|
+
import type { AgentDoc } from "@johpaz/hive-sdk";
|
|
453
|
+
|
|
454
|
+
// Abre la base, crea los índices y siembra el catálogo. Idempotente.
|
|
455
|
+
await ensureHiveDb();
|
|
456
|
+
|
|
457
|
+
const agents = await col<AgentDoc>("agents");
|
|
458
|
+
|
|
459
|
+
const one = await agents.get(agentId); // { id, doc, version } | undefined
|
|
460
|
+
const workers = await agents.findBy("role", "worker");
|
|
461
|
+
const all = await agents.scan({});
|
|
462
|
+
const scoped = await agents.scan({ prefix: `${threadId}:` });
|
|
463
|
+
|
|
464
|
+
// Escritura con concurrencia optimista
|
|
465
|
+
await agents.put(agentId, { ...one.doc, status: "idle" }, { expectedVersion: one.version });
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
`HIVE_DB_PATH=":memory:"` abre una base efímera — es lo que usa la suite de
|
|
469
|
+
tests para no tocar la del usuario.
|
|
470
|
+
|
|
471
|
+
### Búsqueda de capacidad
|
|
472
|
+
|
|
473
|
+
El índice BM25 es lo que hace funcionar a `search_knowledge`: el agente arranca
|
|
474
|
+
con un loadout mínimo y descubre el resto en runtime.
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
import { selectTools, selectSkills } from "@johpaz/hive-sdk";
|
|
478
|
+
|
|
479
|
+
const tools = await selectTools("leer un archivo del workspace");
|
|
480
|
+
const skills = await selectSkills("investigar en la web");
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Una tool declarada con `defineTool` y pasada a `createAgent` queda indexada
|
|
484
|
+
automáticamente, así que el modelo puede descubrirla igual que a las nativas.
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## Config
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
import { loadConfig, loadEnv, getHiveDir } from "@johpaz/hive-sdk";
|
|
492
|
+
|
|
493
|
+
const config = await loadConfig();
|
|
494
|
+
const hiveDir = getHiveDir(); // ~/.hive o HIVE_DATA_DIR
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
*Documentación Hive SDK — ver `version` en package.json*
|