@theaiinc/yggdrasil 0.2.1 → 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/LICENSE +21 -0
- package/README.md +157 -0
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/orchestration-controller.d.ts +13 -1
- package/dist/src/orchestration-controller.d.ts.map +1 -1
- package/dist/src/orchestration-controller.js +419 -50
- package/dist/src/orchestration-controller.js.map +1 -1
- package/dist/src/services/realm-lifecycle.d.ts +49 -0
- package/dist/src/services/realm-lifecycle.d.ts.map +1 -0
- package/dist/src/services/realm-lifecycle.js +154 -0
- package/dist/src/services/realm-lifecycle.js.map +1 -0
- package/dist/src/services/realm-provisioner.d.ts +45 -0
- package/dist/src/services/realm-provisioner.d.ts.map +1 -0
- package/dist/src/services/realm-provisioner.js +102 -0
- package/dist/src/services/realm-provisioner.js.map +1 -0
- package/dist/src/services/realm-registry.d.ts +83 -0
- package/dist/src/services/realm-registry.d.ts.map +1 -0
- package/dist/src/services/realm-registry.js +136 -0
- package/dist/src/services/realm-registry.js.map +1 -0
- package/dist/src/services/realm-scheduler.d.ts +47 -0
- package/dist/src/services/realm-scheduler.d.ts.map +1 -0
- package/dist/src/services/realm-scheduler.js +112 -0
- package/dist/src/services/realm-scheduler.js.map +1 -0
- package/dist/src/types/index.d.ts +270 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +6 -1
- package/dist/src/types/index.js.map +1 -1
- package/package.json +25 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The AI Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @theaiinc/yggdrasil
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/theaiinc/yggdrasil"><img alt="GitHub Repo" src="https://img.shields.io/badge/github-theaiinc%2Fyggdrasil-181717?style=flat-square&logo=github"/></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@theaiinc/yggdrasil"><img alt="npm" src="https://img.shields.io/npm/v/@theaiinc/yggdrasil?style=flat-square&logo=npm"/></a>
|
|
6
|
+
<a href="https://github.com/theaiinc/yggdrasil/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/theaiinc/yggdrasil?style=flat-square"/></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="./yggdrasil.svg" alt="Yggdrasil" width="300" />
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
Distributed runner orchestration controller — receives runner registrations and heartbeats, dispatches tasks, and manages a dynamic pool of Ratatoskr agents.
|
|
14
|
+
|
|
15
|
+
Yggdrasil is the control plane for a fleet of runners. Each runner runs a [Ratatoskr](https://www.npmjs.com/package/@theaiinc/yggdrasil-ratatoskr) daemon that registers, heartbeats, and executes tasks. Yggdrasil tracks which runners are alive, assigns tasks to them, and handles lease expiry, updates, and health monitoring.
|
|
16
|
+
|
|
17
|
+
> **Version note**: `@theaiinc/yggdrasil` and `@theaiinc/yggdrasil-ratatoskr` are always released at the same version number.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @theaiinc/yggdrasil
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Logger } from '@theaiinc/yggdrasil';
|
|
29
|
+
|
|
30
|
+
const logger = new Logger({ level: 'info', format: 'simple', transports: ['console'] });
|
|
31
|
+
logger.info('Yggdrasil ready');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Running the controller
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx @theaiinc/yggdrasil
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
By default Yggdrasil listens on port 3000. Configure via environment variables:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
PORT=3100 \
|
|
44
|
+
API_KEYS=my-secret-key \
|
|
45
|
+
LEASE_TTL_MS=60000 \
|
|
46
|
+
npx @theaiinc/yggdrasil
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Architecture
|
|
50
|
+
|
|
51
|
+
```mermaid
|
|
52
|
+
graph LR
|
|
53
|
+
subgraph Runners
|
|
54
|
+
RT1[Ratatoskr<br/>runner-1]
|
|
55
|
+
RT2[Ratatoskr<br/>runner-2]
|
|
56
|
+
RTN[Ratatoskr<br/>runner-N]
|
|
57
|
+
end
|
|
58
|
+
subgraph ControlPlane
|
|
59
|
+
Y[Yggdrasil<br/>Controller<br/>POST /runners/register<br/>POST /runners/heartbeat<br/>POST /runners/task/:id/patch]
|
|
60
|
+
end
|
|
61
|
+
subgraph Consumers
|
|
62
|
+
OG[api-gateway<br/>orchestration layer]
|
|
63
|
+
end
|
|
64
|
+
RT1 <-->|HTTP| Y
|
|
65
|
+
RT2 <-->|HTTP| Y
|
|
66
|
+
RTN <-->|HTTP| Y
|
|
67
|
+
OG -->|GET /api/runners<br/>GET /runners/:id/tasks| Y
|
|
68
|
+
Y -->|POST /runners/:id/tasks<br/>PATCH /runners/:id/tasks/:tid| OG
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## API Endpoints
|
|
72
|
+
|
|
73
|
+
The controller serves these endpoints (consumed by Ratatoskr and pool orchestrators):
|
|
74
|
+
|
|
75
|
+
| Method | Path | Purpose |
|
|
76
|
+
|--------|------|---------|
|
|
77
|
+
| `GET` | `/health` | Health check |
|
|
78
|
+
| `GET` | `/runners` | List all runners |
|
|
79
|
+
| `POST` | `/runners/register` | Register a new runner |
|
|
80
|
+
| `POST` | `/runners/heartbeat` | Runner heartbeat |
|
|
81
|
+
| `POST` | `/runners/update` | Update runner endpoint |
|
|
82
|
+
| `POST` | `/runners/offline` | Deregister a runner (graceful shutdown) |
|
|
83
|
+
| `GET` | `/runners/:id` | Get runner details |
|
|
84
|
+
| `GET` | `/runners/:id/tasks` | List runner tasks |
|
|
85
|
+
| `POST` | `/runners/:id/tasks` | Dispatch a task to a runner |
|
|
86
|
+
| `PATCH` | `/runners/:id/tasks/:tid` | Update task status |
|
|
87
|
+
| `POST` | `/version-check/:version` | Check version compliance |
|
|
88
|
+
| `POST` | `/runners/:id/request-update` | Request runner update |
|
|
89
|
+
| `GET` | `/admission` | Get admission state (circuit breaker) |
|
|
90
|
+
| `GET` | `/metrics` | Prometheus metrics |
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
### Controller environment variables
|
|
95
|
+
|
|
96
|
+
| Variable | Default | Description |
|
|
97
|
+
|----------|---------|-------------|
|
|
98
|
+
| `PORT` | `3000` | HTTP listen port |
|
|
99
|
+
| `API_KEYS` | `''` | Comma-separated API keys for runner auth |
|
|
100
|
+
| `LEASE_TTL_MS` | `60000` | Milliseconds before an unresponsive runner is marked offline |
|
|
101
|
+
| `HEARTBEAT_INTERVAL_MS` | `15000` | Expected heartbeat interval (for lease calculation) |
|
|
102
|
+
| `NODE_ENV` | `development` | Environment name |
|
|
103
|
+
| `LOG_LEVEL` | `info` | Log level (error, warn, info, debug) |
|
|
104
|
+
| `LOG_FORMAT` | `simple` | Log format (json, simple) |
|
|
105
|
+
| `EXPECTED_RUNNER_VERSION` | `''` | Expected runner version string (for version compliance checks) |
|
|
106
|
+
| `METRICS_PREFIX` | `yggdrasil_` | Prefix for Prometheus metric names |
|
|
107
|
+
|
|
108
|
+
### Exported types
|
|
109
|
+
|
|
110
|
+
All wire protocol types are exported for consumers:
|
|
111
|
+
|
|
112
|
+
- `RunnerInfo`, `RunnerTask`, `SystemResources`, `PendingUpdate`
|
|
113
|
+
- `RegisterRunnerPayload`, `HeartbeatPayload`, `HeartbeatResponse`, `RequestUpdatePayload`
|
|
114
|
+
- `LogLevel`, `LoggerConfig`
|
|
115
|
+
|
|
116
|
+
### Exported utilities
|
|
117
|
+
|
|
118
|
+
- `Logger` — Structured logger (JSON or simple format, console transport)
|
|
119
|
+
|
|
120
|
+
## Prometheus Metrics
|
|
121
|
+
|
|
122
|
+
Yggdrasil exposes Prometheus metrics at `GET /metrics`:
|
|
123
|
+
|
|
124
|
+
| Metric | Type | Labels | Description |
|
|
125
|
+
|--------|------|--------|-------------|
|
|
126
|
+
| `yggdrasil_runners_registered` | Gauge | — | Number of registered runners |
|
|
127
|
+
| `yggdrasil_runners_offline` | Gauge | — | Number of offline runners |
|
|
128
|
+
| `yggdrasil_runner_info` | Gauge | `runner_id`, `name`, `version`, `status` | Runner metadata |
|
|
129
|
+
| `yggdrasil_runner_uptime_seconds` | Gauge | `runner_id` | Runner uptime |
|
|
130
|
+
| `yggdrasil_runner_cpu_percent` | Gauge | `runner_id` | CPU usage |
|
|
131
|
+
| `yggdrasil_runner_memory_percent` | Gauge | `runner_id` | Memory usage |
|
|
132
|
+
| `yggdrasil_runner_leases` | Gauge | `runner_id` | Lease expiry timestamp |
|
|
133
|
+
| `yggdrasil_runner_tasks_running` | Gauge | `runner_id` | Running task count |
|
|
134
|
+
| `yggdrasil_tasks_dispatched_total` | Counter | — | Total dispatched tasks |
|
|
135
|
+
| `yggdrasil_tasks_completed_total` | Counter | `status` | Total completed tasks |
|
|
136
|
+
|
|
137
|
+
## Lease Management
|
|
138
|
+
|
|
139
|
+
Each runner registration includes a lease TTL. Yggdrasil expects heartbeats before the lease expires. On timeout:
|
|
140
|
+
|
|
141
|
+
1. The runner is marked `offline`
|
|
142
|
+
2. Its tasks transition to `failed`
|
|
143
|
+
3. A configured `RUNNER_OFFLINE_HOOK` can be triggered (if set)
|
|
144
|
+
4. The runner must re-register to come back online
|
|
145
|
+
|
|
146
|
+
## Self-Update Protocol
|
|
147
|
+
|
|
148
|
+
Yggdrasil supports requesting runner version updates:
|
|
149
|
+
|
|
150
|
+
1. Admin calls `POST /runners/:id/request-update` with a version/command
|
|
151
|
+
2. Yggdrasil stores the pending update on the runner's record
|
|
152
|
+
3. On the next heartbeat, Ratatoskr sees `pendingUpdate` and triggers the update
|
|
153
|
+
4. The update runs after all current tasks complete, then the runner restarts
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT — © 2026 The AI Inc
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { Logger } from './services/logger.js';
|
|
2
|
-
export
|
|
2
|
+
export { app, runners, sessions, realmRegistry, realmScheduler, realmProvisioner, realmLifecycle } from './orchestration-controller.js';
|
|
3
|
+
export { RealmRegistry } from './services/realm-registry.js';
|
|
4
|
+
export { RealmScheduler } from './services/realm-scheduler.js';
|
|
5
|
+
export { RealmProvisioner } from './services/realm-provisioner.js';
|
|
6
|
+
export { RealmLifecycleService } from './services/realm-lifecycle.js';
|
|
7
|
+
export type { LogLevel, LoggerConfig, SessionType, SessionState, ObservationMethod, InputCapability, SessionDescriptor, CreateSessionRequest, CreateSessionResponse, SessionObservation, SessionInput, SessionInputResult, SessionHealth, RealmTemplateType, RealmState, RealmTemplate, Realm, RealmAllocation, RealmRegistration, RealmHeartbeat, RealmDeregistration, SystemResources, PendingUpdate, RunnerTask, RunnerInfo, RegisterRunnerPayload, HeartbeatPayload, HeartbeatResponse, RequestUpdatePayload, } from './types/index.js';
|
|
3
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAExI,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,YAAY,EACV,QAAQ,EACR,YAAY,EAGZ,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EAGb,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EAGnB,eAAe,EACf,aAAa,EACb,UAAU,EACV,UAAU,EAGV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
// Main entry point for @theaiinc/yggdrasil package
|
|
2
2
|
export { Logger } from './services/logger.js';
|
|
3
|
+
export { app, runners, sessions, realmRegistry, realmScheduler, realmProvisioner, realmLifecycle } from './orchestration-controller.js';
|
|
4
|
+
export { RealmRegistry } from './services/realm-registry.js';
|
|
5
|
+
export { RealmScheduler } from './services/realm-scheduler.js';
|
|
6
|
+
export { RealmProvisioner } from './services/realm-provisioner.js';
|
|
7
|
+
export { RealmLifecycleService } from './services/realm-lifecycle.js';
|
|
3
8
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAExI,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { RealmRegistry } from './services/realm-registry.js';
|
|
2
|
+
import { RealmScheduler } from './services/realm-scheduler.js';
|
|
3
|
+
import { RealmProvisioner } from './services/realm-provisioner.js';
|
|
4
|
+
import { RealmLifecycleService } from './services/realm-lifecycle.js';
|
|
5
|
+
import type { RunnerInfo, SessionDescriptor } from './types/index.js';
|
|
6
|
+
declare const app: import("express-serve-static-core").Express;
|
|
7
|
+
declare const runners: Map<string, RunnerInfo>;
|
|
8
|
+
declare const realmRegistry: RealmRegistry;
|
|
9
|
+
declare const realmScheduler: RealmScheduler;
|
|
10
|
+
declare const realmProvisioner: RealmProvisioner;
|
|
11
|
+
declare const realmLifecycle: RealmLifecycleService;
|
|
12
|
+
declare const sessions: Map<string, SessionDescriptor>;
|
|
13
|
+
export { app, runners, sessions, realmRegistry, realmScheduler, realmProvisioner, realmLifecycle };
|
|
2
14
|
//# sourceMappingURL=orchestration-controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestration-controller.d.ts","sourceRoot":"","sources":["../../src/orchestration-controller.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"orchestration-controller.d.ts","sourceRoot":"","sources":["../../src/orchestration-controller.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAGV,UAAU,EAQV,iBAAiB,EAUlB,MAAM,kBAAkB,CAAC;AAE1B,QAAA,MAAM,GAAG,6CAAY,CAAC;AAGtB,QAAA,MAAM,OAAO,yBAAgC,CAAC;AAI9C,QAAA,MAAM,aAAa,eAAsB,CAAC;AAC1C,QAAA,MAAM,cAAc,gBAAyE,CAAC;AAC9F,QAAA,MAAM,gBAAgB,kBAAsC,CAAC;AAC7D,QAAA,MAAM,cAAc,uBAA2C,CAAC;AAichE,QAAA,MAAM,QAAQ,gCAAuC,CAAC;AAwXtD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC"}
|