@johpaz/hive-sdk 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -203
- package/bun.lock +543 -0
- package/bunfig.toml +7 -0
- package/docs/API-TOOLS-SKILLS-CHANNELS.md +61 -1
- package/docs/API-WORKERS-EVENTS.md +3 -3
- package/docs/INDEX.md +2 -2
- package/docs/TEMPLATE-HIVE-APP.md +6 -6
- package/package.json +2 -2
- package/packages/cli/src/index.ts +1 -1
- package/packages/core/src/agent/selectors/ToolSelector.ts +1 -0
- package/packages/core/src/api/createAgent.ts +10 -0
- package/packages/core/src/config/loader.ts +2 -2
- package/packages/core/src/index.ts +13 -0
- package/packages/core/src/skills/bundled-data.generated.ts +50 -0
- package/packages/core/src/skills/skills.test.ts +21 -0
- package/packages/core/src/tools/index.ts +1 -0
- package/packages/core/src/tools/web/api-request.test.ts +170 -0
- package/packages/core/src/tools/web/api-request.ts +239 -0
- package/packages/core/src/tools/web/browser-click.ts +2 -2
- package/packages/core/src/tools/web/browser-extract.ts +22 -6
- package/packages/core/src/tools/web/browser-navigate.ts +34 -18
- package/packages/core/src/tools/web/browser-screenshot.ts +40 -8
- package/packages/core/src/tools/web/browser-script.ts +2 -2
- package/packages/core/src/tools/web/browser-service.test.ts +83 -0
- package/packages/core/src/tools/web/browser-service.ts +290 -341
- package/packages/core/src/tools/web/browser-type.ts +2 -2
- package/packages/core/src/tools/web/browser-wait.ts +2 -2
- package/packages/core/src/tools/web/index.ts +3 -0
- package/CHANGELOG.md +0 -64
- package/docs/README.md +0 -161
- /package/packages/cli/bin/{hive → hives} +0 -0
package/README.md
CHANGED
|
@@ -1,80 +1,74 @@
|
|
|
1
|
-
# Hive SDK
|
|
1
|
+
# Documentación — Hive SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
<img src="https://img.shields.io/badge/Bun-v1.3.13-000000?style=flat&logo=bun" alt="Bun">
|
|
5
|
-
<img src="https://img.shields.io/badge/TypeScript-6.0-blue?style=flat&logo=typescript">
|
|
6
|
-
<img src="https://img.shields.io/badge/License-MIT-green?style=flat">
|
|
7
|
-
</p>
|
|
3
|
+
> **Hive Agent Harness SDK** — Build, deploy, and scale AI agent applications with multi-channel support, Bun Workers, and swarm orchestration.
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
## Documentos
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
| Documento | Descripción |
|
|
8
|
+
|-----------|-------------|
|
|
9
|
+
| [API-AGENTS.md](docs/API-AGENTS.md) | createAgent, AgentLoop, Tool/Skill Selector, LLM Providers |
|
|
10
|
+
| [API-DAG-SCHEDULER.md](docs/API-DAG-SCHEDULER.md) | DAGScheduler, TaskGraph, TaskNode, Estrategias, Presets |
|
|
11
|
+
| [API-WORKERS-EVENTS.md](docs/API-WORKERS-EVENTS.md) | **Bun Workers**, createWorker, WorkerPool, AgentBus, EventBus, Canvas |
|
|
12
|
+
| [API-TOOLS-SKILLS-CHANNELS.md](docs/API-TOOLS-SKILLS-CHANNELS.md) | Tools, Skills, MCP, **Gateway**, **Channels**, **Tool Runtime**, Storage |
|
|
13
|
+
| [API-CONTEXT-COMPILER.md](docs/API-CONTEXT-COMPILER.md) | Context Compiler, Message History, Scratchpad, EthicsGuard, ACE |
|
|
14
|
+
| [TEMPLATE-HIVE-APP.md](docs/TEMPLATE-HIVE-APP.md) | **Template hive-app** — estructura, opciones, personalización |
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
## ¿Qué es Hive SDK?
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
**Hive SDK es un Agent Harness**: un marco de trabajo completo para construir, desplegar y escalar aplicaciones de agentes de IA. A diferencia de un simple wrapper de LLM, un *harness* provee todo lo necesario para que un agente opere en producción:
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
- **Agentes**: ciclo ReAct, selección dinámica de tools/skills vía FTS5, múltiples providers (OpenAI, Anthropic, Gemini, Ollama).
|
|
21
|
+
- **Tools**: 70+ tools incluidas — filesystem, web search, browser automation (`agent-browser`), APIs (`api_request`), canvas, voz, office, cron.
|
|
22
|
+
- **Skills**: workflows reutilizables con `defineSkill` y `SkillLoader`.
|
|
23
|
+
- **Canales**: Telegram, Discord, WhatsApp, Slack y WebChat con `ChannelManager`.
|
|
24
|
+
- **Swarm**: orquestación multi-agente con `DAGScheduler`, `TaskGraph` y `WorkerPool`.
|
|
25
|
+
- **Runtime**: ejecución paralela de tools vía Bun Workers.
|
|
26
|
+
- **Gateway**: servidor HTTP/WebSocket para exponer agentes como API.
|
|
27
|
+
- **Memoria y estado**: SQLite + FTS5, scratchpad, context compiler.
|
|
28
|
+
|
|
29
|
+
Con Hive SDK no montas un agente desde cero: **enganchas tu lógica de negocio en un harness ya armado**.
|
|
20
30
|
|
|
21
31
|
## Instalación
|
|
22
32
|
|
|
23
33
|
```bash
|
|
24
|
-
#
|
|
34
|
+
# Instalar globalmente para el CLI
|
|
25
35
|
bun install -g @johpaz/hive-sdk
|
|
26
36
|
|
|
27
|
-
#
|
|
37
|
+
# O en un proyecto
|
|
28
38
|
bun add @johpaz/hive-sdk
|
|
29
39
|
```
|
|
30
40
|
|
|
31
41
|
## CLI Commands
|
|
32
42
|
|
|
33
|
-
### Create a full harness application
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
hive create-app my-hive
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Generates a complete Hive harness with gateway, channels, and agent configuration.
|
|
40
|
-
|
|
41
|
-
### Create a lightweight agent project
|
|
42
|
-
|
|
43
43
|
```bash
|
|
44
|
-
|
|
44
|
+
hives init <name> # Inicializar proyecto agente
|
|
45
|
+
hives create-app <name> # Crear aplicación harness completa
|
|
46
|
+
hives add-tool <name> # Añadir tool
|
|
47
|
+
hives add-skill <name> # Añadir skill
|
|
48
|
+
hives add-worker <name> # Añadir Bun Worker
|
|
49
|
+
hives run # Ejecutar agente
|
|
50
|
+
hives test # Test tools/skills
|
|
51
|
+
hives trace # Ver logs de ejecución
|
|
45
52
|
```
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
## Inicio Rápido
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
cd my-hive
|
|
51
|
-
hive add-tool search-docs
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Add a skill to your project
|
|
56
|
+
### 1. Crear una app harness completa
|
|
55
57
|
|
|
56
58
|
```bash
|
|
59
|
+
hives create-app my-hive
|
|
57
60
|
cd my-hive
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### Run your agent
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
cd my-agent
|
|
65
|
-
hive run
|
|
61
|
+
bun install
|
|
62
|
+
cp .env.example .env
|
|
63
|
+
bun run dev
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## Inicio Rápido — Programmatic API
|
|
71
|
-
|
|
72
|
-
### Create an Agent
|
|
66
|
+
### 2. Crear un agente simple
|
|
73
67
|
|
|
74
68
|
```typescript
|
|
75
69
|
import { createAgent, defineTool } from "@johpaz/hive-sdk";
|
|
76
70
|
|
|
77
|
-
const
|
|
71
|
+
const tool = defineTool({
|
|
78
72
|
name: "saludar",
|
|
79
73
|
description: "Saluda a alguien",
|
|
80
74
|
execute: async (args: { nombre: string }) => `¡Hola ${args.nombre}!`,
|
|
@@ -84,197 +78,83 @@ const agent = await createAgent({
|
|
|
84
78
|
name: "asistente",
|
|
85
79
|
provider: "openai",
|
|
86
80
|
model: "gpt-4o-mini",
|
|
87
|
-
tools: [
|
|
81
|
+
tools: [tool],
|
|
88
82
|
});
|
|
89
83
|
|
|
90
84
|
const respuesta = await agent.run("Saluda a Juan");
|
|
91
85
|
console.log(respuesta);
|
|
92
86
|
```
|
|
93
87
|
|
|
94
|
-
###
|
|
88
|
+
### 3. Crear un worker especializado
|
|
95
89
|
|
|
96
90
|
```typescript
|
|
97
|
-
import {
|
|
98
|
-
|
|
99
|
-
await initializeDatabase();
|
|
100
|
-
|
|
101
|
-
const agent = await createAgent({
|
|
102
|
-
name: "coordinator",
|
|
103
|
-
provider: "openai",
|
|
104
|
-
model: "gpt-4o-mini",
|
|
105
|
-
});
|
|
91
|
+
import { createWorker } from "@johpaz/hive-sdk";
|
|
106
92
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
agentId: "coordinator",
|
|
93
|
+
const researcher = createWorker({
|
|
94
|
+
name: "researcher",
|
|
95
|
+
systemPrompt: "You are a research specialist. Provide concise, factual summaries.",
|
|
111
96
|
});
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### Create a Swarm (DAG)
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { DAGScheduler, TaskGraph } from "@johpaz/hive-sdk";
|
|
120
|
-
|
|
121
|
-
const graph = new TaskGraph([
|
|
122
|
-
{ id: "fetch", agentId: "fetcher", taskDescription: "Obtener datos", deps: [] },
|
|
123
|
-
{ id: "process", agentId: "processor", taskDescription: "Procesar", deps: ["fetch"] },
|
|
124
|
-
{ id: "report", agentId: "reporter", taskDescription: "Reportar", deps: ["process"] },
|
|
125
|
-
]);
|
|
126
|
-
|
|
127
|
-
const result = await new DAGScheduler().execute(graph);
|
|
98
|
+
const result = await researcher.run("Research quantum computing advances");
|
|
99
|
+
console.log(result);
|
|
100
|
+
researcher.terminate();
|
|
128
101
|
```
|
|
129
102
|
|
|
130
|
-
###
|
|
103
|
+
### 4. Ejecutar workers en paralelo
|
|
131
104
|
|
|
132
105
|
```typescript
|
|
133
|
-
import {
|
|
134
|
-
|
|
135
|
-
const manager = new ChannelManager();
|
|
136
|
-
|
|
137
|
-
manager.register("telegram", new TelegramChannel({ botToken: process.env.TELEGRAM_BOT_TOKEN! }));
|
|
138
|
-
manager.register("discord", new DiscordChannel({ botToken: process.env.DISCORD_BOT_TOKEN! }));
|
|
106
|
+
import { WorkerPool } from "@johpaz/hive-sdk";
|
|
139
107
|
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
108
|
+
const pool = new WorkerPool({ maxWorkers: 4 });
|
|
144
109
|
|
|
145
|
-
|
|
110
|
+
const tasks = [
|
|
111
|
+
{ id: "t1", message: "Summarize article A" },
|
|
112
|
+
{ id: "t2", message: "Summarize article B" },
|
|
113
|
+
{ id: "t3", message: "Summarize article C" },
|
|
114
|
+
];
|
|
146
115
|
|
|
116
|
+
const results = await pool.executeBatch(tasks);
|
|
117
|
+
console.log(results);
|
|
118
|
+
pool.shutdown();
|
|
147
119
|
```
|
|
148
|
-
hive-sdk/
|
|
149
|
-
├── packages/
|
|
150
|
-
│ ├── core/ # @johpaz/hive-sdk core
|
|
151
|
-
│ │ └── src/
|
|
152
|
-
│ │ ├── api/ # createAgent(), Agent interface
|
|
153
|
-
│ │ ├── agent/ # AgentLoop, ContextCompiler, ConversationStore
|
|
154
|
-
│ │ │ ├── providers/ # LLM: OpenAI, Anthropic, Gemini, Ollama
|
|
155
|
-
│ │ │ └── selectors/ # FTS5: ToolSelector, SkillSelector, PlaybookSelector
|
|
156
|
-
│ │ ├── tools/ # ToolRegistry + 70+ built-in tools
|
|
157
|
-
│ │ ├── skills/ # SkillLoader, defineSkill()
|
|
158
|
-
│ │ ├── swarm/ # DAGScheduler, TaskGraph, WorkerPool
|
|
159
|
-
│ │ ├── gateway/ # HTTP/WebSocket server (Bun.serve)
|
|
160
|
-
│ │ ├── channels/ # Telegram, Discord, WhatsApp, Slack, Webchat
|
|
161
|
-
│ │ ├── mcp/ # MCPClientManager, transports (SSE, WS)
|
|
162
|
-
│ │ ├── storage/ # SQLite (bun:sqlite) + FTS5
|
|
163
|
-
│ │ ├── canvas/ # CanvasManager + A2UI emitter
|
|
164
|
-
│ │ ├── scheduler/ # CronScheduler + DAG execution
|
|
165
|
-
│ │ ├── ethics/ # EthicsGuard
|
|
166
|
-
│ │ ├── memory/ # Scratchpad
|
|
167
|
-
│ │ ├── config/ # loadConfig, loadEnv
|
|
168
|
-
│ │ ├── utils/ # logger, toon, crypto, retry
|
|
169
|
-
│ │ └── index.ts # Public API barrel
|
|
170
|
-
│ │
|
|
171
|
-
│ └── cli/ # Hive CLI
|
|
172
|
-
│ └── src/
|
|
173
|
-
│ ├── index.ts # Entry: hive {init,create-app,add-tool,add-skill,run,test,trace}
|
|
174
|
-
│ ├── commands/
|
|
175
|
-
│ │ ├── init.ts
|
|
176
|
-
│ │ ├── create-app.ts
|
|
177
|
-
│ │ ├── add-tool.ts
|
|
178
|
-
│ │ ├── add-skill.ts
|
|
179
|
-
│ │ ├── run.ts
|
|
180
|
-
│ │ ├── test.ts
|
|
181
|
-
│ │ └── trace.ts
|
|
182
|
-
│ └── templates/
|
|
183
|
-
│ └── hive-app/ # Full harness template
|
|
184
|
-
│ ├── package.json
|
|
185
|
-
│ ├── hive.config.ts
|
|
186
|
-
│ ├── docker-compose.yml
|
|
187
|
-
│ ├── .env.example
|
|
188
|
-
│ └── src/
|
|
189
|
-
│ ├── main.ts
|
|
190
|
-
│ └── agents/
|
|
191
|
-
│ └── coordinator.ts
|
|
192
|
-
│
|
|
193
|
-
├── test/ # Test helpers
|
|
194
|
-
├── docs/ # Documentation
|
|
195
|
-
├── tsconfig.json
|
|
196
|
-
└── package.json
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
---
|
|
200
120
|
|
|
201
|
-
|
|
121
|
+
### 5. Gateway HTTP/WebSocket
|
|
202
122
|
|
|
203
123
|
```typescript
|
|
204
|
-
import {
|
|
205
|
-
// Agent
|
|
206
|
-
createAgent,
|
|
207
|
-
defineTool,
|
|
208
|
-
defineSkill,
|
|
209
|
-
runAgent,
|
|
210
|
-
runAgentIsolated,
|
|
211
|
-
|
|
212
|
-
// Gateway
|
|
213
|
-
startGateway,
|
|
214
|
-
|
|
215
|
-
// Channels
|
|
216
|
-
ChannelManager,
|
|
217
|
-
TelegramChannel,
|
|
218
|
-
DiscordChannel,
|
|
219
|
-
WhatsAppChannel,
|
|
220
|
-
SlackChannel,
|
|
221
|
-
WebChatChannel,
|
|
222
|
-
|
|
223
|
-
// Swarm
|
|
224
|
-
DAGScheduler,
|
|
225
|
-
TaskGraph,
|
|
226
|
-
TaskNode,
|
|
227
|
-
|
|
228
|
-
// MCP
|
|
229
|
-
MCPClientManager,
|
|
230
|
-
|
|
231
|
-
// Tools
|
|
232
|
-
ToolRegistry,
|
|
233
|
-
ToolExecutor,
|
|
234
|
-
executeToolBatch,
|
|
235
|
-
|
|
236
|
-
// Storage
|
|
237
|
-
initializeDatabase,
|
|
238
|
-
|
|
239
|
-
// Config
|
|
240
|
-
loadConfig,
|
|
241
|
-
|
|
242
|
-
// Utils
|
|
243
|
-
logger,
|
|
244
|
-
retry,
|
|
245
|
-
} from "@johpaz/hive-sdk";
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## Testing
|
|
124
|
+
import { startGateway } from "@johpaz/hive-sdk";
|
|
251
125
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
bun test --timeout 30000
|
|
126
|
+
const server = await startGateway({
|
|
127
|
+
host: "127.0.0.1",
|
|
128
|
+
port: 18790,
|
|
129
|
+
agentId: "coordinator",
|
|
130
|
+
});
|
|
258
131
|
|
|
259
|
-
|
|
260
|
-
bun test packages/core/src/tools/ToolRegistry.test.ts
|
|
132
|
+
console.log(`Gateway at http://127.0.0.1:18790`);
|
|
261
133
|
```
|
|
262
134
|
|
|
263
|
-
---
|
|
264
|
-
|
|
265
135
|
## Variables de Entorno
|
|
266
136
|
|
|
267
137
|
```bash
|
|
268
|
-
HIVE_DATA_DIR=./data # Directorio de datos
|
|
138
|
+
HIVE_DATA_DIR=./data # Directorio de datos SQLite
|
|
269
139
|
HIVE_HOST=127.0.0.1 # Gateway host
|
|
270
140
|
HIVE_PORT=18790 # Gateway port
|
|
271
141
|
OPENAI_API_KEY=sk-... # OpenAI
|
|
272
142
|
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
|
|
143
|
+
GOOGLE_API_KEY=... # Gemini
|
|
273
144
|
LOG_LEVEL=info # debug | info | warn | error
|
|
274
145
|
```
|
|
275
146
|
|
|
276
|
-
|
|
147
|
+
## Tests
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Todos los tests (paralelo)
|
|
151
|
+
bun test
|
|
152
|
+
|
|
153
|
+
# Tests con timeout extendido
|
|
154
|
+
bun test --timeout 60000
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
|
|
277
158
|
|
|
278
|
-
## Licencia
|
|
279
159
|
|
|
280
|
-
|
|
160
|
+
*Documentación Hive SDK v0.0.18*
|