@johpaz/hive-sdk 0.0.17 → 0.1.3

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 (63) hide show
  1. package/README.md +83 -203
  2. package/bun.lock +833 -0
  3. package/bunfig.toml +7 -0
  4. package/docs/API-TOOLS-SKILLS-CHANNELS.md +60 -0
  5. package/docs/HIVE-HARNESS.md +113 -0
  6. package/package.json +36 -2
  7. package/packages/cli/package.json +1 -1
  8. package/packages/core/package.json +13 -2
  9. package/packages/core/src/ace/Tracer.ts +1 -1
  10. package/packages/core/src/agent/AgentRunner.ts +12 -0
  11. package/packages/core/src/agent/ContextCompiler.ts +4 -4
  12. package/packages/core/src/agent/ConversationStore.ts +30 -20
  13. package/packages/core/src/agent/selectors/PlaybookSelector.ts +50 -76
  14. package/packages/core/src/agent/selectors/SkillSelector.ts +106 -262
  15. package/packages/core/src/agent/selectors/ToolSelector.ts +54 -89
  16. package/packages/core/src/api/createAgent.ts +10 -0
  17. package/packages/core/src/auth/auth.ts +36 -23
  18. package/packages/core/src/config/loader.ts +2 -2
  19. package/packages/core/src/harness/boot-id.ts +20 -0
  20. package/packages/core/src/harness/collections.ts +98 -0
  21. package/packages/core/src/harness/db-helpers.ts +87 -0
  22. package/packages/core/src/harness/durable-queue.ts +337 -0
  23. package/packages/core/src/harness/goal-verifier.ts +141 -0
  24. package/packages/core/src/harness/harness.test.ts +236 -0
  25. package/packages/core/src/harness/index.ts +34 -0
  26. package/packages/core/src/harness/job-store.ts +399 -0
  27. package/packages/core/src/harness/proof-packet.ts +69 -0
  28. package/packages/core/src/harness/reconcile.ts +149 -0
  29. package/packages/core/src/harness/run-epoch.ts +32 -0
  30. package/packages/core/src/harness/run-store.ts +334 -0
  31. package/packages/core/src/index.ts +19 -0
  32. package/packages/core/src/memory/Scratchpad.test.ts +23 -21
  33. package/packages/core/src/memory/Scratchpad.ts +41 -24
  34. package/packages/core/src/skills/bundled-data.generated.ts +50 -0
  35. package/packages/core/src/skills/skills.test.ts +21 -0
  36. package/packages/core/src/storage/HiveDBStorage.ts +64 -0
  37. package/packages/core/src/storage/SQLiteStorage.ts +7 -0
  38. package/packages/core/src/storage/hiveSeed.ts +308 -0
  39. package/packages/core/src/storage/hiveStorage.test.ts +38 -0
  40. package/packages/core/src/storage/index.ts +10 -0
  41. package/packages/core/src/storage/seed.ts +5 -1
  42. package/packages/core/src/storage/usage.ts +106 -167
  43. package/packages/core/src/tool-runtime/tool-runtime.test.ts +11 -3
  44. package/packages/core/src/tools/agents/get-available-models.ts +52 -56
  45. package/packages/core/src/tools/agents/index.ts +77 -60
  46. package/packages/core/src/tools/core/index.ts +106 -291
  47. package/packages/core/src/tools/index.ts +1 -0
  48. package/packages/core/src/tools/meeting/index.ts +83 -93
  49. package/packages/core/src/tools/web/api-request.test.ts +170 -0
  50. package/packages/core/src/tools/web/api-request.ts +239 -0
  51. package/packages/core/src/tools/web/browser-click.ts +2 -2
  52. package/packages/core/src/tools/web/browser-extract.ts +22 -6
  53. package/packages/core/src/tools/web/browser-navigate.ts +34 -18
  54. package/packages/core/src/tools/web/browser-screenshot.ts +40 -8
  55. package/packages/core/src/tools/web/browser-script.ts +2 -2
  56. package/packages/core/src/tools/web/browser-service.test.ts +83 -0
  57. package/packages/core/src/tools/web/browser-service.ts +290 -341
  58. package/packages/core/src/tools/web/browser-type.ts +2 -2
  59. package/packages/core/src/tools/web/browser-wait.ts +2 -2
  60. package/packages/core/src/tools/web/index.ts +3 -0
  61. package/packages/core/src/utils/toon.ts +4 -4
  62. package/CHANGELOG.md +0 -72
  63. package/docs/README.md +0 -161
package/README.md CHANGED
@@ -1,80 +1,74 @@
1
- # Hive SDK
1
+ # Documentación — Hive SDK
2
2
 
3
- <p align="center">
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
- **The Hive Agent Harness SDK** — Build, deploy, and scale AI agent applications with multi-channel support, context engineering, and swarm orchestration.
5
+ ## Documentos
10
6
 
11
- > This Hive SDK powers the [Hive Harness](https://github.com/johpaz/hive-skd). Use it to create your own harness instances without building everything from scratch.
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
- ## Paquetes
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
- | Paquete | Descripción |
18
- |---------|-------------|
19
- | `@johpaz/hive-sdk` | Core SDK + CLI agents, tools, skills, MCP, storage, swarm, gateway, channels |
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
- # Install globally for the CLI
34
+ # Instalar globalmente para el CLI
25
35
  bun install -g @johpaz/hive-sdk
26
36
 
27
- # Or in a project
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
43
  ```bash
36
- hives create-app my-hive
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
37
52
  ```
38
53
 
39
- Generates a complete Hive harness with gateway, channels, and agent configuration.
40
-
41
- ### Create a lightweight agent project
54
+ ## Inicio Rápido
42
55
 
43
- ```bash
44
- hives init my-agent
45
- ```
46
-
47
- ### Add a tool to your project
48
-
49
- ```bash
50
- cd my-hive
51
- hives 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
- hives add-skill onboarding
61
+ bun install
62
+ cp .env.example .env
63
+ bun run dev
59
64
  ```
60
65
 
61
- ### Run your agent
62
-
63
- ```bash
64
- cd my-agent
65
- hives run
66
- ```
67
-
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 myTool = defineTool({
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: [myTool],
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
- ### Start a Gateway
88
+ ### 3. Crear un worker especializado
95
89
 
96
90
  ```typescript
97
- import { startGateway, createAgent, initializeDatabase } from "@johpaz/hive-sdk";
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 server = await startGateway({
108
- host: "127.0.0.1",
109
- port: 18790,
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
- console.log(`Gateway running at http://127.0.0.1:18790`);
98
+ const result = await researcher.run("Research quantum computing advances");
99
+ console.log(result);
100
+ researcher.terminate();
114
101
  ```
115
102
 
116
- ### Create a Swarm (DAG)
103
+ ### 4. Ejecutar workers en paralelo
117
104
 
118
105
  ```typescript
119
- import { DAGScheduler, TaskGraph } from "@johpaz/hive-sdk";
106
+ import { WorkerPool } from "@johpaz/hive-sdk";
120
107
 
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
- ]);
108
+ const pool = new WorkerPool({ maxWorkers: 4 });
126
109
 
127
- const result = await new DAGScheduler().execute(graph);
128
- ```
129
-
130
- ### Multi-Channel Bot
131
-
132
- ```typescript
133
- import { ChannelManager, TelegramChannel, DiscordChannel } from "@johpaz/hive-sdk";
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
+ ];
134
115
 
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! }));
139
-
140
- await manager.startAll();
116
+ const results = await pool.executeBatch(tasks);
117
+ console.log(results);
118
+ pool.shutdown();
141
119
  ```
142
120
 
143
- ---
144
-
145
- ## Estructura del Proyecto (SDK)
146
-
147
- ```
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
-
201
- ## API Pública
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
- ```bash
253
- # All tests
254
- bun test packages/core/src/
255
-
256
- # Tests with timeout
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
- # Specific tests
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
- MIT © 2024-2025 johpaz
160
+ *Documentación Hive SDK v0.0.18*