@oni.bot/core 0.8.0 → 1.0.1
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 +15 -0
- package/README.md +59 -373
- package/dist/checkpointers/sqlite.d.ts.map +1 -1
- package/dist/checkpointers/sqlite.js +23 -8
- package/dist/checkpointers/sqlite.js.map +1 -1
- package/dist/cli/build.d.ts +11 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +61 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/dev.d.ts +5 -0
- package/dist/cli/dev.d.ts.map +1 -0
- package/dist/cli/dev.js +54 -0
- package/dist/cli/dev.js.map +1 -0
- package/dist/cli/index.js +16 -27
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +18 -1
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/inspect.d.ts +5 -0
- package/dist/cli/inspect.d.ts.map +1 -0
- package/dist/cli/inspect.js +85 -0
- package/dist/cli/inspect.js.map +1 -0
- package/dist/cli/router.d.ts +14 -0
- package/dist/cli/router.d.ts.map +1 -0
- package/dist/cli/router.js +107 -0
- package/dist/cli/router.js.map +1 -0
- package/dist/cli/run.d.ts +5 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +53 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/templates.d.ts +1 -0
- package/dist/cli/templates.d.ts.map +1 -1
- package/dist/cli/templates.js +106 -66
- package/dist/cli/templates.js.map +1 -1
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +29 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +37 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +180 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +74 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +5 -0
- package/dist/config/types.js.map +1 -0
- package/dist/coordination/pubsub.d.ts +4 -0
- package/dist/coordination/pubsub.d.ts.map +1 -1
- package/dist/coordination/pubsub.js +8 -0
- package/dist/coordination/pubsub.js.map +1 -1
- package/dist/coordination/request-reply.d.ts +3 -1
- package/dist/coordination/request-reply.d.ts.map +1 -1
- package/dist/coordination/request-reply.js +11 -2
- package/dist/coordination/request-reply.js.map +1 -1
- package/dist/errors.d.ts +7 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -3
- package/dist/errors.js.map +1 -1
- package/dist/events/bridge.d.ts +17 -0
- package/dist/events/bridge.d.ts.map +1 -0
- package/dist/events/bridge.js +67 -0
- package/dist/events/bridge.js.map +1 -0
- package/dist/events/bus.d.ts +9 -0
- package/dist/events/bus.d.ts.map +1 -1
- package/dist/events/bus.js +39 -4
- package/dist/events/bus.js.map +1 -1
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -1
- package/dist/events/types.d.ts +123 -1
- package/dist/events/types.d.ts.map +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +16 -8
- package/dist/graph.js.map +1 -1
- package/dist/guardrails/types.d.ts +1 -1
- package/dist/guardrails/types.d.ts.map +1 -1
- package/dist/harness/agent-loop.d.ts.map +1 -1
- package/dist/harness/agent-loop.js +226 -29
- package/dist/harness/agent-loop.js.map +1 -1
- package/dist/harness/context-compactor.d.ts +21 -2
- package/dist/harness/context-compactor.d.ts.map +1 -1
- package/dist/harness/context-compactor.js +45 -6
- package/dist/harness/context-compactor.js.map +1 -1
- package/dist/harness/hooks-engine.d.ts +7 -1
- package/dist/harness/hooks-engine.d.ts.map +1 -1
- package/dist/harness/hooks-engine.js.map +1 -1
- package/dist/harness/index.d.ts +3 -2
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +2 -0
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/skill-loader.d.ts +14 -1
- package/dist/harness/skill-loader.d.ts.map +1 -1
- package/dist/harness/skill-loader.js +33 -3
- package/dist/harness/skill-loader.js.map +1 -1
- package/dist/harness/types.d.ts +24 -2
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/validate-args.d.ts +16 -0
- package/dist/harness/validate-args.d.ts.map +1 -0
- package/dist/harness/validate-args.js +132 -0
- package/dist/harness/validate-args.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/timeout.d.ts +2 -0
- package/dist/internal/timeout.d.ts.map +1 -0
- package/dist/internal/timeout.js +16 -0
- package/dist/internal/timeout.js.map +1 -0
- package/dist/lsp/client.d.ts +70 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +421 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +77 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +183 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/servers.d.ts +48 -0
- package/dist/lsp/servers.d.ts.map +1 -0
- package/dist/lsp/servers.js +108 -0
- package/dist/lsp/servers.js.map +1 -0
- package/dist/lsp/types.d.ts +142 -0
- package/dist/lsp/types.d.ts.map +1 -0
- package/dist/lsp/types.js +16 -0
- package/dist/lsp/types.js.map +1 -0
- package/dist/mcp/client.d.ts +56 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +170 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/convert.d.ts +26 -0
- package/dist/mcp/convert.d.ts.map +1 -0
- package/dist/mcp/convert.js +56 -0
- package/dist/mcp/convert.js.map +1 -0
- package/dist/mcp/index.d.ts +21 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/transport.d.ts +56 -0
- package/dist/mcp/transport.d.ts.map +1 -0
- package/dist/mcp/transport.js +204 -0
- package/dist/mcp/transport.js.map +1 -0
- package/dist/mcp/types.d.ts +96 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +11 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/models/anthropic.d.ts.map +1 -1
- package/dist/models/anthropic.js +78 -41
- package/dist/models/anthropic.js.map +1 -1
- package/dist/models/google.d.ts.map +1 -1
- package/dist/models/google.js +47 -46
- package/dist/models/google.js.map +1 -1
- package/dist/models/http-error.d.ts +16 -0
- package/dist/models/http-error.d.ts.map +1 -0
- package/dist/models/http-error.js +67 -0
- package/dist/models/http-error.js.map +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -1
- package/dist/models/ollama.d.ts.map +1 -1
- package/dist/models/ollama.js +4 -3
- package/dist/models/ollama.js.map +1 -1
- package/dist/models/openai.d.ts.map +1 -1
- package/dist/models/openai.js +36 -44
- package/dist/models/openai.js.map +1 -1
- package/dist/models/openrouter.d.ts +13 -0
- package/dist/models/openrouter.d.ts.map +1 -1
- package/dist/models/openrouter.js +86 -47
- package/dist/models/openrouter.js.map +1 -1
- package/dist/models/sse.d.ts +9 -0
- package/dist/models/sse.d.ts.map +1 -0
- package/dist/models/sse.js +45 -0
- package/dist/models/sse.js.map +1 -0
- package/dist/models/types.d.ts +10 -0
- package/dist/models/types.d.ts.map +1 -1
- package/dist/pregel.d.ts +4 -0
- package/dist/pregel.d.ts.map +1 -1
- package/dist/pregel.js +121 -54
- package/dist/pregel.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +10 -3
- package/dist/retry.js.map +1 -1
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +17 -0
- package/dist/store/index.js.map +1 -1
- package/dist/streaming.d.ts +4 -1
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +21 -7
- package/dist/streaming.js.map +1 -1
- package/dist/swarm/graph.d.ts +81 -2
- package/dist/swarm/graph.d.ts.map +1 -1
- package/dist/swarm/graph.js +517 -32
- package/dist/swarm/graph.js.map +1 -1
- package/dist/swarm/index.d.ts +10 -2
- package/dist/swarm/index.d.ts.map +1 -1
- package/dist/swarm/index.js +6 -1
- package/dist/swarm/index.js.map +1 -1
- package/dist/swarm/mermaid.d.ts +10 -0
- package/dist/swarm/mermaid.d.ts.map +1 -0
- package/dist/swarm/mermaid.js +64 -0
- package/dist/swarm/mermaid.js.map +1 -0
- package/dist/swarm/pool.d.ts +9 -1
- package/dist/swarm/pool.d.ts.map +1 -1
- package/dist/swarm/pool.js +58 -10
- package/dist/swarm/pool.js.map +1 -1
- package/dist/swarm/registry.d.ts +11 -1
- package/dist/swarm/registry.d.ts.map +1 -1
- package/dist/swarm/registry.js +17 -3
- package/dist/swarm/registry.js.map +1 -1
- package/dist/swarm/scaling.d.ts +95 -0
- package/dist/swarm/scaling.d.ts.map +1 -0
- package/dist/swarm/scaling.js +214 -0
- package/dist/swarm/scaling.js.map +1 -0
- package/dist/swarm/snapshot.d.ts +51 -0
- package/dist/swarm/snapshot.d.ts.map +1 -0
- package/dist/swarm/snapshot.js +115 -0
- package/dist/swarm/snapshot.js.map +1 -0
- package/dist/swarm/supervisor.d.ts.map +1 -1
- package/dist/swarm/supervisor.js +82 -0
- package/dist/swarm/supervisor.js.map +1 -1
- package/dist/swarm/tracer.d.ts +57 -0
- package/dist/swarm/tracer.d.ts.map +1 -0
- package/dist/swarm/tracer.js +138 -0
- package/dist/swarm/tracer.js.map +1 -0
- package/dist/swarm/types.d.ts +23 -1
- package/dist/swarm/types.d.ts.map +1 -1
- package/dist/swarm/types.js.map +1 -1
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/package.json +160 -141
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ All notable changes to @oni.bot/core are documented here.
|
|
|
5
5
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.0] — 2026-03-13
|
|
9
|
+
|
|
10
|
+
### Breaking Changes
|
|
11
|
+
- `oni-code` AI coding assistant extracted to `@oni.bot/code` (separate package)
|
|
12
|
+
- `sentinel` code analysis engine extracted to `@oni.bot/sentinel` (separate package)
|
|
13
|
+
- `oni` and `oni-code` CLI binaries removed from this package (install `@oni.bot/code` for the CLI)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- `./config` sub-module export (`@oni.bot/core/config`) — JSONC config loader with env var substitution and hierarchical merge
|
|
17
|
+
- `"sideEffects": false` — enables full tree shaking in bundlers
|
|
18
|
+
|
|
19
|
+
### Framework
|
|
20
|
+
- 5 model adapters (anthropic, openai, openrouter, google, ollama) — zero runtime dependencies
|
|
21
|
+
- 21 total exports: root + 20 named subpaths
|
|
22
|
+
|
|
8
23
|
## [0.7.0] - 2026-03-08
|
|
9
24
|
|
|
10
25
|
### Added
|
package/README.md
CHANGED
|
@@ -2,422 +2,108 @@
|
|
|
2
2
|
<strong>@oni.bot/core</strong>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<h3 align="center">The graph execution engine for agent swarms.</h3>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
Production-grade orchestration with zero dependencies.
|
|
9
|
-
</p>
|
|
5
|
+
<h3 align="center">The graph execution engine for production agent swarms.</h3>
|
|
10
6
|
|
|
11
7
|
<p align="center">
|
|
12
8
|
<a href="https://www.npmjs.com/package/@oni.bot/core"><img src="https://img.shields.io/npm/v/@oni.bot/core.svg" alt="npm version" /></a>
|
|
13
|
-
<a href="https://github.com/oni-bot/core/actions"><img src="https://img.shields.io/github/actions/workflow/status/oni-bot/core/ci.yml?label=tests" alt="tests" /></a>
|
|
14
|
-
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="zero dependencies" />
|
|
15
|
-
<img src="https://img.shields.io/badge/TypeScript-strict-blue" alt="TypeScript strict" />
|
|
16
9
|
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License" /></a>
|
|
10
|
+
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="zero dependencies" />
|
|
17
11
|
</p>
|
|
18
12
|
|
|
19
13
|
---
|
|
20
14
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
Most agent frameworks make the easy things easy and the hard things impossible. You can spin up a chatbot in ten lines, but the moment you need four agents coordinating with retries, circuit breakers, and human approval gates, you're writing glue code from scratch.
|
|
24
|
-
|
|
25
|
-
ONI was built for the hard things:
|
|
26
|
-
|
|
27
|
-
- **Multi-agent orchestration is a first-class primitive.** Seven swarm templates ship out of the box -- hierarchical, fan-out, pipeline, peer-network, map-reduce, debate, and hierarchical-mesh. Pick one, plug in your agents, and go.
|
|
28
|
-
- **Zero runtime dependencies.** The entire engine is self-contained TypeScript. No framework lock-in, no transitive supply-chain risk. Runs in Node, serverless functions, and edge runtimes without adaptation.
|
|
29
|
-
- **Production-grade from day one.** Circuit breakers, node timeouts, dead letter queues, retry with exponential backoff, OpenTelemetry tracing, and checkpointing with time-travel debugging. These aren't afterthoughts -- they're wired into the execution engine.
|
|
30
|
-
- **Type-safe end to end.** Full generics on state, channels, and node returns. TypeScript strict mode. If your graph compiles, it runs.
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## Quick Start
|
|
15
|
+
## Install
|
|
35
16
|
|
|
36
17
|
```bash
|
|
37
18
|
npm install @oni.bot/core
|
|
38
19
|
```
|
|
39
20
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type State = { query: string; answer: string; log: string[] };
|
|
44
|
-
|
|
45
|
-
const graph = new StateGraph<State>({
|
|
46
|
-
channels: {
|
|
47
|
-
query: lastValue(() => ""),
|
|
48
|
-
answer: lastValue(() => ""),
|
|
49
|
-
log: appendList(() => []),
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
graph.addNode("think", async (state) => {
|
|
54
|
-
return { answer: `Processed: ${state.query}`, log: ["think ran"] };
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
graph.addEdge(START, "think");
|
|
58
|
-
graph.addEdge("think", END);
|
|
59
|
-
|
|
60
|
-
const app = graph.compile();
|
|
61
|
-
const result = await app.invoke({ query: "What is ONI?" });
|
|
62
|
-
console.log(result.answer); // "Processed: What is ONI?"
|
|
63
|
-
```
|
|
21
|
+
- **Zero runtime dependencies.** Self-contained TypeScript. No transitive supply-chain risk. Runs in Node.js 18+, serverless functions, and edge runtimes without adaptation.
|
|
22
|
+
- **5 model adapters via raw HTTP.** Anthropic, OpenAI, OpenRouter, Google, and Ollama — no vendor SDKs required.
|
|
23
|
+
- **21 exports.** Root package plus 20 named subpaths for precise tree shaking.
|
|
64
24
|
|
|
65
25
|
---
|
|
66
26
|
|
|
67
|
-
##
|
|
68
|
-
|
|
69
|
-
Build coordinated agent teams with a single function call:
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
import { SwarmGraph } from "@oni.bot/core/swarm";
|
|
73
|
-
import { defineAgent } from "@oni.bot/core/agents";
|
|
74
|
-
import { anthropic } from "@oni.bot/core/models";
|
|
75
|
-
|
|
76
|
-
const researcher = defineAgent({
|
|
77
|
-
name: "researcher",
|
|
78
|
-
model: anthropic("claude-sonnet-4-6"),
|
|
79
|
-
systemPrompt: "You research topics thoroughly.",
|
|
80
|
-
tools: [webSearch],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const writer = defineAgent({
|
|
84
|
-
name: "writer",
|
|
85
|
-
model: anthropic("claude-sonnet-4-6"),
|
|
86
|
-
systemPrompt: "You write compelling content from research notes.",
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const swarm = SwarmGraph.hierarchical({
|
|
90
|
-
supervisor: { model: anthropic("claude-sonnet-4-6"), strategy: "llm", maxRounds: 10 },
|
|
91
|
-
agents: [researcher, writer],
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const app = swarm.compile();
|
|
95
|
-
const result = await app.invoke({ task: "Write a technical brief on quantum error correction" });
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
No boilerplate routing, no manual state plumbing. The supervisor decides which agent runs next, results flow back through typed channels, and the swarm terminates when the task is complete.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## Features
|
|
103
|
-
|
|
104
|
-
| Category | Feature | Description |
|
|
105
|
-
|---|---|---|
|
|
106
|
-
| **Engine** | Pregel execution | Superstep-parallel graph engine with deterministic state merging |
|
|
107
|
-
| | Typed channels | `lastValue`, `appendList`, `mergeObject`, `ephemeralValue` reducers |
|
|
108
|
-
| | Command routing | State update + routing in a single return value |
|
|
109
|
-
| | Send API | Dynamic fan-out to nodes with per-instance payloads |
|
|
110
|
-
| | Subgraphs | Nested compiled graphs with `Command.PARENT` state bridging |
|
|
111
|
-
| **Swarm** | 7 templates | Hierarchical, fan-out, pipeline, peer-network, map-reduce, debate, mesh |
|
|
112
|
-
| | Supervisor | LLM-based or rule-based routing strategies |
|
|
113
|
-
| | Handoff | Agent-to-agent delegation with context transfer |
|
|
114
|
-
| | Coordination | `RequestReplyBroker`, `PubSub` for inter-agent messaging |
|
|
115
|
-
| **Models** | 5 LLM adapters | Anthropic, OpenAI, Google, Ollama, OpenRouter |
|
|
116
|
-
| | Unified interface | `ONIModel` with chat, streaming, and tool calling |
|
|
117
|
-
| | Mock model | Deterministic test doubles with call history |
|
|
118
|
-
| **Streaming** | 5 modes | `values`, `updates`, `debug`, `messages`, `custom` |
|
|
119
|
-
| | Token streaming | Character-level LLM output via `messages` mode |
|
|
120
|
-
| | Custom events | Emit named events from any node via `StreamWriter` |
|
|
121
|
-
| | Multi-mode | Subscribe to multiple stream modes simultaneously |
|
|
122
|
-
| **Reliability** | Circuit breakers | Automatic failure detection with configurable thresholds |
|
|
123
|
-
| | Node timeouts | Per-node deadline enforcement |
|
|
124
|
-
| | Dead letter queues | Capture and inspect failed executions |
|
|
125
|
-
| | Retry + backoff | Configurable per-node retry with exponential backoff |
|
|
126
|
-
| **Persistence** | Checkpointing | Memory, SQLite, PostgreSQL backends |
|
|
127
|
-
| | Time travel | `getHistory`, `getStateAt`, `forkFrom` |
|
|
128
|
-
| | Cross-thread store | Namespaced KV with semantic search for agent memory |
|
|
129
|
-
| **HITL** | Interrupts | `interrupt()`, `getUserInput()`, `getUserApproval()` |
|
|
130
|
-
| | Session management | Typed resume values, multi-step approval flows |
|
|
131
|
-
| **Guardrails** | Budget tracking | Token and cost limits with automatic enforcement |
|
|
132
|
-
| | Content filters | PII detection, topic filtering, custom validators |
|
|
133
|
-
| | Permissions | Per-tool permission checks with audit logging |
|
|
134
|
-
| | Audit log | Structured logging of all guardrail decisions |
|
|
135
|
-
| **Observability** | OpenTelemetry | Zero-dep adapter -- bring your own tracer |
|
|
136
|
-
| | Graph inspection | Topology descriptors, Mermaid diagrams, cycle detection |
|
|
137
|
-
| **Testing** | `mockModel()` | Deterministic model stubs with call history tracking |
|
|
138
|
-
| | `assertGraph()` | Structural assertions on graph topology |
|
|
139
|
-
| | `createTestHarness()` | Pre-wired test runner with auto-checkpointing |
|
|
140
|
-
| **API Styles** | Builder pattern | `StateGraph` + `addNode` + `addEdge` + `compile` |
|
|
141
|
-
| | Functional | `task()`, `entrypoint()`, `pipe()`, `branch()` |
|
|
142
|
-
| | Prebuilt | `createReactAgent()`, `defineAgent()` |
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## Swarm Templates
|
|
147
|
-
|
|
148
|
-
| Template | Pattern | When to use it |
|
|
149
|
-
|---|---|---|
|
|
150
|
-
| `SwarmGraph.hierarchical()` | Supervisor routes to workers | General multi-agent tasks with centralized control |
|
|
151
|
-
| `SwarmGraph.fanOut()` | Parallel execution + aggregation | Independent subtasks that can run concurrently |
|
|
152
|
-
| `SwarmGraph.pipeline()` | Sequential A -> B -> C chain | Ordered processing stages (ETL, content pipelines) |
|
|
153
|
-
| `SwarmGraph.peerNetwork()` | Dynamic peer-to-peer handoff | Agents self-organize based on capabilities |
|
|
154
|
-
| `SwarmGraph.mapReduce()` | Split -> Pool -> Reduce | Distributing N items across a worker pool |
|
|
155
|
-
| `SwarmGraph.debate()` | Judge -> Debaters -> Consensus | Multi-perspective reasoning, red-teaming |
|
|
156
|
-
| `SwarmGraph.hierarchicalMesh()` | Coordinator -> Team subgraphs | Nested teams with inter-team coordination |
|
|
157
|
-
|
|
158
|
-
Each template handles routing, error recovery, and termination automatically. See `examples/swarm/` for runnable examples.
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## Architecture
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
@oni.bot/core v0.7.0
|
|
166
|
-
|
|
167
|
-
+--------------------------+
|
|
168
|
-
| Your Application |
|
|
169
|
-
+--------------------------+
|
|
170
|
-
|
|
|
171
|
-
+--------------------+--------------------+
|
|
172
|
-
| | |
|
|
173
|
-
defineAgent() StateGraph SwarmGraph
|
|
174
|
-
(single agent) (custom graph) (7 templates)
|
|
175
|
-
| | |
|
|
176
|
-
+--------------------+--------------------+
|
|
177
|
-
|
|
|
178
|
-
+-----------+-----------+
|
|
179
|
-
| ONIPregelRunner |
|
|
180
|
-
| (execution engine) |
|
|
181
|
-
+-----------+-----------+
|
|
182
|
-
|
|
|
183
|
-
+----------+----------+-------+-------+----------+----------+
|
|
184
|
-
| | | | | |
|
|
185
|
-
Channels Streaming Checkpoint Circuit Runtime Telemetry
|
|
186
|
-
(reducers) (5 modes) (3 backends) Breaker Context (OTel)
|
|
187
|
-
+ Retry (AsyncLocal)
|
|
188
|
-
+ DLQ
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
Entry points at every level of abstraction:
|
|
192
|
-
|
|
193
|
-
- **`ONIModel`** -- Call an LLM directly
|
|
194
|
-
- **`defineAgent()`** -- Single agent with tools and system prompt
|
|
195
|
-
- **`StateGraph`** -- Custom graph with full control over nodes and edges
|
|
196
|
-
- **`SwarmGraph`** -- Multi-agent orchestration from templates
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Sub-module Imports
|
|
201
|
-
|
|
202
|
-
Tree-shakeable sub-module imports for bundle optimization:
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
import { StateGraph, START, END } from "@oni.bot/core"; // Core engine
|
|
206
|
-
import { createReactAgent } from "@oni.bot/core/prebuilt"; // Prebuilt agents
|
|
207
|
-
import { SwarmGraph } from "@oni.bot/core/swarm"; // Swarm templates
|
|
208
|
-
import { interrupt } from "@oni.bot/core/hitl"; // Human-in-the-loop
|
|
209
|
-
import { InMemoryStore } from "@oni.bot/core/store"; // Cross-thread store
|
|
210
|
-
import { messagesChannel } from "@oni.bot/core/messages"; // Message handling
|
|
211
|
-
import { SqliteCheckpointer } from "@oni.bot/core/checkpointers";// Persistence
|
|
212
|
-
import { entrypoint, task } from "@oni.bot/core/functional"; // Functional API
|
|
213
|
-
import { buildGraphDescriptor } from "@oni.bot/core/inspect"; // Graph inspection
|
|
214
|
-
import { emitToken } from "@oni.bot/core/streaming"; // Token streaming
|
|
215
|
-
import { anthropic, openai } from "@oni.bot/core/models"; // LLM adapters
|
|
216
|
-
import { defineAgent } from "@oni.bot/core/agents"; // Agent builder
|
|
217
|
-
import { RequestReplyBroker } from "@oni.bot/core/coordination"; // Agent messaging
|
|
218
|
-
import { BudgetTracker } from "@oni.bot/core/guardrails"; // Safety controls
|
|
219
|
-
import { defineTool } from "@oni.bot/core/tools"; // Tool definitions
|
|
220
|
-
import { mockModel } from "@oni.bot/core/testing"; // Test utilities
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
16 entry points. Import only what you use.
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Production Features
|
|
228
|
-
|
|
229
|
-
### Circuit Breakers
|
|
230
|
-
|
|
231
|
-
```ts
|
|
232
|
-
const app = graph.compile({
|
|
233
|
-
circuitBreaker: { threshold: 5, resetAfter: 30_000 },
|
|
234
|
-
});
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
After 5 consecutive failures, the circuit opens and fast-fails all requests. After 30 seconds, it transitions to half-open and lets one request through to test recovery.
|
|
238
|
-
|
|
239
|
-
### Node Timeouts
|
|
27
|
+
## Quick Start
|
|
240
28
|
|
|
241
29
|
```ts
|
|
242
|
-
|
|
243
|
-
```
|
|
30
|
+
import { StateGraph, START, END, lastValue, anthropic } from "@oni.bot/core";
|
|
244
31
|
|
|
245
|
-
|
|
32
|
+
type State = {
|
|
33
|
+
question: string;
|
|
34
|
+
answer: string;
|
|
35
|
+
};
|
|
246
36
|
|
|
247
|
-
|
|
37
|
+
const model = anthropic("claude-sonnet-4-6");
|
|
248
38
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
39
|
+
const graph = new StateGraph<State>({
|
|
40
|
+
channels: {
|
|
41
|
+
question: lastValue<string>(() => ""),
|
|
42
|
+
answer: lastValue<string>(() => ""),
|
|
43
|
+
},
|
|
252
44
|
});
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### Dead Letter Queue
|
|
256
|
-
|
|
257
|
-
```ts
|
|
258
|
-
const dlq = new DeadLetterQueue();
|
|
259
|
-
const app = graph.compile({ dlq });
|
|
260
|
-
|
|
261
|
-
// Later: inspect failures
|
|
262
|
-
const failures = dlq.list();
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### OpenTelemetry Tracing
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
import { ONITracer } from "@oni.bot/core";
|
|
269
|
-
import { trace } from "@opentelemetry/api";
|
|
270
|
-
|
|
271
|
-
const tracer = new ONITracer(trace.getTracer("my-app"));
|
|
272
|
-
const app = graph.compile({ tracer });
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
Zero-dep adapter that wraps any OpenTelemetry-compatible tracer. Emits spans for graph execution, node runs, tool calls, model invocations, and checkpoint operations.
|
|
276
|
-
|
|
277
|
-
### Checkpointing + Time Travel
|
|
278
|
-
|
|
279
|
-
```ts
|
|
280
|
-
import { SqliteCheckpointer } from "@oni.bot/core/checkpointers";
|
|
281
|
-
|
|
282
|
-
const checkpointer = new SqliteCheckpointer("./state.db");
|
|
283
|
-
const app = graph.compile({ checkpointer });
|
|
284
|
-
|
|
285
|
-
// Resume from any point
|
|
286
|
-
const history = await app.getHistory("thread-1");
|
|
287
|
-
const forked = await app.forkFrom("thread-1", history[2].checkpoint);
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
Three built-in backends: `MemoryCheckpointer` (dev), `SqliteCheckpointer` (single-node), `PostgresCheckpointer` (distributed). Or implement `ONICheckpointer` for your own.
|
|
291
45
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
import { interrupt, getUserApproval } from "@oni.bot/core/hitl";
|
|
298
|
-
|
|
299
|
-
graph.addNode("review", async (state) => {
|
|
300
|
-
const approved = await getUserApproval("Publish this draft?", {
|
|
301
|
-
payload: state.draft,
|
|
46
|
+
graph.addNode("answer", async (state) => {
|
|
47
|
+
const response = await model.chat({
|
|
48
|
+
messages: [{ role: "user", content: state.question }],
|
|
302
49
|
});
|
|
303
|
-
|
|
304
|
-
return { status: "published" };
|
|
50
|
+
return { answer: response.content as string };
|
|
305
51
|
});
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
Execution pauses, the interrupt is surfaced to your application, and the graph resumes exactly where it left off when the user responds.
|
|
309
|
-
|
|
310
|
-
---
|
|
311
52
|
|
|
312
|
-
|
|
53
|
+
graph.addEdge(START, "answer");
|
|
54
|
+
graph.addEdge("answer", END);
|
|
313
55
|
|
|
314
|
-
|
|
315
|
-
// Single mode
|
|
316
|
-
for await (const event of app.stream(input, { streamMode: "updates" })) {
|
|
317
|
-
console.log(event.node, event.data);
|
|
318
|
-
}
|
|
56
|
+
const app = graph.compile();
|
|
319
57
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
58
|
+
for await (const chunk of app.stream(
|
|
59
|
+
{ question: "What is a Pregel execution model?" },
|
|
60
|
+
{ streamMode: "values" },
|
|
61
|
+
)) {
|
|
62
|
+
console.log(chunk.answer);
|
|
325
63
|
}
|
|
326
|
-
|
|
327
|
-
// Custom events from inside a node
|
|
328
|
-
import { getStreamWriter } from "@oni.bot/core";
|
|
329
|
-
|
|
330
|
-
graph.addNode("agent", async (state) => {
|
|
331
|
-
const writer = getStreamWriter();
|
|
332
|
-
writer.emit("progress", { step: 1, message: "Searching..." });
|
|
333
|
-
// ...
|
|
334
|
-
});
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
---
|
|
338
|
-
|
|
339
|
-
## Functional API
|
|
340
|
-
|
|
341
|
-
For simpler use cases, skip the builder pattern entirely:
|
|
342
|
-
|
|
343
|
-
```ts
|
|
344
|
-
import { entrypoint, task } from "@oni.bot/core/functional";
|
|
345
|
-
import { lastValue } from "@oni.bot/core";
|
|
346
|
-
|
|
347
|
-
const summarize = task("summarize", async (text: string) => {
|
|
348
|
-
return await llm.chat({ messages: [{ role: "user", content: `Summarize: ${text}` }] });
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
const app = entrypoint(
|
|
352
|
-
{ channels: { query: lastValue(() => ""), answer: lastValue(() => "") } },
|
|
353
|
-
async (state) => ({ answer: await summarize(state.query) }),
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
const result = await app.invoke({ query: "Explain quantum computing" });
|
|
357
64
|
```
|
|
358
65
|
|
|
359
66
|
---
|
|
360
67
|
|
|
361
|
-
##
|
|
68
|
+
## Sub-modules
|
|
362
69
|
|
|
363
|
-
|
|
364
|
-
import { mockModel, assertGraph, createTestHarness } from "@oni.bot/core/testing";
|
|
70
|
+
21 entry points — import only what you use.
|
|
365
71
|
|
|
366
|
-
|
|
367
|
-
const model = mockModel([
|
|
368
|
-
{ role: "assistant", content: "Hello!" },
|
|
369
|
-
{ role: "assistant", content: "Goodbye!", toolCalls: [{ id: "1", name: "search", args: {} }] },
|
|
370
|
-
]);
|
|
371
|
-
|
|
372
|
-
// Structural graph assertions
|
|
373
|
-
assertGraph(graph, {
|
|
374
|
-
hasNode: ["agent", "tools"],
|
|
375
|
-
hasEdge: [["__start__", "agent"]],
|
|
376
|
-
nodeCount: 2,
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
// Pre-wired test harness
|
|
380
|
-
const harness = createTestHarness(graph);
|
|
381
|
-
const result = await harness.invoke({ query: "test" });
|
|
382
|
-
const events = await harness.collectStream({ query: "test" }, "updates");
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
---
|
|
386
|
-
|
|
387
|
-
## Documentation
|
|
388
|
-
|
|
389
|
-
| Resource | Description |
|
|
72
|
+
| Subpath | Description |
|
|
390
73
|
|---|---|
|
|
391
|
-
|
|
|
392
|
-
|
|
|
393
|
-
|
|
|
74
|
+
| `@oni.bot/core` | Core engine: `StateGraph`, `START`, `END`, channels, `Command`, `Send` |
|
|
75
|
+
| `@oni.bot/core/prebuilt` | Prebuilt agents: `createReactAgent`, `defineAgent` |
|
|
76
|
+
| `@oni.bot/core/swarm` | Swarm templates: `SwarmGraph` (hierarchical, fan-out, pipeline, peer-network, map-reduce, debate, mesh) |
|
|
77
|
+
| `@oni.bot/core/hitl` | Human-in-the-loop: `interrupt`, `getUserInput`, `getUserApproval` |
|
|
78
|
+
| `@oni.bot/core/store` | Cross-thread KV store: `InMemoryStore`, `BaseStore`, `NamespacedStore` |
|
|
79
|
+
| `@oni.bot/core/messages` | Message channel primitives: `messagesChannel`, `MessageAnnotation` |
|
|
80
|
+
| `@oni.bot/core/checkpointers` | Persistence backends: `MemoryCheckpointer`, `SqliteCheckpointer` |
|
|
81
|
+
| `@oni.bot/core/functional` | Functional API: `task`, `entrypoint`, `pipe`, `branch` |
|
|
82
|
+
| `@oni.bot/core/inspect` | Graph inspection: `buildGraphDescriptor`, `toMermaid`, cycle detection |
|
|
83
|
+
| `@oni.bot/core/streaming` | Token streaming: `emitToken`, `getStreamWriter`, `StreamWriter` |
|
|
84
|
+
| `@oni.bot/core/models` | LLM adapters: `anthropic`, `openai`, `openrouter`, `google`, `ollama` |
|
|
85
|
+
| `@oni.bot/core/tools` | Tool definition: `defineTool`, `ToolSchema`, `ToolResult` |
|
|
86
|
+
| `@oni.bot/core/agents` | Agent builder: `defineAgent`, `AgentDefinition` |
|
|
87
|
+
| `@oni.bot/core/coordination` | Inter-agent messaging: `RequestReplyBroker`, `PubSub` |
|
|
88
|
+
| `@oni.bot/core/events` | Event bus: `EventBus`, 10 lifecycle event types |
|
|
89
|
+
| `@oni.bot/core/guardrails` | Budget and safety: `BudgetTracker`, `ContentFilter`, `PermissionGuard` |
|
|
90
|
+
| `@oni.bot/core/testing` | Test utilities: `mockModel`, `assertGraph`, `createTestHarness` |
|
|
91
|
+
| `@oni.bot/core/harness` | Agentic loop: `ONIHarness`, `AgentLoop`, `HooksEngine`, `ContextCompactor` |
|
|
92
|
+
| `@oni.bot/core/mcp` | MCP client: JSON-RPC/stdio tool bridge |
|
|
93
|
+
| `@oni.bot/core/lsp` | LSP client: language server protocol primitives |
|
|
94
|
+
| `@oni.bot/core/config` | Config loader: JSONC parsing, environment variable resolution |
|
|
394
95
|
|
|
395
96
|
---
|
|
396
97
|
|
|
397
|
-
##
|
|
98
|
+
## Ecosystem
|
|
398
99
|
|
|
399
|
-
|
|
100
|
+
**Built on @oni.bot/core:**
|
|
400
101
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
npm install pg # PostgresCheckpointer
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
## Contributing
|
|
409
|
-
|
|
410
|
-
Contributions are welcome. Please open an issue to discuss significant changes before submitting a PR.
|
|
411
|
-
|
|
412
|
-
```bash
|
|
413
|
-
git clone https://github.com/oni-bot/core.git
|
|
414
|
-
cd core
|
|
415
|
-
npm install
|
|
416
|
-
npm test
|
|
417
|
-
```
|
|
102
|
+
- [`@oni.bot/code`](https://github.com/AP3X-Dev) — AI coding assistant CLI *(coming soon)*
|
|
103
|
+
- [`@oni.bot/sentinel`](https://github.com/AP3X-Dev) — Code analysis and review engine *(coming soon)*
|
|
418
104
|
|
|
419
105
|
---
|
|
420
106
|
|
|
421
107
|
## License
|
|
422
108
|
|
|
423
|
-
MIT
|
|
109
|
+
MIT — [AP3X Dev](https://github.com/AP3X-Dev)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/checkpointers/sqlite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/checkpointers/sqlite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AASzF,qBAAa,kBAAkB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAC1C,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAvC,OAAO;WAEM,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IA4BhE,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAOvD,GAAG,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IA6BjF,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAK7E,KAAK,IAAI,IAAI;IAEb,OAAO,CAAC,WAAW;CA4BpB"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// npm install better-sqlite3
|
|
7
7
|
// npm install -D @types/better-sqlite3
|
|
8
8
|
// ============================================================
|
|
9
|
+
import { CheckpointCorruptError } from "../errors.js";
|
|
9
10
|
export class SqliteCheckpointer {
|
|
10
11
|
db;
|
|
11
12
|
constructor(db) {
|
|
@@ -84,16 +85,30 @@ export class SqliteCheckpointer {
|
|
|
84
85
|
}
|
|
85
86
|
close() { this.db.close(); }
|
|
86
87
|
deserialize(row) {
|
|
88
|
+
const threadId = row["thread_id"];
|
|
89
|
+
const safeParse = (field, raw) => {
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(raw);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
throw new CheckpointCorruptError(threadId, `failed to parse "${field}" — data may be truncated or corrupted`);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const step = Number(row["step"]);
|
|
98
|
+
const timestamp = Number(row["timestamp"]);
|
|
99
|
+
if (!Number.isFinite(step) || !Number.isFinite(timestamp)) {
|
|
100
|
+
throw new CheckpointCorruptError(threadId, "step or timestamp is not a valid number");
|
|
101
|
+
}
|
|
87
102
|
return {
|
|
88
|
-
threadId
|
|
89
|
-
step
|
|
103
|
+
threadId,
|
|
104
|
+
step,
|
|
90
105
|
agentId: row["agent_id"] ?? undefined,
|
|
91
|
-
state:
|
|
92
|
-
nextNodes:
|
|
93
|
-
pendingSends:
|
|
94
|
-
metadata: row["metadata"] ?
|
|
95
|
-
pendingWrites: row["pending_writes"] ?
|
|
96
|
-
timestamp
|
|
106
|
+
state: safeParse("state", row["state"]),
|
|
107
|
+
nextNodes: safeParse("next_nodes", row["next_nodes"]),
|
|
108
|
+
pendingSends: safeParse("pending_sends", row["pending_sends"]),
|
|
109
|
+
metadata: row["metadata"] ? safeParse("metadata", row["metadata"]) : undefined,
|
|
110
|
+
pendingWrites: row["pending_writes"] ? safeParse("pending_writes", row["pending_writes"]) : undefined,
|
|
111
|
+
timestamp,
|
|
97
112
|
};
|
|
98
113
|
}
|
|
99
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/checkpointers/sqlite.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,sCAAsC;AACtC,+DAA+D;AAC/D,uDAAuD;AACvD,EAAE;AACF,+BAA+B;AAC/B,yCAAyC;AACzC,+DAA+D;
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/checkpointers/sqlite.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,sCAAsC;AACtC,+DAA+D;AAC/D,uDAAuD;AACvD,EAAE;AACF,+BAA+B;AAC/B,yCAAyC;AACzC,+DAA+D;AAG/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAQtD,MAAM,OAAO,kBAAkB;IACQ;IAArC,YAAqC,EAAY;QAAZ,OAAE,GAAF,EAAE,CAAU;IAAG,CAAC;IAErD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAI,MAAc;QACnC,IAAI,EAA+B,CAAC;QACpC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,gBAA0B,CAAC,CAAC;YACrD,EA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AAS;YAC9D,KAAK,EAAU,SAAS,CAAI,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAClD,SAAS,EAAM,SAAS,CAAW,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;YACnE,YAAY,EAAG,SAAS,CAAyD,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;YACvH,QAAQ,EAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAA0B,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;YAC5G,aAAa,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS,CAA6D,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;YACjK,SAAS;SACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParsedArgs } from "./router.js";
|
|
2
|
+
interface PackageExports {
|
|
3
|
+
exports?: Record<string, {
|
|
4
|
+
import?: string;
|
|
5
|
+
types?: string;
|
|
6
|
+
} | string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateExports(pkg: PackageExports): string[];
|
|
9
|
+
export declare function buildCommand(args: ParsedArgs): Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,UAAU,cAAc;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,CAAC;CACxE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,EAAE,CAe7D;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA2ClE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @oni.bot/core CLI — build command
|
|
3
|
+
// TypeScript build + export validation
|
|
4
|
+
// ============================================================
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
export function validateExports(pkg) {
|
|
9
|
+
const errors = [];
|
|
10
|
+
if (!pkg.exports)
|
|
11
|
+
return errors;
|
|
12
|
+
for (const [path, value] of Object.entries(pkg.exports)) {
|
|
13
|
+
if (typeof value === "string")
|
|
14
|
+
continue;
|
|
15
|
+
if (!value.types) {
|
|
16
|
+
errors.push(`Export "${path}" is missing "types" field`);
|
|
17
|
+
}
|
|
18
|
+
if (!value.import) {
|
|
19
|
+
errors.push(`Export "${path}" is missing "import" field`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return errors;
|
|
23
|
+
}
|
|
24
|
+
export async function buildCommand(args) {
|
|
25
|
+
const noCheck = args.flags["no-check"] === "true";
|
|
26
|
+
const cwd = process.cwd();
|
|
27
|
+
console.log("\n Building...\n");
|
|
28
|
+
// Step 1: Run tsc
|
|
29
|
+
const tscArgs = noCheck ? ["tsc", "--noEmit", "false"] : ["tsc"];
|
|
30
|
+
const child = spawn("npx", tscArgs, {
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
shell: true,
|
|
33
|
+
});
|
|
34
|
+
const exitCode = await new Promise((r) => child.on("close", r));
|
|
35
|
+
if (exitCode && exitCode !== 0) {
|
|
36
|
+
console.error("\n Build failed — TypeScript compilation errors");
|
|
37
|
+
process.exitCode = exitCode;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
console.log(" TypeScript compilation successful");
|
|
41
|
+
// Step 2: Validate package.json exports
|
|
42
|
+
try {
|
|
43
|
+
const pkgPath = resolve(cwd, "package.json");
|
|
44
|
+
const pkgJson = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
45
|
+
const errors = validateExports(pkgJson);
|
|
46
|
+
if (errors.length > 0) {
|
|
47
|
+
console.log("\n Export validation warnings:");
|
|
48
|
+
for (const err of errors) {
|
|
49
|
+
console.log(` ! ${err}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(" Export validation passed");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// No package.json or can't read — skip validation
|
|
58
|
+
}
|
|
59
|
+
console.log("\n Build complete!\n");
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,oCAAoC;AACpC,uCAAuC;AACvC,+DAA+D;AAE/D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,MAAM,UAAU,eAAe,CAAC,GAAmB;IACjD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAEhC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACxD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QACxC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,WAAW,IAAI,4BAA4B,CAAC,CAAC;QAC3D,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