@johpaz/hive-sdk 0.0.14 → 0.0.16
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 +64 -0
- package/README.md +280 -0
- package/docs/API-AGENTS.md +316 -0
- package/docs/API-CONTEXT-COMPILER.md +252 -0
- package/docs/API-DAG-SCHEDULER.md +273 -0
- package/docs/API-TOOLS-SKILLS-CHANNELS.md +350 -0
- package/docs/API-WORKERS-EVENTS.md +299 -0
- package/docs/INDEX.md +190 -0
- package/docs/README.md +161 -0
- package/docs/TEMPLATE-HIVE-APP.md +360 -0
- package/package.json +60 -104
- package/packages/cli/bin/hive +2 -0
- package/packages/cli/package.json +17 -0
- package/packages/cli/src/commands/add-skill.ts +42 -0
- package/packages/cli/src/commands/add-tool.ts +45 -0
- package/packages/cli/src/commands/add-worker.ts +49 -0
- package/packages/cli/src/commands/create-app-utils.ts +32 -0
- package/packages/cli/src/commands/create-app.test.ts +151 -0
- package/packages/cli/src/commands/create-app.ts +35 -0
- package/packages/cli/src/commands/init.ts +56 -0
- package/packages/cli/src/commands/run.ts +45 -0
- package/packages/cli/src/commands/test.ts +42 -0
- package/packages/cli/src/commands/trace.ts +55 -0
- package/packages/cli/src/index.ts +59 -0
- package/packages/cli/templates/hive-app/.env.example +17 -0
- package/packages/cli/templates/hive-app/docker-compose.yml +20 -0
- package/packages/cli/templates/hive-app/hive.config.ts +19 -0
- package/packages/cli/templates/hive-app/package.json +16 -0
- package/packages/cli/templates/hive-app/src/agents/coordinator.ts +9 -0
- package/packages/cli/templates/hive-app/src/main.ts +56 -0
- package/packages/core/package.json +58 -0
- package/packages/core/src/ace/Curator.ts +158 -0
- package/packages/core/src/ace/Reflector.ts +200 -0
- package/packages/core/src/ace/Tracer.ts +100 -0
- package/packages/core/src/ace/index.ts +4 -0
- package/packages/core/src/agent/AgentRunner.ts +699 -0
- package/packages/core/src/agent/Compaction.ts +221 -0
- package/packages/core/src/agent/ContextCompiler.ts +567 -0
- package/packages/core/src/agent/ContextGuard.ts +91 -0
- package/packages/core/src/agent/ConversationStore.ts +244 -0
- package/packages/core/src/agent/Hooks.ts +166 -0
- package/packages/core/src/agent/NativeTools.ts +31 -0
- package/packages/core/src/agent/PromptBuilder.ts +169 -0
- package/packages/core/src/agent/Service.ts +267 -0
- package/packages/core/src/agent/StuckLoop.ts +133 -0
- package/packages/core/src/agent/index.ts +12 -0
- package/packages/core/src/agent/providers/LLMClient.ts +149 -0
- package/packages/core/src/agent/providers/anthropic.ts +212 -0
- package/packages/core/src/agent/providers/gemini.ts +215 -0
- package/packages/core/src/agent/providers/index.ts +199 -0
- package/packages/core/src/agent/providers/interface.ts +195 -0
- package/packages/core/src/agent/providers/ollama.ts +175 -0
- package/packages/core/src/agent/providers/openai-compat.ts +231 -0
- package/packages/core/src/agent/selectors/PlaybookSelector.ts +147 -0
- package/packages/core/src/agent/selectors/SkillSelector.ts +478 -0
- package/packages/core/src/agent/selectors/ToolSelector.ts +577 -0
- package/packages/core/src/agent/selectors/index.ts +6 -0
- package/packages/core/src/api/createAgent.test.ts +48 -0
- package/packages/core/src/api/createAgent.ts +122 -0
- package/packages/core/src/api/index.ts +2 -0
- package/packages/core/src/auth/auth.ts +108 -0
- package/packages/core/src/auth/index.ts +1 -0
- package/packages/core/src/canvas/CanvasManager.ts +390 -0
- package/packages/core/src/canvas/a2ui-tools.ts +255 -0
- package/packages/core/src/canvas/canvas-tools.ts +448 -0
- package/packages/core/src/canvas/canvas.test.ts +32 -0
- package/packages/core/src/canvas/emitter.ts +149 -0
- package/packages/core/src/canvas/index.ts +3 -0
- package/packages/core/src/channels/base.ts +154 -0
- package/packages/core/src/channels/channels.test.ts +18 -0
- package/packages/core/src/channels/discord.ts +273 -0
- package/packages/core/src/channels/index.ts +7 -0
- package/packages/core/src/channels/manager.ts +450 -0
- package/packages/core/src/channels/slack.ts +323 -0
- package/packages/core/src/channels/telegram.ts +612 -0
- package/packages/core/src/channels/webchat.ts +139 -0
- package/packages/core/src/channels/whatsapp.ts +548 -0
- package/packages/core/src/config/index.ts +2 -0
- package/packages/core/src/config/loader.ts +554 -0
- package/packages/core/src/ethics/EthicsGuard.test.ts +54 -0
- package/packages/core/src/ethics/EthicsGuard.ts +66 -0
- package/packages/core/src/ethics/index.ts +2 -0
- package/packages/core/src/events/agent-bus.ts +460 -0
- package/packages/core/src/events/event-bus.ts +169 -0
- package/packages/core/src/gateway/channel-notify.ts +37 -0
- package/packages/core/src/gateway/gateway.test.ts +38 -0
- package/packages/core/src/gateway/index.ts +2 -0
- package/packages/core/src/gateway/server.ts +139 -0
- package/packages/core/src/heartbeat/index.ts +157 -0
- package/packages/core/src/index.ts +81 -0
- package/packages/core/src/mcp/MCPClient.ts +439 -0
- package/packages/core/src/mcp/MCPToolAdapter.ts +176 -0
- package/packages/core/src/mcp/config.ts +13 -0
- package/packages/core/src/mcp/hot-reload.ts +147 -0
- package/packages/core/src/mcp/index.ts +11 -0
- package/packages/core/src/mcp/logger.ts +42 -0
- package/packages/core/src/mcp/singleton.ts +21 -0
- package/packages/core/src/mcp/transports/index.ts +67 -0
- package/packages/core/src/mcp/transports/sse.ts +241 -0
- package/packages/core/src/mcp/transports/websocket.ts +159 -0
- package/packages/core/src/memory/Scratchpad.test.ts +47 -0
- package/packages/core/src/memory/Scratchpad.ts +37 -0
- package/packages/core/src/memory/Storage.ts +6 -0
- package/packages/core/src/memory/index.ts +2 -0
- package/packages/core/src/multimodal/VisionService.ts +293 -0
- package/packages/core/src/multimodal/index.ts +2 -0
- package/packages/core/src/multimodal/types.ts +28 -0
- package/packages/core/src/multimodal/vision-service.ts +283 -0
- package/packages/core/src/plugins/api.ts +128 -0
- package/packages/core/src/plugins/index.ts +2 -0
- package/packages/core/src/plugins/loader.ts +365 -0
- package/packages/core/src/resilience/circuit-breaker.ts +225 -0
- package/packages/core/src/scheduler/CronScheduler.ts +699 -0
- package/packages/core/src/scheduler/dag/AgentExecutor.ts +53 -0
- package/packages/core/src/scheduler/dag/DAGScheduler.ts +250 -0
- package/packages/core/src/scheduler/dag/EventBridge.ts +122 -0
- package/packages/core/src/scheduler/dag/TaskGraph.ts +192 -0
- package/packages/core/src/scheduler/dag/TaskNode.ts +97 -0
- package/packages/core/src/scheduler/dag/TaskResult.ts +22 -0
- package/packages/core/src/scheduler/dag/errors.ts +37 -0
- package/packages/core/src/scheduler/dag/index.ts +26 -0
- package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +97 -0
- package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +21 -0
- package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +46 -0
- package/packages/core/src/scheduler/index.ts +22 -0
- package/packages/core/src/scheduler/integration.ts +237 -0
- package/packages/core/src/scheduler/scheduler.test.ts +19 -0
- package/packages/core/src/scheduler/types.ts +164 -0
- package/packages/core/src/security/Pairing.ts +250 -0
- package/packages/core/src/security/RateLimit.ts +270 -0
- package/packages/core/src/security/google-chat.ts +269 -0
- package/packages/core/src/security/index.ts +192 -0
- package/packages/core/src/security/rate-limit.ts +270 -0
- package/packages/core/src/security/signal.ts +321 -0
- package/packages/core/src/skills/SkillLoader.ts +388 -0
- package/packages/core/src/skills/bundled-data.generated.ts +3332 -0
- package/packages/core/src/skills/defineSkill.ts +18 -0
- package/packages/core/src/skills/index.ts +4 -0
- package/packages/core/src/state/index.ts +2 -0
- package/packages/core/src/state/store.ts +312 -0
- package/packages/core/src/storage/SQLiteStorage.ts +407 -0
- package/packages/core/src/storage/crypto.ts +233 -0
- package/packages/core/src/storage/index.ts +10 -0
- package/packages/core/src/storage/onboarding.ts +1603 -0
- package/packages/core/src/storage/schema.ts +689 -0
- package/packages/core/src/storage/seed.ts +740 -0
- package/packages/core/src/storage/storage.test.ts +37 -0
- package/packages/core/src/storage/usage.ts +374 -0
- package/packages/core/src/swarm/AgentBus.ts +460 -0
- package/packages/core/src/swarm/AgentExecutor.ts +53 -0
- package/packages/core/src/swarm/Coordinator.ts +251 -0
- package/packages/core/src/swarm/EventBridge.ts +122 -0
- package/packages/core/src/swarm/EventBus.ts +169 -0
- package/packages/core/src/swarm/TaskGraph.ts +192 -0
- package/packages/core/src/swarm/TaskNode.ts +97 -0
- package/packages/core/src/swarm/TaskResult.ts +22 -0
- package/packages/core/src/swarm/WorkerPool.ts +236 -0
- package/packages/core/src/swarm/errors.ts +37 -0
- package/packages/core/src/swarm/index.ts +30 -0
- package/packages/core/src/swarm/presets/HiveLearnPreset.ts +99 -0
- package/packages/core/src/swarm/presets/ResearchPreset.ts +97 -0
- package/packages/core/src/swarm/presets/index.ts +4 -0
- package/packages/core/src/swarm/strategies/ParallelStrategy.ts +21 -0
- package/packages/core/src/swarm/strategies/PriorityStrategy.ts +46 -0
- package/packages/core/src/swarm/strategies/index.ts +3 -0
- package/packages/core/src/swarm/swarm.test.ts +24 -0
- package/packages/core/src/swarm/types.ts +164 -0
- package/packages/core/src/tool-runtime/index.ts +522 -0
- package/packages/core/src/tool-runtime/tool-runtime.test.ts +91 -0
- package/packages/core/src/tool-runtime/tool-worker.ts +125 -0
- package/packages/core/src/tools/ToolExecutor.ts +58 -0
- package/packages/core/src/tools/ToolRegistry.test.ts +98 -0
- package/packages/core/src/tools/ToolRegistry.ts +61 -0
- package/packages/core/src/tools/agents/get-available-models.ts +118 -0
- package/packages/core/src/tools/agents/index.ts +715 -0
- package/packages/core/src/tools/bridge-events.ts +26 -0
- package/packages/core/src/tools/canvas/index.ts +375 -0
- package/packages/core/src/tools/cli/index.ts +142 -0
- package/packages/core/src/tools/codebridge/index.ts +342 -0
- package/packages/core/src/tools/core/index.ts +476 -0
- package/packages/core/src/tools/cron/index.ts +626 -0
- package/packages/core/src/tools/filesystem/fs-delete.ts +78 -0
- package/packages/core/src/tools/filesystem/fs-edit.ts +106 -0
- package/packages/core/src/tools/filesystem/fs-exists.ts +63 -0
- package/packages/core/src/tools/filesystem/fs-glob.ts +108 -0
- package/packages/core/src/tools/filesystem/fs-list.ts +129 -0
- package/packages/core/src/tools/filesystem/fs-read.ts +72 -0
- package/packages/core/src/tools/filesystem/fs-write.ts +67 -0
- package/packages/core/src/tools/filesystem/index.ts +34 -0
- package/packages/core/src/tools/filesystem/workspace-guard.ts +62 -0
- package/packages/core/src/tools/index.ts +231 -0
- package/packages/core/src/tools/meeting/index.ts +363 -0
- package/packages/core/src/tools/office/index.ts +47 -0
- package/packages/core/src/tools/office/office-escribir-docx.ts +192 -0
- package/packages/core/src/tools/office/office-escribir-pdf.ts +172 -0
- package/packages/core/src/tools/office/office-escribir-pptx.ts +174 -0
- package/packages/core/src/tools/office/office-escribir-xlsx.ts +116 -0
- package/packages/core/src/tools/office/office-leer-docx.ts +93 -0
- package/packages/core/src/tools/office/office-leer-pdf.ts +114 -0
- package/packages/core/src/tools/office/office-leer-pptx.ts +136 -0
- package/packages/core/src/tools/office/office-leer-xlsx.ts +124 -0
- package/packages/core/src/tools/projects/index.ts +37 -0
- package/packages/core/src/tools/projects/project-create.ts +94 -0
- package/packages/core/src/tools/projects/project-done.ts +66 -0
- package/packages/core/src/tools/projects/project-fail.ts +66 -0
- package/packages/core/src/tools/projects/project-list.ts +96 -0
- package/packages/core/src/tools/projects/project-update.ts +72 -0
- package/packages/core/src/tools/projects/task-create.ts +68 -0
- package/packages/core/src/tools/projects/task-evaluate.ts +93 -0
- package/packages/core/src/tools/projects/task-update.ts +93 -0
- package/packages/core/src/tools/types.ts +39 -0
- package/packages/core/src/tools/voice/index.ts +104 -0
- package/packages/core/src/tools/web/browser-click.ts +78 -0
- package/packages/core/src/tools/web/browser-extract.ts +139 -0
- package/packages/core/src/tools/web/browser-navigate.ts +106 -0
- package/packages/core/src/tools/web/browser-screenshot.ts +87 -0
- package/packages/core/src/tools/web/browser-script.ts +88 -0
- package/packages/core/src/tools/web/browser-service.ts +554 -0
- package/packages/core/src/tools/web/browser-type.ts +101 -0
- package/packages/core/src/tools/web/browser-wait.ts +136 -0
- package/packages/core/src/tools/web/index.ts +41 -0
- package/packages/core/src/tools/web/web-fetch.ts +78 -0
- package/packages/core/src/tools/web/web-search.ts +123 -0
- package/packages/core/src/utils/benchmark.ts +80 -0
- package/packages/core/src/utils/crypto.ts +73 -0
- package/packages/core/src/utils/date.ts +42 -0
- package/packages/core/src/utils/index.ts +10 -0
- package/packages/core/src/utils/logger.ts +389 -0
- package/packages/core/src/utils/retry.ts +70 -0
- package/packages/core/src/utils/toon.ts +253 -0
- package/packages/core/src/voice/index.ts +643 -0
- package/packages/core/src/workers/WorkerPool.ts +167 -0
- package/packages/core/src/workers/agent.worker.ts +68 -0
- package/packages/core/src/workers/createWorker.ts +144 -0
- package/packages/core/src/workers/index.ts +5 -0
- package/packages/core/src/workers/workers.test.ts +48 -0
- package/test/setup-db.ts +216 -0
- package/tsconfig.json +40 -0
- package/src/agents.ts +0 -1
- package/src/canvas.ts +0 -1
- package/src/channels.ts +0 -1
- package/src/config.ts +0 -1
- package/src/events.ts +0 -1
- package/src/gateway.ts +0 -1
- package/src/index.ts +0 -304
- package/src/mcp.ts +0 -1
- package/src/multimodal.ts +0 -1
- package/src/scheduler.ts +0 -1
- package/src/security.ts +0 -1
- package/src/skills.ts +0 -1
- package/src/state.ts +0 -1
- package/src/storage.ts +0 -1
- package/src/tools.ts +0 -1
- package/src/tts.ts +0 -1
- package/src/types.ts +0 -82
- package/src/utils.ts +0 -1
- package/src/voice.ts +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.0.16] - 2026-05-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Bun Workers individuales**: `createWorker()`, `WorkerPool`, `agent.worker.ts`
|
|
12
|
+
- Workers especializados con system prompt propio
|
|
13
|
+
- Ejecución en threads aislados via `Bun.Worker`
|
|
14
|
+
- Comunicación via `postMessage`/`onmessage`
|
|
15
|
+
- **Gateway simplificado**: HTTP/WebSocket server con `Bun.serve()`
|
|
16
|
+
- Endpoints: `/status`, `/chat`, `/ws`
|
|
17
|
+
- Streaming de respuestas en tiempo real
|
|
18
|
+
- **Channels**: Telegram, Discord, WhatsApp, Slack, Webchat
|
|
19
|
+
- **Tool Runtime**: Ejecución paralela de tools via Bun Workers
|
|
20
|
+
- **CLI mejorado**:
|
|
21
|
+
- `hive create-app <name>` — Generar app harness completa
|
|
22
|
+
- `hive add-tool <name>` — Generar boilerplate de tool
|
|
23
|
+
- `hive add-skill <name>` — Generar boilerplate de skill
|
|
24
|
+
- `hive add-worker <name>` — Generar Bun Worker
|
|
25
|
+
- **Template hive-app**: Proyecto harness completo con Docker, config, gateway
|
|
26
|
+
- **Tests del harness**: 39 tests pasando en 12 archivos
|
|
27
|
+
- Workers, Gateway, Channels, Canvas, Scheduler, Storage, Swarm, Tool Runtime
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- API pública expandida: exports de gateway, channels, canvas, scheduler, tool-runtime, workers
|
|
31
|
+
- `package.json`: versión 0.0.16, descripción actualizada, bin `hive`
|
|
32
|
+
- Documentación actualizada en `docs/`
|
|
33
|
+
|
|
34
|
+
## [0.0.10] - 2026-05-02
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
- DAG Scheduler with parallel worker execution
|
|
38
|
+
- Tool selector with FTS5 full-text search
|
|
39
|
+
- Skill selector with semantic triggers
|
|
40
|
+
- Context compiler for agent execution
|
|
41
|
+
- Canvas (ACE) real-time visualization
|
|
42
|
+
- Multi-channel support (Slack, Discord, Telegram, WhatsApp)
|
|
43
|
+
- AgentBus for inter-agent communication
|
|
44
|
+
- SQLite storage with FTS5 built-in
|
|
45
|
+
- 130+ passing tests
|
|
46
|
+
|
|
47
|
+
### Performance
|
|
48
|
+
- 3x faster than LangChain (Bun runtime)
|
|
49
|
+
- Parallel DAG execution (15x faster than sequential)
|
|
50
|
+
- Streaming TTFT benchmarks
|
|
51
|
+
- Worker metrics (12 tasks/sec throughput)
|
|
52
|
+
|
|
53
|
+
### Documentation
|
|
54
|
+
- Complete API documentation in docs/
|
|
55
|
+
- README comparison with LangChain
|
|
56
|
+
- Benchmark documentation
|
|
57
|
+
|
|
58
|
+
## [0.0.9] - 2026-01-01
|
|
59
|
+
|
|
60
|
+
### Added
|
|
61
|
+
- Initial release
|
|
62
|
+
- Agent execution with LLM providers
|
|
63
|
+
- Basic tool and skill system
|
|
64
|
+
- Gateway server
|
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Hive SDK
|
|
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>
|
|
8
|
+
|
|
9
|
+
**The Hive Agent Harness SDK** — Build, deploy, and scale AI agent applications with multi-channel support, context engineering, and swarm orchestration.
|
|
10
|
+
|
|
11
|
+
> This Hive SDK powers the [Hive Harness](https://github.com/johpaz/hive). Use it to create your own harness instances without building everything from scratch.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Paquetes
|
|
16
|
+
|
|
17
|
+
| Paquete | Descripción |
|
|
18
|
+
|---------|-------------|
|
|
19
|
+
| `@johpaz/hive-sdk` | Core SDK + CLI — agents, tools, skills, MCP, storage, swarm, gateway, channels |
|
|
20
|
+
|
|
21
|
+
## Instalación
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Install globally for the CLI
|
|
25
|
+
bun install -g @johpaz/hive-sdk
|
|
26
|
+
|
|
27
|
+
# Or in a project
|
|
28
|
+
bun add @johpaz/hive-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## CLI Commands
|
|
32
|
+
|
|
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
|
+
```bash
|
|
44
|
+
hive init my-agent
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Add a tool to your project
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
cd my-hive
|
|
51
|
+
hive add-tool search-docs
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Add a skill to your project
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cd my-hive
|
|
58
|
+
hive add-skill onboarding
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Run your agent
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd my-agent
|
|
65
|
+
hive run
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Inicio Rápido — Programmatic API
|
|
71
|
+
|
|
72
|
+
### Create an Agent
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { createAgent, defineTool } from "@johpaz/hive-sdk";
|
|
76
|
+
|
|
77
|
+
const myTool = defineTool({
|
|
78
|
+
name: "saludar",
|
|
79
|
+
description: "Saluda a alguien",
|
|
80
|
+
execute: async (args: { nombre: string }) => `¡Hola ${args.nombre}!`,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const agent = await createAgent({
|
|
84
|
+
name: "asistente",
|
|
85
|
+
provider: "openai",
|
|
86
|
+
model: "gpt-4o-mini",
|
|
87
|
+
tools: [myTool],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const respuesta = await agent.run("Saluda a Juan");
|
|
91
|
+
console.log(respuesta);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Start a Gateway
|
|
95
|
+
|
|
96
|
+
```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
|
+
});
|
|
106
|
+
|
|
107
|
+
const server = await startGateway({
|
|
108
|
+
host: "127.0.0.1",
|
|
109
|
+
port: 18790,
|
|
110
|
+
agentId: "coordinator",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
console.log(`Gateway running at http://127.0.0.1:18790`);
|
|
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);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Multi-Channel Bot
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { ChannelManager, TelegramChannel, DiscordChannel } from "@johpaz/hive-sdk";
|
|
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! }));
|
|
139
|
+
|
|
140
|
+
await manager.startAll();
|
|
141
|
+
```
|
|
142
|
+
|
|
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
|
|
202
|
+
|
|
203
|
+
```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
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# All tests
|
|
254
|
+
bun test packages/core/src/
|
|
255
|
+
|
|
256
|
+
# Tests with timeout
|
|
257
|
+
bun test --timeout 30000
|
|
258
|
+
|
|
259
|
+
# Specific tests
|
|
260
|
+
bun test packages/core/src/tools/ToolRegistry.test.ts
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Variables de Entorno
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
HIVE_DATA_DIR=./data # Directorio de datos
|
|
269
|
+
HIVE_HOST=127.0.0.1 # Gateway host
|
|
270
|
+
HIVE_PORT=18790 # Gateway port
|
|
271
|
+
OPENAI_API_KEY=sk-... # OpenAI
|
|
272
|
+
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
|
|
273
|
+
LOG_LEVEL=info # debug | info | warn | error
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Licencia
|
|
279
|
+
|
|
280
|
+
MIT © 2024-2025 Anomaly Co. / @Johpaz
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# API Reference — Agentes
|
|
2
|
+
|
|
3
|
+
## Índice
|
|
4
|
+
|
|
5
|
+
1. [createAgent](#createagent)
|
|
6
|
+
2. [AgentLoop](#agentloop)
|
|
7
|
+
3. [Tool Selector](#tool-selector)
|
|
8
|
+
4. [Skill Selector](#skill-selector)
|
|
9
|
+
5. [LLM Providers](#llm-providers)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## createAgent
|
|
14
|
+
|
|
15
|
+
Función de alto nivel para crear y ejecutar agentes.
|
|
16
|
+
|
|
17
|
+
### Firma
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createAgent } from "@johpaz/hive-sdk";
|
|
21
|
+
|
|
22
|
+
const agent = await createAgent(config: AgentConfig): Promise<Agent>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### AgentConfig
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
interface AgentConfig {
|
|
29
|
+
name: string;
|
|
30
|
+
model?: string; // default: gpt-4o-mini
|
|
31
|
+
provider?: "openai" | "anthropic" | "gemini" | "ollama";
|
|
32
|
+
systemPrompt?: string;
|
|
33
|
+
tools?: ToolDefinition[]; // Tools custom
|
|
34
|
+
skills?: SkillDefinition[]; // Skills custom
|
|
35
|
+
mcpServers?: Record<string, { // Servidores MCP
|
|
36
|
+
command?: string; // STDIO transport
|
|
37
|
+
url?: string; // SSE transport
|
|
38
|
+
args?: string[];
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
}>;
|
|
41
|
+
maxIterations?: number;
|
|
42
|
+
workspace?: string;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Agent
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface Agent {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly config: AgentConfig;
|
|
52
|
+
|
|
53
|
+
// Streaming chat
|
|
54
|
+
chat(message: string, opts?: {
|
|
55
|
+
threadId?: string;
|
|
56
|
+
channel?: string;
|
|
57
|
+
}): AsyncGenerator<AgentEvent>;
|
|
58
|
+
|
|
59
|
+
// Run to completion (devuelve string final)
|
|
60
|
+
run(task: string, opts?: {
|
|
61
|
+
threadId?: string;
|
|
62
|
+
channel?: string;
|
|
63
|
+
}): Promise<string>;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### AgentEvent
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
type AgentEvent =
|
|
71
|
+
| { type: "text"; content: string }
|
|
72
|
+
| { type: "tool_call"; name: string; args: Record<string, unknown> }
|
|
73
|
+
| { type: "tool_result"; name: string; result: unknown }
|
|
74
|
+
| { type: "done"; response: string };
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Ejemplo
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { createAgent, defineTool } from "@johpaz/hive-sdk";
|
|
81
|
+
|
|
82
|
+
const agent = await createAgent({
|
|
83
|
+
name: "asistente",
|
|
84
|
+
provider: "openai",
|
|
85
|
+
model: "gpt-4o-mini",
|
|
86
|
+
systemPrompt: "Eres un asistente útil.",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Streaming
|
|
90
|
+
for await (const event of agent.chat("Hola!")) {
|
|
91
|
+
if (event.type === "text") process.stdout.write(event.content);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Run to completion
|
|
95
|
+
const respuesta = await agent.run("Analiza las ventas del mes");
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## defineTool
|
|
101
|
+
|
|
102
|
+
Define una herramienta que el agente puede invocar.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { defineTool } from "@johpaz/hive-sdk";
|
|
106
|
+
|
|
107
|
+
const tool = defineTool({
|
|
108
|
+
name: "saludar",
|
|
109
|
+
description: "Saluda a alguien por su nombre",
|
|
110
|
+
execute: async (args: { nombre: string }) => {
|
|
111
|
+
return { mensaje: `¡Hola ${args.nombre}!` };
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### ToolDefinition
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
interface ToolDefinition {
|
|
120
|
+
name: string;
|
|
121
|
+
description: string;
|
|
122
|
+
schema?: z.ZodType; // Validación Zod opcional
|
|
123
|
+
execute: (args: any, config?: any) => Promise<any>;
|
|
124
|
+
category?: string;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## defineSkill
|
|
131
|
+
|
|
132
|
+
Define una composición de herramientas con triggers semánticos.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { defineSkill } from "@johpaz/hive-sdk";
|
|
136
|
+
|
|
137
|
+
const skill = defineSkill({
|
|
138
|
+
name: "analisis-datos",
|
|
139
|
+
description: "Analiza datos y genera reportes",
|
|
140
|
+
steps: [
|
|
141
|
+
{ action: "web_search", instruction: "Buscar datos relevantes" },
|
|
142
|
+
{ action: "create_report", instruction: "Generar reporte" },
|
|
143
|
+
],
|
|
144
|
+
tools: ["web_search", "create_report"],
|
|
145
|
+
triggers: ["analizar", "reporte", "datos"],
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## AgentLoop
|
|
152
|
+
|
|
153
|
+
Clase de bajo nivel para control directo del bucle del agente.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { AgentLoop, buildAgentLoop } from "@johpaz/hive-sdk";
|
|
157
|
+
|
|
158
|
+
const loop = buildAgentLoop({ mcpManager });
|
|
159
|
+
|
|
160
|
+
const stream = loop.stream(
|
|
161
|
+
{ messages: [{ role: "user", content: "Hola" }] },
|
|
162
|
+
{ configurable: { thread_id: "thread-1" } }
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
for await (const chunk of stream) {
|
|
166
|
+
if (chunk.agent?.messages) {
|
|
167
|
+
console.log(chunk.agent.messages[0].content);
|
|
168
|
+
}
|
|
169
|
+
if (chunk.tools?.messages) {
|
|
170
|
+
console.log("Tool result:", chunk.tools.messages);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### StreamChunk
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
interface StreamChunk {
|
|
179
|
+
agent?: { messages: any[] };
|
|
180
|
+
tools?: { messages: any[] };
|
|
181
|
+
usage?: { input_tokens: number; output_tokens: number };
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### runAgent (bajo nivel)
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { runAgent, runAgentIsolated } from "@johpaz/hive-sdk";
|
|
189
|
+
|
|
190
|
+
// Streaming
|
|
191
|
+
for await (const chunk of runAgent({
|
|
192
|
+
agentId: "assistant",
|
|
193
|
+
userMessage: "Analiza las ventas",
|
|
194
|
+
threadId: "thread-123",
|
|
195
|
+
})) {
|
|
196
|
+
// procesar chunk
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Modo aislado (para workers DAG)
|
|
200
|
+
const result = await runAgentIsolated({
|
|
201
|
+
agentId: "processor",
|
|
202
|
+
taskDescription: "Procesa estos datos",
|
|
203
|
+
threadId: "dag-thread",
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Tool Selector
|
|
210
|
+
|
|
211
|
+
Selección automática de tools basada en FTS5.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { selectTools, CORE_TOOL_CATALOG } from "@johpaz/hive-sdk";
|
|
215
|
+
|
|
216
|
+
// Seleccionar tools relevantes
|
|
217
|
+
const tools = selectTools("Buscar archivos en el proyecto");
|
|
218
|
+
console.log(tools.map(t => t.name));
|
|
219
|
+
|
|
220
|
+
// Con límite personalizado
|
|
221
|
+
const limited = selectTools("search query", CORE_TOOL_CATALOG, 3);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Constantes
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const MIN_RELEVANCE_THRESHOLD = -30;
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### CORE_TOOL_CATALOG
|
|
231
|
+
|
|
232
|
+
~50 tools built-in organizadas por categoría:
|
|
233
|
+
|
|
234
|
+
| Categoría | Descripción |
|
|
235
|
+
|-----------|-------------|
|
|
236
|
+
| filesystem | read, write, edit, delete, list, glob |
|
|
237
|
+
| web | web_search, web_fetch, browser automation |
|
|
238
|
+
| projects | project/task CRUD |
|
|
239
|
+
| cron | Croner-based scheduling |
|
|
240
|
+
| cli | Shell command execution |
|
|
241
|
+
| agents | Agent management, task delegation |
|
|
242
|
+
| canvas | UI rendering, A2UI |
|
|
243
|
+
| codebridge | Code execution bridge |
|
|
244
|
+
| voice | TTS/STT |
|
|
245
|
+
| core | save_note, notify, report_progress |
|
|
246
|
+
| office | PDF, DOCX, XLSX, PPTX |
|
|
247
|
+
| meeting | Meeting management |
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Skill Selector
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { selectSkills, getMinimalSkills } from "@johpaz/hive-sdk";
|
|
255
|
+
|
|
256
|
+
// Skills según mensaje
|
|
257
|
+
const skills = selectSkills("Analyze the sales data");
|
|
258
|
+
|
|
259
|
+
// Skills mínimos siempre disponibles
|
|
260
|
+
const minimal = getMinimalSkills();
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## LLM Providers
|
|
266
|
+
|
|
267
|
+
### Providers Soportados
|
|
268
|
+
|
|
269
|
+
| Provider | Modelos | Streaming |
|
|
270
|
+
|----------|---------|-----------|
|
|
271
|
+
| openai | gpt-4o, gpt-4o-mini | ✅ |
|
|
272
|
+
| anthropic | claude-sonnet, claude-haiku | ✅ |
|
|
273
|
+
| gemini | gemini-2.5-flash | ✅ |
|
|
274
|
+
| ollama | modelos locales | ✅ |
|
|
275
|
+
|
|
276
|
+
### callLLM
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { callLLM, resolveProviderConfig } from "@johpaz/hive-sdk";
|
|
280
|
+
|
|
281
|
+
const config = await resolveProviderConfig("openai", "gpt-4o-mini");
|
|
282
|
+
|
|
283
|
+
const response = await callLLM({
|
|
284
|
+
provider: config.provider,
|
|
285
|
+
model: config.model,
|
|
286
|
+
messages: [{ role: "user", content: "Hola" }],
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Errores Comunes
|
|
293
|
+
|
|
294
|
+
### createAgent: no se encuentra el agente
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// El agente no necesita existir en DB — createAgent lo gestiona internamente
|
|
298
|
+
// Si falla, verificar API keys en variables de entorno
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Tool no encontrada
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
// Verificar que la tool está registrada
|
|
305
|
+
const reg = new ToolRegistry();
|
|
306
|
+
reg.register(myTool);
|
|
307
|
+
reg.has("my_tool"); // true
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Context too large
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// Usar maybeCompact para reducir historial
|
|
314
|
+
const { maybeCompact } = await import("../agent/Compaction.ts");
|
|
315
|
+
await maybeCompact(threadId, { channel, userId });
|
|
316
|
+
```
|