@johpaz/hive-sdk 0.0.12 → 0.0.15
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/.github/CODEOWNERS +9 -0
- package/.github/workflows/publish.yml +89 -0
- package/.github/workflows/version-bump.yml +102 -0
- package/CHANGELOG.md +38 -0
- package/README.md +158 -0
- package/bun.lock +543 -0
- package/bunfig.toml +7 -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 +293 -0
- package/docs/API-WORKERS-EVENTS.md +152 -0
- package/docs/INDEX.md +141 -0
- package/docs/README.md +68 -0
- package/package.json +54 -105
- package/packages/cli/package.json +17 -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 +43 -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/providers.ts +1 -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/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/emitter.ts +149 -0
- package/packages/core/src/canvas/index.ts +6 -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/gateway/channel-notify.test.ts +14 -0
- package/packages/core/src/gateway/channel-notify.ts +12 -0
- package/packages/core/src/gateway/index.ts +1 -0
- package/packages/core/src/index.ts +37 -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/security/Pairing.ts +250 -0
- package/packages/core/src/security/RateLimit.ts +270 -0
- package/packages/core/src/security/index.ts +4 -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 +101 -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/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/types.ts +164 -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 +656 -0
- package/test/setup-db.ts +216 -0
- package/tsconfig.json +39 -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/docs/INDEX.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Índice de Documentación — Hive SDK
|
|
2
|
+
|
|
3
|
+
## Documentos de Usuario
|
|
4
|
+
|
|
5
|
+
| Documento | Descripción |
|
|
6
|
+
|-----------|-------------|
|
|
7
|
+
| [README.md](../README.md) | Introducción y guía rápida |
|
|
8
|
+
| [API-AGENTS.md](./API-AGENTS.md) | AgentLoop, Tool/Skill Selector, LLM Providers |
|
|
9
|
+
| [API-DAG-SCHEDULER.md](./API-DAG-SCHEDULER.md) | DAGScheduler, TaskGraph, Estrategias, Presets |
|
|
10
|
+
| [API-WORKERS-EVENTS.md](./API-WORKERS-EVENTS.md) | Workers, AgentBus, Eventos del sistema |
|
|
11
|
+
| [API-TOOLS-SKILLS-CHANNELS.md](./API-TOOLS-SKILLS-CHANNELS.md) | Tools, Skills, Canvas, Storage |
|
|
12
|
+
| [API-CONTEXT-COMPILER.md](./API-CONTEXT-COMPILER.md) | Context Compiler, MCP, LLM Client |
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Guía de Inicio Rápido
|
|
17
|
+
|
|
18
|
+
### 1. Crear Agente (nueva API)
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { createAgent, defineTool } from "@hive/core";
|
|
22
|
+
|
|
23
|
+
const tool = defineTool({
|
|
24
|
+
name: "saludar",
|
|
25
|
+
description: "Saluda a alguien",
|
|
26
|
+
execute: async (args: { nombre: string }) => `¡Hola ${args.nombre}!`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const agent = await createAgent({
|
|
30
|
+
name: "asistente",
|
|
31
|
+
provider: "openai",
|
|
32
|
+
model: "gpt-4o-mini",
|
|
33
|
+
tools: [tool],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const respuesta = await agent.run("Saluda a Juan");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 2. Crear un Swarm
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { DAGScheduler, TaskGraph } from "@hive/core";
|
|
43
|
+
|
|
44
|
+
const graph = new TaskGraph([
|
|
45
|
+
{ id: "task1", agentId: "worker", taskDescription: "Tarea 1", deps: [] },
|
|
46
|
+
{ id: "task2", agentId: "worker", taskDescription: "Tarea 2", deps: ["task1"] },
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const result = await new DAGScheduler().execute(graph);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Estructura de Paquetes
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
packages/
|
|
58
|
+
├── core/ # @hive/core
|
|
59
|
+
│ └── src/
|
|
60
|
+
│ ├── agent/ # AgentLoop, ContextCompiler
|
|
61
|
+
│ │ ├── providers/ # LLM providers (OpenAI, Anthropic, Gemini, Ollama)
|
|
62
|
+
│ │ └── selectors/ # FTS5 ToolSelector, SkillSelector
|
|
63
|
+
│ ├── tools/ # 66 built-in tools + ToolRegistry
|
|
64
|
+
│ ├── skills/ # SkillLoader, defineSkill()
|
|
65
|
+
│ ├── swarm/ # DAGScheduler, TaskGraph, WorkerPool
|
|
66
|
+
│ │ ├── strategies/ # Parallel, Priority
|
|
67
|
+
│ │ └── presets/ # HiveLearn, Research
|
|
68
|
+
│ ├── mcp/ # MCPClientManager + transports
|
|
69
|
+
│ ├── storage/ # SQLite (bun:sqlite) + FTS5
|
|
70
|
+
│ ├── ace/ # Tracer, Reflector, Curator
|
|
71
|
+
│ ├── canvas/ # CanvasManager + A2UI
|
|
72
|
+
│ ├── memory/ # Scratchpad
|
|
73
|
+
│ ├── ethics/ # EthicsGuard
|
|
74
|
+
│ ├── config/ # loadConfig
|
|
75
|
+
│ ├── utils/ # logger, toon
|
|
76
|
+
│ ├── api/ # createAgent()
|
|
77
|
+
│ └── index.ts # Public API
|
|
78
|
+
│
|
|
79
|
+
└── cli/ # @hive/cli
|
|
80
|
+
└── src/
|
|
81
|
+
└── commands/ # init, run, test, trace
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Conceptos Clave
|
|
87
|
+
|
|
88
|
+
### Agente
|
|
89
|
+
Unidad de ejecución con:
|
|
90
|
+
- Configuración (provider, model, system prompt)
|
|
91
|
+
- Contexto (historial, tools, skills)
|
|
92
|
+
- Ciclo de ejecución (prompt → LLM → tools → response)
|
|
93
|
+
|
|
94
|
+
### Tool
|
|
95
|
+
Función que el agente puede invocar:
|
|
96
|
+
- Definida con `defineTool()`
|
|
97
|
+
- Seleccionada dinámicamente via FTS5
|
|
98
|
+
- Ejecutada por el worker
|
|
99
|
+
|
|
100
|
+
### Skill
|
|
101
|
+
Composición de tools con triggers semánticos:
|
|
102
|
+
- Definida con `defineSkill()`
|
|
103
|
+
- Categorización automática
|
|
104
|
+
|
|
105
|
+
### Swarm (DAG)
|
|
106
|
+
Ejecución paralela de múltiples agentes:
|
|
107
|
+
- Nodos = tareas con dependencias
|
|
108
|
+
- Topological sort automático
|
|
109
|
+
- Workers paralelos con estrategias
|
|
110
|
+
|
|
111
|
+
### MCP
|
|
112
|
+
Model Context Protocol:
|
|
113
|
+
- Servidores MCP como herramientas externas
|
|
114
|
+
- Transports: STDIO, SSE, WebSocket
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Variables de Entorno
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
HIVE_DATA_DIR=./data # Directorio de datos
|
|
122
|
+
OPENAI_API_KEY=sk-... # OpenAI
|
|
123
|
+
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
|
|
124
|
+
LOG_LEVEL=info # debug | info | warn | error
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Tests
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Tests unitarios
|
|
133
|
+
bun test packages/core/src/
|
|
134
|
+
|
|
135
|
+
# Tests con timeout extendido
|
|
136
|
+
bun test --timeout 60000 packages/core/src/
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
*Documentación Hive SDK v2.0.0*
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Documentación — Hive SDK
|
|
2
|
+
|
|
3
|
+
## Documentos
|
|
4
|
+
|
|
5
|
+
| Documento | Descripción |
|
|
6
|
+
|-----------|-------------|
|
|
7
|
+
| [API-AGENTS.md](API-AGENTS.md) | createAgent, defineTool, defineSkill, AgentLoop, Tool/Skill Selector, LLM Providers |
|
|
8
|
+
| [API-DAG-SCHEDULER.md](API-DAG-SCHEDULER.md) | DAGScheduler, TaskGraph, TaskNode, Estrategias, Presets, EventBridge |
|
|
9
|
+
| [API-WORKERS-EVENTS.md](API-WORKERS-EVENTS.md) | Workers, AgentBus, EventBus, Canvas Events |
|
|
10
|
+
| [API-TOOLS-SKILLS-CHANNELS.md](API-TOOLS-SKILLS-CHANNELS.md) | ToolRegistry, ToolExecutor, SkillLoader, MCP, Canvas, Storage, Config |
|
|
11
|
+
| [API-CONTEXT-COMPILER.md](API-CONTEXT-COMPILER.md) | compileContext, Message History, Scratchpad, EthicsGuard, ACE, MCP Internals |
|
|
12
|
+
|
|
13
|
+
## Inicio Rápido
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Instalar
|
|
17
|
+
git clone https://github.com/anomalyco/hive-sdk.git
|
|
18
|
+
cd hive-sdk
|
|
19
|
+
bun install
|
|
20
|
+
|
|
21
|
+
# Test
|
|
22
|
+
bun test packages/core/src/
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createAgent, defineTool } from "@hive/core";
|
|
27
|
+
|
|
28
|
+
const tool = defineTool({
|
|
29
|
+
name: "saludar",
|
|
30
|
+
description: "Saluda a alguien",
|
|
31
|
+
execute: async (args: { nombre: string }) => `¡Hola ${args.nombre}!`,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const agent = await createAgent({
|
|
35
|
+
name: "asistente",
|
|
36
|
+
provider: "openai",
|
|
37
|
+
model: "gpt-4o-mini",
|
|
38
|
+
tools: [tool],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const respuesta = await agent.run("Saluda a Juan");
|
|
42
|
+
console.log(respuesta);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Variables de Entorno
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
HIVE_DATA_DIR=./data # Directorio de datos SQLite
|
|
49
|
+
OPENAI_API_KEY=sk-... # OpenAI
|
|
50
|
+
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
|
|
51
|
+
LOG_LEVEL=info # debug | info | warn | error
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Changelog
|
|
55
|
+
|
|
56
|
+
### v2.0.0
|
|
57
|
+
- Restructura completa a @hive/core, @hive/cli
|
|
58
|
+
- Nueva API: createAgent, defineTool, defineSkill
|
|
59
|
+
- Eliminados: gateway, channels, tts, voice service (migrados a hive-app)
|
|
60
|
+
- FTS5 preservado como ventaja competitiva
|
|
61
|
+
|
|
62
|
+
### v1.1.0
|
|
63
|
+
- Streaming TTFT benchmarks
|
|
64
|
+
- Worker performance metrics
|
|
65
|
+
- DAGScheduler executor option fix
|
|
66
|
+
|
|
67
|
+
### v1.0.0
|
|
68
|
+
- Lanzamiento inicial
|
package/package.json
CHANGED
|
@@ -1,113 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johpaz/hive-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Hive SDK —
|
|
3
|
+
"version": "0.0.15",
|
|
4
|
+
"description": "Hive SDK — Agentes AI con Context Engineering, FTS5, ACE, Swarm",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"main": "./src/index.ts",
|
|
11
|
-
"module": "./src/index.ts",
|
|
12
|
-
"types": "./src/index.ts",
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"types": "./src/index.ts",
|
|
16
|
-
"default": "./src/index.ts"
|
|
17
|
-
},
|
|
18
|
-
"./agents": {
|
|
19
|
-
"types": "./src/agents.ts",
|
|
20
|
-
"default": "./src/agents.ts"
|
|
21
|
-
},
|
|
22
|
-
"./tools": {
|
|
23
|
-
"types": "./src/tools.ts",
|
|
24
|
-
"default": "./src/tools.ts"
|
|
25
|
-
},
|
|
26
|
-
"./skills": {
|
|
27
|
-
"types": "./src/skills.ts",
|
|
28
|
-
"default": "./src/skills.ts"
|
|
29
|
-
},
|
|
30
|
-
"./mcp": {
|
|
31
|
-
"types": "./src/mcp.ts",
|
|
32
|
-
"default": "./src/mcp.ts"
|
|
33
|
-
},
|
|
34
|
-
"./tts": {
|
|
35
|
-
"types": "./src/tts.ts",
|
|
36
|
-
"default": "./src/tts.ts"
|
|
37
|
-
},
|
|
38
|
-
"./channels": {
|
|
39
|
-
"types": "./src/channels.ts",
|
|
40
|
-
"default": "./src/channels.ts"
|
|
41
|
-
},
|
|
42
|
-
"./storage": {
|
|
43
|
-
"types": "./src/storage.ts",
|
|
44
|
-
"default": "./src/storage.ts"
|
|
45
|
-
},
|
|
46
|
-
"./gateway": {
|
|
47
|
-
"types": "./src/gateway.ts",
|
|
48
|
-
"default": "./src/gateway.ts"
|
|
49
|
-
},
|
|
50
|
-
"./scheduler": {
|
|
51
|
-
"types": "./src/scheduler.ts",
|
|
52
|
-
"default": "./src/scheduler.ts"
|
|
53
|
-
},
|
|
54
|
-
"./events": {
|
|
55
|
-
"types": "./src/events.ts",
|
|
56
|
-
"default": "./src/events.ts"
|
|
57
|
-
},
|
|
58
|
-
"./state": {
|
|
59
|
-
"types": "./src/state.ts",
|
|
60
|
-
"default": "./src/state.ts"
|
|
61
|
-
},
|
|
62
|
-
"./security": {
|
|
63
|
-
"types": "./src/security.ts",
|
|
64
|
-
"default": "./src/security.ts"
|
|
65
|
-
},
|
|
66
|
-
"./config": {
|
|
67
|
-
"types": "./src/config.ts",
|
|
68
|
-
"default": "./src/config.ts"
|
|
69
|
-
},
|
|
70
|
-
"./canvas": {
|
|
71
|
-
"types": "./src/canvas.ts",
|
|
72
|
-
"default": "./src/canvas.ts"
|
|
73
|
-
},
|
|
74
|
-
"./voice": {
|
|
75
|
-
"types": "./src/voice.ts",
|
|
76
|
-
"default": "./src/voice.ts"
|
|
77
|
-
},
|
|
78
|
-
"./multimodal": {
|
|
79
|
-
"types": "./src/multimodal.ts",
|
|
80
|
-
"default": "./src/multimodal.ts"
|
|
81
|
-
},
|
|
82
|
-
"./utils": {
|
|
83
|
-
"types": "./src/utils.ts",
|
|
84
|
-
"default": "./src/utils.ts"
|
|
85
|
-
},
|
|
86
|
-
"./types": {
|
|
87
|
-
"types": "./src/types.ts",
|
|
88
|
-
"default": "./src/types.ts"
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
"peerDependencies": {
|
|
92
|
-
"typescript": "6.0.2"
|
|
6
|
+
"homepage": "https://github.com/anomalyco/hive-sdk#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/anomalyco/hive-sdk.git"
|
|
93
10
|
},
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"optional": true
|
|
97
|
-
}
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/anomalyco/hive-sdk/issues"
|
|
98
13
|
},
|
|
99
14
|
"keywords": [
|
|
100
|
-
"hive",
|
|
101
|
-
"sdk",
|
|
102
|
-
"agents",
|
|
103
15
|
"ai",
|
|
16
|
+
"agent",
|
|
104
17
|
"llm",
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
18
|
+
"context-engineering",
|
|
19
|
+
"fts5",
|
|
20
|
+
"swarm",
|
|
21
|
+
"ace",
|
|
22
|
+
"bun",
|
|
23
|
+
"langchain-alternative"
|
|
24
|
+
],
|
|
25
|
+
"main": "./packages/core/src/index.ts",
|
|
26
|
+
"types": "./packages/core/src/index.ts",
|
|
27
|
+
"workspaces": [
|
|
28
|
+
"packages/core",
|
|
29
|
+
"packages/cli"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "bun run typecheck",
|
|
33
|
+
"typecheck": "tsc --build --force",
|
|
34
|
+
"test": "bun test",
|
|
35
|
+
"prepublish": "echo 'No build needed - Bun runs TypeScript directly'"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@anthropic-ai/sdk": "^0.74.0",
|
|
39
|
+
"@google/genai": "^1.43.0",
|
|
40
|
+
"@modelcontextprotocol/sdk": "latest",
|
|
41
|
+
"@sapphire/snowflake": "latest",
|
|
42
|
+
"async-mutex": "^0.5.0",
|
|
43
|
+
"cron-parser": "^5.5.0",
|
|
44
|
+
"croner": "^10.0.1",
|
|
45
|
+
"docx": "^9.6.1",
|
|
46
|
+
"groq-sdk": "^0.37.0",
|
|
47
|
+
"jszip": "^3.10.1",
|
|
48
|
+
"pdf-lib": "^1.17.1",
|
|
49
|
+
"mammoth": "^1.12.0",
|
|
50
|
+
"ollama": "^0.6.3",
|
|
51
|
+
"openai": "^6.18.0",
|
|
52
|
+
"pdfjs-dist": "^5.6.205",
|
|
53
|
+
"pptxgenjs": "^4.0.1",
|
|
54
|
+
"toon-format-parser": "^1.1.0",
|
|
55
|
+
"xlsx": "^0.18.5",
|
|
56
|
+
"zod": "latest"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/bun": "^1.3.13",
|
|
60
|
+
"typescript": "6.0.2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hive/cli",
|
|
3
|
+
"version": "0.0.15",
|
|
4
|
+
"description": "Hive CLI — init, run, test, trace",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"hive": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"main": "./src/index.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@hive/core": "workspace:*"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import * as process from "node:process";
|
|
4
|
+
|
|
5
|
+
const TEMPLATE_DIR = join(import.meta.dir, "..", "..", "templates");
|
|
6
|
+
|
|
7
|
+
const HIVE_CONFIG = `{
|
|
8
|
+
"name": "my-hive-agent",
|
|
9
|
+
"version": "0.1.0",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@hive/core": "latest"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const HIVE_AGENT_TS = `import { createAgent, defineTool } from "@hive/core";
|
|
18
|
+
|
|
19
|
+
const myTool = defineTool({
|
|
20
|
+
name: "hello",
|
|
21
|
+
description: "Say hello",
|
|
22
|
+
execute: async (args: { name?: string }) => {
|
|
23
|
+
return { greeting: \`Hello, \${args.name ?? "world"}!\` };
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const agent = await createAgent({
|
|
28
|
+
name: "my-agent",
|
|
29
|
+
model: "gpt-4o",
|
|
30
|
+
provider: "openai",
|
|
31
|
+
tools: [myTool],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log("Agent ready:", agent.name);
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
async function runInit() {
|
|
38
|
+
const targetDir = process.argv[3] || process.cwd();
|
|
39
|
+
|
|
40
|
+
if (existsSync(join(targetDir, "hive.json"))) {
|
|
41
|
+
console.error("A hive project already exists in this directory.");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
writeFileSync(join(targetDir, "hive.json"), HIVE_CONFIG.trim());
|
|
46
|
+
writeFileSync(join(targetDir, "hive.agent.ts"), HIVE_AGENT_TS.trim());
|
|
47
|
+
|
|
48
|
+
console.log(`\nInitialized Hive project in ${targetDir}`);
|
|
49
|
+
console.log("\nFiles created:");
|
|
50
|
+
console.log(" hive.json - Project configuration");
|
|
51
|
+
console.log(" hive.agent.ts - Agent definition");
|
|
52
|
+
console.log("\nNext steps:");
|
|
53
|
+
console.log(" Run: hive run");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
runInit();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
async function runCommand() {
|
|
5
|
+
const agentFile = findAgentFile();
|
|
6
|
+
if (!agentFile) {
|
|
7
|
+
console.error("No hive.agent.ts or hive.agent.js found in current directory.");
|
|
8
|
+
console.error("Run 'hive init' to create one.");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
console.log(`Running agent from ${agentFile}...`);
|
|
13
|
+
const { createAgent } = await import("@hive/core");
|
|
14
|
+
const agentModule = await import(agentFile);
|
|
15
|
+
|
|
16
|
+
if (agentModule.agent) {
|
|
17
|
+
const input = process.argv[3] || process.env.HIVE_INPUT || "Hello!";
|
|
18
|
+
console.log(`\n--- Agent: ${agentModule.agent.name} ---`);
|
|
19
|
+
console.log(`Input: ${input}\n`);
|
|
20
|
+
|
|
21
|
+
for await (const event of agentModule.agent.chat(input)) {
|
|
22
|
+
if (event.type === "text") {
|
|
23
|
+
process.stdout.write(event.content);
|
|
24
|
+
} else if (event.type === "tool_call") {
|
|
25
|
+
console.log(`\n[Tool: ${event.name}]`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
console.log("\n--- Done ---");
|
|
29
|
+
} else {
|
|
30
|
+
console.error("Agent module does not export an 'agent' instance.");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function findAgentFile(): string | null {
|
|
36
|
+
const candidates = ["hive.agent.ts", "hive.agent.js", "agent.ts", "agent.js"];
|
|
37
|
+
const cwd = process.cwd();
|
|
38
|
+
for (const name of candidates) {
|
|
39
|
+
const full = join(cwd, name);
|
|
40
|
+
if (existsSync(full)) return full;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
runCommand();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
async function testCommand() {
|
|
3
|
+
const filter = process.argv[3];
|
|
4
|
+
|
|
5
|
+
console.log("Hive Test Runner\n");
|
|
6
|
+
|
|
7
|
+
const { initializeDatabase, dbService } = await import("@hive/core");
|
|
8
|
+
await initializeDatabase();
|
|
9
|
+
|
|
10
|
+
const { Glob } = await import("bun");
|
|
11
|
+
const glob = new Glob("packages/core/src/**/*.{test,spec}.ts");
|
|
12
|
+
const testFiles = Array.from(glob.scanSync({ cwd: process.cwd(), absolute: true }));
|
|
13
|
+
|
|
14
|
+
const tests = filter
|
|
15
|
+
? testFiles.filter((f: string) => f.includes(filter))
|
|
16
|
+
: testFiles;
|
|
17
|
+
|
|
18
|
+
if (tests.length === 0) {
|
|
19
|
+
console.log("No tests found.");
|
|
20
|
+
} else {
|
|
21
|
+
console.log(`Found ${tests.length} test(s)\n`);
|
|
22
|
+
let passed = 0;
|
|
23
|
+
let failed = 0;
|
|
24
|
+
|
|
25
|
+
for (const test of tests as string[]) {
|
|
26
|
+
try {
|
|
27
|
+
await import(test);
|
|
28
|
+
console.log(` ✓ ${test.split("/").pop()}`);
|
|
29
|
+
passed++;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(` ✗ ${test.split("/").pop()}: ${(err as Error).message}`);
|
|
32
|
+
failed++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
dbService.close();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
testCommand();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
async function traceCommand() {
|
|
3
|
+
const { initializeDatabase } = await import("@hive/core");
|
|
4
|
+
const { getDb } = await import("@hive/core/storage");
|
|
5
|
+
|
|
6
|
+
await initializeDatabase();
|
|
7
|
+
const db = getDb();
|
|
8
|
+
|
|
9
|
+
const limit = parseInt(process.argv[3] || "20", 10);
|
|
10
|
+
|
|
11
|
+
console.log(`\nRecent Trace Logs (last ${limit})\n`);
|
|
12
|
+
console.log("─".repeat(80));
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const rows = db
|
|
16
|
+
.query(
|
|
17
|
+
`SELECT id, agent_id, model, tool_calls, duration_ms, tokens_used, created_at
|
|
18
|
+
FROM traces
|
|
19
|
+
ORDER BY created_at DESC
|
|
20
|
+
LIMIT ?`
|
|
21
|
+
)
|
|
22
|
+
.all(limit) as Array<{
|
|
23
|
+
id: string;
|
|
24
|
+
agent_id: string;
|
|
25
|
+
model: string;
|
|
26
|
+
tool_calls: string;
|
|
27
|
+
duration_ms: number;
|
|
28
|
+
tokens_used: number;
|
|
29
|
+
created_at: string;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
if (rows.length === 0) {
|
|
33
|
+
console.log("No traces found.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const row of rows) {
|
|
38
|
+
console.log(`ID: ${row.id}`);
|
|
39
|
+
console.log(`Agent: ${row.agent_id}`);
|
|
40
|
+
console.log(`Model: ${row.model}`);
|
|
41
|
+
console.log(`Duration: ${row.duration_ms}ms`);
|
|
42
|
+
console.log(`Tokens: ${row.tokens_used}`);
|
|
43
|
+
console.log(`Time: ${row.created_at}`);
|
|
44
|
+
if (row.tool_calls) {
|
|
45
|
+
const tools = JSON.parse(row.tool_calls);
|
|
46
|
+
console.log(`Tools: ${Array.isArray(tools) ? tools.join(", ") : row.tool_calls}`);
|
|
47
|
+
}
|
|
48
|
+
console.log("─".repeat(80));
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.log("No traces table found (run the agent first).");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
traceCommand();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
export {};
|
|
4
|
+
const command = process.argv[2];
|
|
5
|
+
|
|
6
|
+
switch (command) {
|
|
7
|
+
case "init":
|
|
8
|
+
await import("./commands/init.ts");
|
|
9
|
+
break;
|
|
10
|
+
case "run":
|
|
11
|
+
await import("./commands/run.ts");
|
|
12
|
+
break;
|
|
13
|
+
case "test":
|
|
14
|
+
await import("./commands/test.ts");
|
|
15
|
+
break;
|
|
16
|
+
case "trace":
|
|
17
|
+
await import("./commands/trace.ts");
|
|
18
|
+
break;
|
|
19
|
+
case "--help":
|
|
20
|
+
case "-h":
|
|
21
|
+
case undefined:
|
|
22
|
+
printHelp();
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
console.error(`Unknown command: ${command}`);
|
|
26
|
+
printHelp();
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function printHelp() {
|
|
31
|
+
console.log(`
|
|
32
|
+
Usage: hive <command> [options]
|
|
33
|
+
|
|
34
|
+
Commands:
|
|
35
|
+
init Initialize a new Hive project
|
|
36
|
+
run Run the agent
|
|
37
|
+
test Test tools or skills
|
|
38
|
+
trace View trace execution logs
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
--help, -h Show this help message
|
|
42
|
+
`);
|
|
43
|
+
}
|