@johpaz/hive-sdk 0.1.6 → 0.3.0
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 +441 -0
- package/README.md +21 -3
- package/package.json +27 -5
- package/packages/core/src/agent/acceptance-checks.ts +9 -9
- package/packages/core/src/agent/agent-catalog.ts +82 -25
- package/packages/core/src/agent/agent-loop.ts +115 -26
- package/packages/core/src/agent/capability-search.ts +2 -2
- package/packages/core/src/agent/catalog-selector.ts +4 -4
- package/packages/core/src/agent/compaction.ts +30 -10
- package/packages/core/src/agent/context-compiler.ts +63 -36
- package/packages/core/src/agent/conversation-store.ts +167 -9
- package/packages/core/src/agent/curator.ts +16 -7
- package/packages/core/src/agent/delegation-runtime.ts +5 -5
- package/packages/core/src/agent/goal-runner.ts +9 -9
- package/packages/core/src/agent/index.ts +1 -0
- package/packages/core/src/agent/llm-client.ts +98 -37
- package/packages/core/src/agent/llm-providers/anthropic.ts +4 -4
- package/packages/core/src/agent/llm-providers/deepseek.ts +1 -1
- package/packages/core/src/agent/llm-providers/gemini.ts +4 -4
- package/packages/core/src/agent/llm-providers/groq.ts +1 -1
- package/packages/core/src/agent/llm-providers/hiveagents.ts +3 -3
- package/packages/core/src/agent/llm-providers/interface.ts +2 -2
- package/packages/core/src/agent/llm-providers/kimi.ts +1 -1
- package/packages/core/src/agent/llm-providers/minimax.ts +1 -1
- package/packages/core/src/agent/llm-providers/mistral.ts +1 -1
- package/packages/core/src/agent/llm-providers/modelscope.ts +1 -1
- package/packages/core/src/agent/llm-providers/nvidia.ts +40 -1
- package/packages/core/src/agent/llm-providers/ollama.ts +4 -4
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +47 -7
- package/packages/core/src/agent/llm-providers/openai.ts +1 -1
- package/packages/core/src/agent/llm-providers/opencode-go.ts +1 -1
- package/packages/core/src/agent/llm-providers/openrouter.ts +1 -1
- package/packages/core/src/agent/llm-providers/qwen.ts +1 -1
- package/packages/core/src/agent/llm-providers/z-ai.ts +1 -1
- package/packages/core/src/agent/mcp-result-normalizer.ts +192 -0
- package/packages/core/src/agent/playbook-selector.ts +22 -7
- package/packages/core/src/agent/prompt-builder.ts +5 -5
- package/packages/core/src/agent/proof-packet.ts +5 -5
- package/packages/core/src/agent/providers/index.ts +39 -4
- package/packages/core/src/agent/realtime-providers/gemini-live.ts +238 -0
- package/packages/core/src/agent/realtime-providers/index.ts +29 -0
- package/packages/core/src/agent/realtime-providers/interface.ts +108 -0
- package/packages/core/src/agent/reflector.ts +38 -15
- package/packages/core/src/agent/run-store.ts +8 -8
- package/packages/core/src/agent/service.ts +10 -10
- package/packages/core/src/agent/skill-selector.ts +6 -6
- package/packages/core/src/agent/thread-id.ts +71 -0
- package/packages/core/src/agent/thread-store.ts +293 -0
- package/packages/core/src/agent/tool-selector.ts +9 -5
- package/packages/core/src/agent/tracer.ts +5 -5
- package/packages/core/src/api/createAgent.ts +67 -2
- package/packages/core/src/artifacts/index.ts +15 -0
- package/packages/core/src/artifacts/store.ts +161 -5
- package/packages/core/src/canvas/emitter.ts +2 -2
- package/packages/core/src/canvas/index.ts +9 -0
- package/packages/core/src/channels/telegram.ts +1 -1
- package/packages/core/src/channels/webchat.ts +1 -1
- package/packages/core/src/config/loader.ts +14 -5
- package/packages/core/src/ethics/EthicsGuard.ts +7 -1
- package/packages/core/src/events/agent-bus.ts +3 -3
- package/packages/core/src/events/channel-narration.ts +3 -3
- package/packages/core/src/events/event-bus.ts +1 -1
- package/packages/core/src/events/index.ts +18 -0
- package/packages/core/src/events/narration.ts +3 -3
- package/packages/core/src/events/tool-narration.ts +4 -0
- package/packages/core/src/gateway/channel-notify.ts +103 -6
- package/packages/core/src/gateway/delegation-groups.ts +4 -4
- package/packages/core/src/gateway/durable-queue.ts +18 -6
- package/packages/core/src/gateway/index.ts +3 -0
- package/packages/core/src/gateway/job-store.ts +11 -5
- package/packages/core/src/gateway/notification-inbox.ts +2 -2
- package/packages/core/src/gateway/server.ts +2 -2
- package/packages/core/src/harness/executors.ts +493 -0
- package/packages/core/src/harness/index.ts +12 -2
- package/packages/core/src/hooks/index.ts +203 -0
- package/packages/core/src/images/index.ts +161 -0
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/mcp/MCPClient.ts +3 -3
- package/packages/core/src/mcp/hot-reload.ts +5 -5
- package/packages/core/src/mcp/tool-sync.ts +5 -5
- package/packages/core/src/mcp/transports/index.ts +2 -2
- package/packages/core/src/mcp/transports/sse.ts +1 -1
- package/packages/core/src/models/index.ts +36 -0
- package/packages/core/src/multimodal/index.ts +2 -2
- package/packages/core/src/multimodal/vision-service.ts +51 -19
- package/packages/core/src/plugins/loader.ts +4 -1
- package/packages/core/src/resilience/circuit-breaker.ts +16 -5
- package/packages/core/src/resilience/index.ts +13 -0
- package/packages/core/src/resilience/retry.ts +1 -1
- package/packages/core/src/scheduler/CronScheduler.ts +54 -27
- package/packages/core/src/scheduler/cron/expression.ts +165 -0
- package/packages/core/src/scheduler/cron/index.ts +10 -0
- package/packages/core/src/scheduler/cron/job.ts +339 -0
- package/packages/core/src/scheduler/cron/next-run.ts +121 -0
- package/packages/core/src/scheduler/cron/zoned-time.ts +138 -0
- package/packages/core/src/scheduler/index.ts +21 -3
- package/packages/core/src/scheduler/integration.ts +25 -14
- package/packages/core/src/scheduler/types.ts +3 -18
- package/packages/core/src/services/agents.ts +268 -0
- package/packages/core/src/services/cron.ts +257 -0
- package/packages/core/src/services/endpoints.ts +289 -0
- package/packages/core/src/services/ethics.ts +107 -0
- package/packages/core/src/services/images.ts +212 -0
- package/packages/core/src/services/index.ts +112 -0
- package/packages/core/src/services/mcp.ts +201 -0
- package/packages/core/src/services/memory.ts +133 -0
- package/packages/core/src/services/models.ts +179 -0
- package/packages/core/src/services/providers.ts +152 -0
- package/packages/core/src/services/setup.ts +222 -0
- package/packages/core/src/services/skills.ts +241 -0
- package/packages/core/src/services/swarms.ts +307 -0
- package/packages/core/src/services/tools.ts +106 -0
- package/packages/core/src/sessions/index.ts +268 -0
- package/packages/core/src/sessions/resolve.ts +108 -0
- package/packages/core/src/skills/SkillLoader.ts +8 -1
- package/packages/core/src/skills/bundled/artifacts/artifact_reader/SKILL.md +105 -0
- package/packages/core/src/skills/bundled/cron_manager/SKILL.md +21 -11
- package/packages/core/src/skills/bundled/images/image_editor/SKILL.md +120 -0
- package/packages/core/src/skills/bundled/web/browser_automate/SKILL.md +12 -3
- package/packages/core/src/skills/bundled/web/browser_scrape/SKILL.md +22 -7
- package/packages/core/src/skills/bundled-data.generated.ts +110 -12
- package/packages/core/src/storage/bootstrap.ts +107 -12
- package/packages/core/src/storage/causal-events.ts +1 -1
- package/packages/core/src/storage/collections.ts +138 -2
- package/packages/core/src/storage/crypto.ts +35 -4
- package/packages/core/src/storage/hive.ts +1 -1
- package/packages/core/src/storage/hivedb.ts +10 -1
- package/packages/core/src/storage/index.ts +2 -1
- package/packages/core/src/storage/onboarding.ts +61 -45
- package/packages/core/src/storage/reconcile.ts +11 -6
- package/packages/core/src/storage/seed.ts +191 -23
- package/packages/core/src/storage/usage.ts +3 -3
- package/packages/core/src/swarm/AgentExecutor.ts +2 -2
- package/packages/core/src/swarm/Coordinator.ts +8 -8
- package/packages/core/src/swarm/EventBridge.ts +2 -2
- package/packages/core/src/swarm/RoleSwarm.ts +234 -0
- package/packages/core/src/swarm/TaskGraph.ts +2 -2
- package/packages/core/src/swarm/index.ts +7 -0
- package/packages/core/src/swarm/presets/HiveLearnPreset.ts +2 -2
- package/packages/core/src/swarm/presets/ResearchPreset.ts +2 -2
- package/packages/core/src/swarm/strategies/ParallelStrategy.ts +1 -1
- package/packages/core/src/swarm/strategies/PriorityStrategy.ts +3 -3
- package/packages/core/src/swarm/types.ts +3 -18
- package/packages/core/src/tool-runtime/embedded-worker.generated.ts +21 -0
- package/packages/core/src/tool-runtime/index.ts +129 -14
- package/packages/core/src/tools/ToolExecutor.ts +7 -3
- package/packages/core/src/tools/agents/index.ts +18 -60
- package/packages/core/src/tools/cli/index.ts +55 -0
- package/packages/core/src/tools/core/index.ts +52 -4
- package/packages/core/src/tools/cron/index.ts +8 -8
- package/packages/core/src/tools/images/index.ts +130 -0
- package/packages/core/src/tools/index.ts +14 -1
- package/packages/core/src/tools/office/office-escribir-xlsx.ts +2 -1
- package/packages/core/src/tools/office/office-leer-xlsx.ts +2 -1
- package/packages/core/src/tools/office/xlsx-loader.ts +19 -0
- package/packages/core/src/tools/web/artifact-inspect.ts +2 -2
- package/packages/core/src/tools/web/artifact-read.ts +162 -0
- package/packages/core/src/tools/web/browser-backend.ts +141 -44
- package/packages/core/src/tools/web/browser-click.ts +2 -2
- package/packages/core/src/tools/web/browser-extract.ts +2 -2
- package/packages/core/src/tools/web/browser-navigate.ts +2 -2
- package/packages/core/src/tools/web/browser-screenshot.ts +12 -5
- package/packages/core/src/tools/web/browser-script.ts +2 -2
- package/packages/core/src/tools/web/browser-service.ts +63 -384
- package/packages/core/src/tools/web/browser-session.ts +125 -0
- 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/computer-use.ts +553 -0
- package/packages/core/src/tools/web/index.ts +8 -1
- package/packages/core/src/tools/web/webview-backend.ts +460 -21
- package/packages/core/src/utils/index.ts +1 -0
- package/packages/core/src/utils/logger.ts +12 -4
- package/packages/core/src/utils/redact-binary.ts +17 -0
- package/packages/core/src/utils/toon.ts +1 -1
- package/packages/core/src/voice/index.ts +6 -6
- package/bun.lock +0 -859
- package/bunfig.toml +0 -9
- package/docs/API-AGENTS.md +0 -367
- package/docs/API-CONTEXT-COMPILER.md +0 -249
- package/docs/API-DAG-SCHEDULER.md +0 -273
- package/docs/API-TOOLS-SKILLS-CHANNELS.md +0 -446
- package/docs/API-WORKERS-EVENTS.md +0 -299
- package/docs/HIVE-HARNESS.md +0 -113
- package/docs/INDEX.md +0 -190
- package/docs/TEMPLATE-HIVE-APP.md +0 -360
- package/packages/cli/package.json +0 -17
- package/packages/cli/src/commands/create-app.test.ts +0 -180
- package/packages/core/package.json +0 -70
- package/packages/core/src/api/createAgent.test.ts +0 -160
- package/packages/core/src/canvas/canvas.test.ts +0 -36
- package/packages/core/src/channels/channels.test.ts +0 -18
- package/packages/core/src/ethics/EthicsGuard.test.ts +0 -108
- package/packages/core/src/gateway/gateway.test.ts +0 -38
- package/packages/core/src/memory/Scratchpad.test.ts +0 -68
- package/packages/core/src/scheduler/scheduler.test.ts +0 -15
- package/packages/core/src/skills/skills.test.ts +0 -62
- package/packages/core/src/swarm/swarm.test.ts +0 -24
- package/packages/core/src/tool-runtime/tool-runtime.test.ts +0 -99
- package/packages/core/src/tools/ToolRegistry.test.ts +0 -98
- package/packages/core/src/tools/api/api-request.test.ts +0 -164
- package/packages/core/src/tools/web/browser-service.test.ts +0 -83
- package/packages/core/src/workers/workers.test.ts +0 -41
- package/scripts/bump-version.ts +0 -248
- package/scripts/generate-skill-bundle.ts +0 -108
- package/test/acceptance-checks.test.ts +0 -403
- package/test/agent-loop-terminal-synthesis.test.ts +0 -32
- package/test/browser-backend.test.ts +0 -308
- package/test/catalog-agents-stay-enabled.test.ts +0 -117
- package/test/causal-events.test.ts +0 -117
- package/test/compaction.test.ts +0 -105
- package/test/context-compiler.test.ts +0 -269
- package/test/curator.test.ts +0 -130
- package/test/durable-queue.test.ts +0 -114
- package/test/harness-barrel.test.ts +0 -64
- package/test/hive-helpers.test.ts +0 -130
- package/test/hivedb-search.test.ts +0 -189
- package/test/internal-turns.test.ts +0 -166
- package/test/job-idempotency.test.ts +0 -68
- package/test/job-retry-backoff.test.ts +0 -184
- package/test/job-store.test.ts +0 -381
- package/test/llm-retry.test.ts +0 -97
- package/test/memory-perf.test.ts +0 -774
- package/test/minimal-loadout.test.ts +0 -78
- package/test/model-catalog.test.ts +0 -105
- package/test/preload.ts +0 -12
- package/test/reflector.test.ts +0 -320
- package/test/retention-cap.test.ts +0 -91
- package/test/retired-capabilities-pruned.test.ts +0 -192
- package/test/run-store.test.ts +0 -355
- package/test/scratchpad.test.ts +0 -74
- package/test/secrets-durability.test.ts +0 -119
- package/test/seed-model-reseed.test.ts +0 -155
- package/test/setup-agent-seed.test.ts +0 -264
- package/test/tool-inventory.test.ts +0 -65
- package/test/tool-runtime.test.ts +0 -258
- package/test/tool-selector-runtime-tools.test.ts +0 -117
- package/test/toon.test.ts +0 -429
- package/tsconfig.json +0 -42
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
# API Reference — Workers y Eventos
|
|
2
|
-
|
|
3
|
-
## Índice
|
|
4
|
-
|
|
5
|
-
1. [Bun Workers](#bun-workers)
|
|
6
|
-
2. [createWorker](#createworker)
|
|
7
|
-
3. [WorkerPool](#workerpool)
|
|
8
|
-
4. [AgentBus](#agentbus)
|
|
9
|
-
5. [EventBus](#eventbus)
|
|
10
|
-
6. [Canvas Events](#canvas-events)
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## Bun Workers
|
|
15
|
-
|
|
16
|
-
Hive SDK soporta **workers individuales con Bun Workers**. Cada worker corre en un thread aislado (`Bun.Worker` con `{ smol: true }`), con su propio system prompt y configuración.
|
|
17
|
-
|
|
18
|
-
### Casos de uso
|
|
19
|
-
|
|
20
|
-
- **Workers especializados**: Un worker para research, otro para coding, otro para review
|
|
21
|
-
- **Paralelismo**: Ejecutar múltiples tareas simultáneamente sin bloquear el hilo principal
|
|
22
|
-
- **Aislamiento**: Cada worker tiene su propio contexto y no interfere con otros
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## createWorker
|
|
27
|
-
|
|
28
|
-
Crea un worker individual con Bun Workers.
|
|
29
|
-
|
|
30
|
-
### Firma
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { createWorker } from "@johpaz/hive-sdk";
|
|
34
|
-
|
|
35
|
-
const worker = createWorker(config: WorkerConfig): WorkerInstance
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### WorkerConfig
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
interface WorkerConfig {
|
|
42
|
-
name: string; // Identificador del worker
|
|
43
|
-
agentId?: string; // ID del agente en DB (default: name)
|
|
44
|
-
systemPrompt?: string; // System prompt personalizado
|
|
45
|
-
model?: string; // Modelo LLM
|
|
46
|
-
provider?: string; // Provider LLM
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### WorkerInstance
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
interface WorkerInstance {
|
|
54
|
-
readonly name: string;
|
|
55
|
-
readonly id: string;
|
|
56
|
-
|
|
57
|
-
// Ejecutar y esperar resultado
|
|
58
|
-
run(message: string, opts?: {
|
|
59
|
-
threadId?: string;
|
|
60
|
-
channel?: string;
|
|
61
|
-
}): Promise<string>;
|
|
62
|
-
|
|
63
|
-
// Streaming de resultados
|
|
64
|
-
runStream(message: string, opts?: {
|
|
65
|
-
threadId?: string;
|
|
66
|
-
channel?: string;
|
|
67
|
-
}): AsyncGenerator<WorkerChunk>;
|
|
68
|
-
|
|
69
|
-
// Terminar el worker
|
|
70
|
-
terminate(): void;
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Ejemplo básico
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { createWorker } from "@johpaz/hive-sdk";
|
|
78
|
-
|
|
79
|
-
const researcher = createWorker({
|
|
80
|
-
name: "researcher",
|
|
81
|
-
systemPrompt: `
|
|
82
|
-
You are a research specialist.
|
|
83
|
-
Provide concise, factual summaries with citations.
|
|
84
|
-
Always verify facts before presenting them.
|
|
85
|
-
`,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const result = await researcher.run("Latest advances in quantum computing 2025");
|
|
89
|
-
console.log(result);
|
|
90
|
-
|
|
91
|
-
researcher.terminate();
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Streaming
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
const stream = researcher.runStream("Explain quantum entanglement");
|
|
98
|
-
|
|
99
|
-
for await (const chunk of stream) {
|
|
100
|
-
if (chunk.type === "chunk") {
|
|
101
|
-
console.log("Chunk:", chunk.chunk);
|
|
102
|
-
} else if (chunk.type === "result") {
|
|
103
|
-
console.log("Final:", chunk.content);
|
|
104
|
-
} else if (chunk.type === "error") {
|
|
105
|
-
console.error("Error:", chunk.error);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## WorkerPool
|
|
113
|
-
|
|
114
|
-
Gestiona un pool de Bun Workers para ejecución paralela.
|
|
115
|
-
|
|
116
|
-
### Firma
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { WorkerPool } from "@johpaz/hive-sdk";
|
|
120
|
-
|
|
121
|
-
const pool = new WorkerPool(config?: WorkerPoolConfig);
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### WorkerPoolConfig
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
interface WorkerPoolConfig {
|
|
128
|
-
maxWorkers?: number; // Default: 4
|
|
129
|
-
taskTimeoutMs?: number; // Default: 120000
|
|
130
|
-
workerConfig?: WorkerConfig;
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Métodos
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
// Ejecutar una tarea
|
|
138
|
-
pool.execute(task: PoolTask): Promise<PoolTaskResult>
|
|
139
|
-
|
|
140
|
-
// Ejecutar múltiples tareas en paralelo
|
|
141
|
-
pool.executeBatch(tasks: PoolTask[]): Promise<PoolTaskResult[]>
|
|
142
|
-
|
|
143
|
-
// Ejecutar con límite de concurrencia
|
|
144
|
-
pool.executeWithConcurrency(tasks: PoolTask[], concurrency: number): Promise<PoolTaskResult[]>
|
|
145
|
-
|
|
146
|
-
// Estadísticas
|
|
147
|
-
pool.stats // { total, busy, idle }
|
|
148
|
-
|
|
149
|
-
// Cerrar todos los workers
|
|
150
|
-
pool.shutdown(): void
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Ejemplo: Batch processing
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import { WorkerPool } from "@johpaz/hive-sdk";
|
|
157
|
-
|
|
158
|
-
const pool = new WorkerPool({
|
|
159
|
-
maxWorkers: 4,
|
|
160
|
-
workerConfig: {
|
|
161
|
-
name: "analyzer",
|
|
162
|
-
systemPrompt: "You analyze text and extract key insights.",
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const articles = [
|
|
167
|
-
{ id: "a1", message: "Summarize article about AI..." },
|
|
168
|
-
{ id: "a2", message: "Summarize article about climate..." },
|
|
169
|
-
{ id: "a3", message: "Summarize article about space..." },
|
|
170
|
-
];
|
|
171
|
-
|
|
172
|
-
const results = await pool.executeBatch(articles);
|
|
173
|
-
|
|
174
|
-
for (const result of results) {
|
|
175
|
-
console.log(`${result.taskId}: ${result.result} (${result.durationMs}ms)`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
pool.shutdown();
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Ejemplo: Concurrency limit
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
// Procesar 100 tareas pero solo 5 a la vez
|
|
185
|
-
const tasks = Array.from({ length: 100 }, (_, i) => ({
|
|
186
|
-
id: `task-${i}`,
|
|
187
|
-
message: `Process item ${i}`,
|
|
188
|
-
}));
|
|
189
|
-
|
|
190
|
-
const results = await pool.executeWithConcurrency(tasks, 5);
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
## CLI: hives add-worker
|
|
196
|
-
|
|
197
|
-
Genera un Bun Worker en tu proyecto:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
cd my-project
|
|
201
|
-
hives add-worker researcher
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
Crea `src/workers/researcher.worker.ts`:
|
|
205
|
-
|
|
206
|
-
```typescript
|
|
207
|
-
import { createWorker } from "@johpaz/hive-sdk";
|
|
208
|
-
|
|
209
|
-
export const researcherWorker = createWorker({
|
|
210
|
-
name: "researcher",
|
|
211
|
-
systemPrompt: `You are the ResearcherWorker specialist...`,
|
|
212
|
-
});
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
## AgentBus
|
|
218
|
-
|
|
219
|
-
Sistema de eventos singleton para comunicación entre agentes.
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
import { agentBus, getUnreadMessagesForWorker } from "@johpaz/hive-sdk";
|
|
223
|
-
|
|
224
|
-
// Publicar evento
|
|
225
|
-
agentBus.publish("worker:task_started", { taskId: "task-1" }, "worker-1");
|
|
226
|
-
|
|
227
|
-
// Suscribirse
|
|
228
|
-
const unsub = agentBus.subscribe("worker:task_completed", (data) => {
|
|
229
|
-
console.log("Task completed:", data);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// Unsubscribe
|
|
233
|
-
unsub();
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Métodos Helper
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
import {
|
|
240
|
-
getUnreadMessagesForWorker,
|
|
241
|
-
getProjectMessageHistory,
|
|
242
|
-
} from "@johpaz/hive-sdk";
|
|
243
|
-
|
|
244
|
-
const messages = getUnreadMessagesForWorker("worker-1");
|
|
245
|
-
const history = getProjectMessageHistory("project-1");
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## EventBus
|
|
251
|
-
|
|
252
|
-
EventBus global singleton (eventos del sistema).
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
import { eventBus } from "@johpaz/hive-sdk";
|
|
256
|
-
|
|
257
|
-
// Escuchar eventos
|
|
258
|
-
eventBus.on("agent:start", (data) => {
|
|
259
|
-
console.log("Agent started:", data);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Emitir eventos
|
|
263
|
-
eventBus.emit("agent:complete", { agentId: "a1", result: "ok" });
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
|
-
## Canvas Events
|
|
269
|
-
|
|
270
|
-
Eventos de actualización visual del canvas.
|
|
271
|
-
|
|
272
|
-
```typescript
|
|
273
|
-
import { emitCanvas, subscribeCanvas, unsubscribeCanvas } from "@johpaz/hive-sdk";
|
|
274
|
-
|
|
275
|
-
// Suscribirse a eventos canvas
|
|
276
|
-
const handler = (data: any) => console.log("Canvas:", data);
|
|
277
|
-
subscribeCanvas(handler);
|
|
278
|
-
|
|
279
|
-
// Emitir evento
|
|
280
|
-
emitCanvas("canvas:node_update", {
|
|
281
|
-
nodeId: "agent-1",
|
|
282
|
-
changes: { status: "thinking" },
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
// Desuscribirse
|
|
286
|
-
unsubscribeCanvas(handler);
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
### CanvasManager
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
import { CanvasManager } from "@johpaz/hive-sdk";
|
|
293
|
-
|
|
294
|
-
const canvas = new CanvasManager();
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
---
|
|
298
|
-
|
|
299
|
-
*Documentación Hive SDK v0.0.17*
|
package/docs/HIVE-HARNESS.md
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# Hive Harness — durable task execution
|
|
2
|
-
|
|
3
|
-
The `harness` module (`@johpaz/hive-sdk/harness`) is the SDK's durable-execution
|
|
4
|
-
layer: a HiveDB-backed job queue with crash recovery, checkpointable runs,
|
|
5
|
-
retry with backoff, idempotent submission, goal verification, and proof
|
|
6
|
-
packets. It's what lets a host app (a `hive-app`, or a production service like
|
|
7
|
-
Hive Cloud) survive a process restart mid-task without losing work or
|
|
8
|
-
double-executing a tool call.
|
|
9
|
-
|
|
10
|
-
It is deliberately **not** wired into the agent loop automatically, and it has
|
|
11
|
-
no built-in notion of "chat" vs "project task" vs any other app-specific job
|
|
12
|
-
type — job `type` and run `kind` are plain strings. The host app defines its
|
|
13
|
-
own vocabulary and registers executors for it. This is the same infrastructure
|
|
14
|
-
that powers `hive`'s durable-queue harness, generalized so any SDK consumer
|
|
15
|
-
can reuse it instead of re-implementing crash-safe job execution from scratch.
|
|
16
|
-
|
|
17
|
-
## Architecture
|
|
18
|
-
|
|
19
|
-
| Piece | File | Responsibility |
|
|
20
|
-
|---|---|---|
|
|
21
|
-
| `JobDoc` / `HarnessRunDoc` / `ProofPacketDoc` | `collections.ts` | HiveDB document shapes |
|
|
22
|
-
| `db-helpers` | `db-helpers.ts` | `nextId`, `updateDoc`, `findByAny` — primitives HiveDB's `Collection` doesn't provide directly |
|
|
23
|
-
| `job-store` | `job-store.ts` | Durable job persistence: claim/lease/complete/fail/retry, all via OCC |
|
|
24
|
-
| `run-store` | `run-store.ts` | Checkpoint + lease for a single durable run (messages, iteration/token counters, pending tool calls) |
|
|
25
|
-
| `durable-queue` | `durable-queue.ts` | `DurableLaneQueue` — FIFO+priority per lane, global concurrency cap, executor registry |
|
|
26
|
-
| `goal-verifier` | `goal-verifier.ts` | `verifyGoal()` — deterministic check tool or LLM verifier, single goal or a list of acceptance criteria |
|
|
27
|
-
| `run-epoch` | `run-epoch.ts` | Fixed-worker epoch fingerprint (provider/model/app-version/tool-catalog) |
|
|
28
|
-
| `proof-packet` | `proof-packet.ts` | Compressed evidence artifact for a completed run |
|
|
29
|
-
| `reconcile` | `reconcile.ts` | `reconcileOnBoot()` — crash repair + retention cap, call once at startup |
|
|
30
|
-
|
|
31
|
-
## Durable queue semantics
|
|
32
|
-
|
|
33
|
-
- **Lanes**: a lane (e.g. a session id, or `task:<id>`) runs at most one job
|
|
34
|
-
at a time, FIFO within the lane, ordered by `priority` then creation order.
|
|
35
|
-
- **Global concurrency**: `maxGlobalConcurrency` caps how many jobs run at
|
|
36
|
-
once across all lanes (default 4). Types listed in `nonRetryableTypes`
|
|
37
|
-
(default `["chat_turn"]`) bypass this cap — a busy batch of background jobs
|
|
38
|
-
must not make an interactive/user-facing job type stop responding.
|
|
39
|
-
- **Leases**: a claimed job gets a lease (default 30 min); the queue renews
|
|
40
|
-
it every 30s while executing. A lease that expires (crashed process) is
|
|
41
|
-
reclaimed to `pending` or marked `interrupted` once `attempts >=
|
|
42
|
-
max_attempts` — checked by `reconcileOnBoot()` at startup and by the
|
|
43
|
-
queue's periodic maintenance tick thereafter.
|
|
44
|
-
- **Executors**: register one per job type with `registerExecutor(type, fn)`.
|
|
45
|
-
An executor receives the `JobDoc`, an `AbortSignal` (fired on cancel or
|
|
46
|
-
`taskTimeoutMs`), and any live callbacks passed to `enqueue()`.
|
|
47
|
-
|
|
48
|
-
## Retry & backoff
|
|
49
|
-
|
|
50
|
-
Two independent retry mechanisms:
|
|
51
|
-
|
|
52
|
-
1. **Crash retries** (`attempts` / `max_attempts`) — bumped on every claim,
|
|
53
|
-
checked by `reclaimOrInterrupt` after a lease expires. This is about
|
|
54
|
-
*the process dying*, not the job failing logically.
|
|
55
|
-
2. **Logical-failure retries** (`retry_count` / `JobRetryPolicy`) — when an
|
|
56
|
-
executor returns `{ok: false, retryable: true}` (the default unless set
|
|
57
|
-
`false`), `failJobOrRetry` reschedules the job with exponential backoff +
|
|
58
|
-
jitter instead of failing it immediately:
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
delay = min(maxDelayMs, initialDelayMs * backoffMultiplier ** retryCount)
|
|
62
|
-
* (1 + jitter * random())
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Once `retryCount >= policy.maxRetries`, the job fails terminally. Types in
|
|
66
|
-
`nonRetryableTypes` never take this path — a failed interactive turn
|
|
67
|
-
should surface to the user immediately, not silently retry later.
|
|
68
|
-
|
|
69
|
-
## Idempotency
|
|
70
|
-
|
|
71
|
-
`createJob`/`enqueue` accept an optional `idempotency_key`. A repeated key
|
|
72
|
-
returns the existing job (whatever its status — pending, running, completed,
|
|
73
|
-
or terminally failed) instead of creating a duplicate, so a retried HTTP
|
|
74
|
-
request from a caller doesn't double-enqueue work.
|
|
75
|
-
|
|
76
|
-
## Goal verification & acceptance criteria
|
|
77
|
-
|
|
78
|
-
`verifyGoal()` answers "was this met" for a single goal or — when
|
|
79
|
-
`acceptance` criteria are supplied — for each criterion independently (its
|
|
80
|
-
own optional `checkTool`, or an LLM judgment against its own description).
|
|
81
|
-
The overall verdict is the conjunction of all criteria. The harness has no
|
|
82
|
-
built-in tool registry: pass a `runCheckTool` callback that resolves a
|
|
83
|
-
`checkTool` name to something the host app can actually execute.
|
|
84
|
-
|
|
85
|
-
## Proof packets
|
|
86
|
-
|
|
87
|
-
`buildProofPacket()` persists a compressed evidence artifact once a run
|
|
88
|
-
finishes: intended outcome, per-criterion results, checks run, evidence
|
|
89
|
-
snippets, known limits, and the run's fixed-worker epoch. Useful as an
|
|
90
|
-
audit trail without having to replay the full run transcript.
|
|
91
|
-
|
|
92
|
-
## Setup
|
|
93
|
-
|
|
94
|
-
```ts
|
|
95
|
-
import {
|
|
96
|
-
ensureHarnessIndexes,
|
|
97
|
-
reconcileOnBoot,
|
|
98
|
-
initDurableQueue,
|
|
99
|
-
registerExecutor,
|
|
100
|
-
getBootId,
|
|
101
|
-
} from "@johpaz/hive-sdk/harness";
|
|
102
|
-
|
|
103
|
-
await ensureHarnessIndexes(); // idempotent — safe every boot
|
|
104
|
-
await reconcileOnBoot(getBootId());
|
|
105
|
-
|
|
106
|
-
registerExecutor("my_job_type", async (job, signal) => {
|
|
107
|
-
// ... do the work, honoring `signal` for cancellation/timeout
|
|
108
|
-
return { ok: true, result: "done" };
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const queue = initDurableQueue({ maxGlobalConcurrency: 4 });
|
|
112
|
-
await queue.enqueue({ lane: "session-1", type: "my_job_type", run_id: "r1", payload: {} });
|
|
113
|
-
```
|
package/docs/INDEX.md
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
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, instalación, CLI, guía rápida |
|
|
8
|
-
| [API-AGENTS.md](./API-AGENTS.md) | createAgent, 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) | **Bun Workers**, createWorker, WorkerPool, AgentBus, EventBus, Canvas |
|
|
11
|
-
| [API-TOOLS-SKILLS-CHANNELS.md](./API-TOOLS-SKILLS-CHANNELS.md) | Tools, Skills, MCP, Gateway, Channels, Tool Runtime, Storage |
|
|
12
|
-
| [API-CONTEXT-COMPILER.md](./API-CONTEXT-COMPILER.md) | Context Compiler, Message History, Scratchpad, EthicsGuard, ACE |
|
|
13
|
-
| [TEMPLATE-HIVE-APP.md](./TEMPLATE-HIVE-APP.md) | **Template hive-app** — estructura, opciones, personalización |
|
|
14
|
-
| [HIVE-HARNESS.md](../docs/HIVE-HARNESS.md) | Posicionamiento: Hive como Agent Harness vertical |
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Guía de Inicio Rápido
|
|
19
|
-
|
|
20
|
-
### 1. Crear una app harness completa
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
hives create-app my-hive
|
|
24
|
-
cd my-hive
|
|
25
|
-
bun install
|
|
26
|
-
cp .env.example .env
|
|
27
|
-
bun run dev
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### 2. Crear Agente
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { createAgent, defineTool } from "@johpaz/hive-sdk";
|
|
34
|
-
|
|
35
|
-
const tool = defineTool({
|
|
36
|
-
name: "saludar",
|
|
37
|
-
description: "Saluda a alguien",
|
|
38
|
-
execute: async (args: { nombre: string }) => `¡Hola ${args.nombre}!`,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const agent = await createAgent({
|
|
42
|
-
name: "asistente",
|
|
43
|
-
provider: "openai",
|
|
44
|
-
model: "gpt-5.6-luna",
|
|
45
|
-
tools: [tool],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const respuesta = await agent.run("Saluda a Juan");
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### 3. Crear un Bun Worker
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
import { createWorker } from "@johpaz/hive-sdk";
|
|
55
|
-
|
|
56
|
-
const worker = createWorker({
|
|
57
|
-
name: "researcher",
|
|
58
|
-
systemPrompt: "You are a research specialist...",
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const result = await worker.run("Research quantum computing");
|
|
62
|
-
worker.terminate();
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 4. Ejecutar un Swarm (DAG)
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
import { DAGScheduler, TaskGraph } from "@johpaz/hive-sdk";
|
|
69
|
-
|
|
70
|
-
const graph = new TaskGraph([
|
|
71
|
-
{ id: "task1", agentId: "worker", name: "T1", taskDescription: "Tarea 1", deps: [] },
|
|
72
|
-
{ id: "task2", agentId: "worker", name: "T2", taskDescription: "Tarea 2", deps: ["task1"] },
|
|
73
|
-
]);
|
|
74
|
-
|
|
75
|
-
const result = await new DAGScheduler().execute(graph);
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### 5. Gateway + Canales
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { startGateway, ChannelManager, TelegramChannel } from "@johpaz/hive-sdk";
|
|
82
|
-
|
|
83
|
-
const server = await startGateway({ host: "127.0.0.1", port: 18790 });
|
|
84
|
-
|
|
85
|
-
const channels = new ChannelManager(config);
|
|
86
|
-
// channels.register("telegram", new TelegramChannel({ botToken: "..." }));
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## Estructura de Paquetes
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
packages/
|
|
95
|
-
├── core/ # @johpaz/hive-sdk
|
|
96
|
-
│ └── src/
|
|
97
|
-
│ ├── api/ # createAgent(), Agent interface
|
|
98
|
-
│ ├── agent/ # AgentLoop, ContextCompiler, ConversationStore
|
|
99
|
-
│ │ ├── providers/ # LLM providers (OpenAI, Anthropic, Gemini, Ollama)
|
|
100
|
-
│ │ └── tool-selector.ts, skill-selector.ts, playbook-selector.ts (BM25 sobre HiveDB)
|
|
101
|
-
│ ├── tools/ # 70+ built-in tools + ToolRegistry + ToolExecutor
|
|
102
|
-
│ ├── skills/ # SkillLoader, defineSkill()
|
|
103
|
-
│ ├── swarm/ # DAGScheduler, TaskGraph, WorkerPool
|
|
104
|
-
│ ├── workers/ # Bun Workers: createWorker, WorkerPool, agent.worker.ts
|
|
105
|
-
│ ├── gateway/ # HTTP/WebSocket server (Bun.serve)
|
|
106
|
-
│ ├── channels/ # Telegram, Discord, WhatsApp, Slack, Webchat
|
|
107
|
-
│ ├── mcp/ # MCPClientManager + transports (SSE, WS, STDIO)
|
|
108
|
-
│ ├── storage/ # HiveDB (colecciones + BM25)
|
|
109
|
-
│ ├── canvas/ # CanvasManager + A2UI emitter
|
|
110
|
-
│ ├── scheduler/ # CronScheduler + DAG execution
|
|
111
|
-
│ ├── tool-runtime/ # Bun Worker pool para ejecución paralela de tools
|
|
112
|
-
│ ├── ethics/ # EthicsGuard
|
|
113
|
-
│ ├── memory/ # Scratchpad
|
|
114
|
-
│ ├── config/ # loadConfig, loadEnv, getHiveDir
|
|
115
|
-
│ ├── utils/ # logger, toon, crypto, retry
|
|
116
|
-
│ └── index.ts # Public API barrel
|
|
117
|
-
│
|
|
118
|
-
└── cli/ # Hive CLI
|
|
119
|
-
└── src/
|
|
120
|
-
├── index.ts # Entry: hive <command>
|
|
121
|
-
└── commands/
|
|
122
|
-
├── init.ts
|
|
123
|
-
├── create-app.ts # Generar app harness completa
|
|
124
|
-
├── add-tool.ts # Generar boilerplate de tool
|
|
125
|
-
├── add-skill.ts # Generar boilerplate de skill
|
|
126
|
-
├── add-worker.ts # Generar Bun Worker
|
|
127
|
-
├── run.ts
|
|
128
|
-
├── test.ts
|
|
129
|
-
└── trace.ts
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## Conceptos Clave
|
|
135
|
-
|
|
136
|
-
### Agente
|
|
137
|
-
Unidad de ejecución con configuración, contexto y ciclo de ejecución.
|
|
138
|
-
|
|
139
|
-
### Tool
|
|
140
|
-
Función invocable por el agente. Definida con `defineTool()`, seleccionada por búsqueda BM25.
|
|
141
|
-
|
|
142
|
-
### Skill
|
|
143
|
-
Composición de tools con triggers semánticos. Definida con `defineSkill()`.
|
|
144
|
-
|
|
145
|
-
### Bun Worker
|
|
146
|
-
Thread aislado que ejecuta un agente con system prompt propio. Creado con `createWorker()`.
|
|
147
|
-
|
|
148
|
-
### WorkerPool
|
|
149
|
-
Gestiona múltiples Bun Workers para ejecución paralela de tareas.
|
|
150
|
-
|
|
151
|
-
### Swarm (DAG)
|
|
152
|
-
Ejecución paralela de múltiples agentes con dependencias. Topological sort automático.
|
|
153
|
-
|
|
154
|
-
### Gateway
|
|
155
|
-
Servidor HTTP/WebSocket que expone el agente como API.
|
|
156
|
-
|
|
157
|
-
### Channel
|
|
158
|
-
Integración con plataformas de mensajería (Telegram, Discord, WhatsApp, Slack, Webchat).
|
|
159
|
-
|
|
160
|
-
### MCP
|
|
161
|
-
Model Context Protocol — herramientas externas via STDIO/SSE/WebSocket.
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## Variables de Entorno
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
HIVE_DATA_DIR=./data # Directorio de datos
|
|
169
|
-
HIVE_HOST=127.0.0.1 # Gateway host
|
|
170
|
-
HIVE_PORT=18790 # Gateway port
|
|
171
|
-
OPENAI_API_KEY=sk-... # OpenAI
|
|
172
|
-
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
|
|
173
|
-
LOG_LEVEL=info # debug | info | warn | error
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
## Tests
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
# Tests unitarios (paralelo)
|
|
182
|
-
bun test
|
|
183
|
-
|
|
184
|
-
# Tests con timeout extendido
|
|
185
|
-
bun test --timeout 60000
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
*Documentación Hive SDK v0.0.17*
|