@radaros/edge 0.3.19
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/dist/index.d.ts +427 -0
- package/dist/index.js +5964 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Agent, Toolkit, ToolDef } from '@radaros/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Register all edge/IoT toolkits in the global ToolkitCatalog.
|
|
6
|
+
* Call this once at startup so they appear in the Admin UI.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { registerEdgeToolkits } from "@radaros/edge";
|
|
11
|
+
* registerEdgeToolkits();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function registerEdgeToolkits(): void;
|
|
15
|
+
|
|
16
|
+
interface EdgePreset {
|
|
17
|
+
/** Preset identifier. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable label. */
|
|
20
|
+
label: string;
|
|
21
|
+
/** Recommended Ollama model for this device class. */
|
|
22
|
+
recommendedModel: string;
|
|
23
|
+
/** Max tokens to generate per request. */
|
|
24
|
+
maxTokens: number;
|
|
25
|
+
/** Max context window (tokens) — limits conversation history. */
|
|
26
|
+
contextWindow: number;
|
|
27
|
+
/** Memory budget for the Node.js process in MB. */
|
|
28
|
+
memoryLimitMb: number;
|
|
29
|
+
/** Watchdog timeout in ms — restart agent if unresponsive longer than this. */
|
|
30
|
+
watchdogTimeoutMs: number;
|
|
31
|
+
/** Resource monitor polling interval in ms. */
|
|
32
|
+
monitorIntervalMs: number;
|
|
33
|
+
/** CPU temperature threshold (°C) — start throttling above this. */
|
|
34
|
+
thermalThrottleC: number;
|
|
35
|
+
/** Memory usage threshold (0-1) — start shedding tools above this. */
|
|
36
|
+
memoryThreshold: number;
|
|
37
|
+
/** Disable heavyweight features on edge by default. */
|
|
38
|
+
disableFeatures: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get an edge configuration preset by device identifier.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const config = edgePreset("pi5-8gb");
|
|
46
|
+
* console.log(config.recommendedModel); // "phi3:mini"
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function edgePreset(id: string): EdgePreset;
|
|
50
|
+
/** List all available preset IDs and labels. */
|
|
51
|
+
declare function listEdgePresets(): Array<{
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** Create a custom preset by overriding fields of an existing one. */
|
|
56
|
+
declare function customEdgePreset(base: string, overrides: Partial<EdgePreset>): EdgePreset;
|
|
57
|
+
|
|
58
|
+
interface ResourceSnapshot {
|
|
59
|
+
timestamp: number;
|
|
60
|
+
cpu: {
|
|
61
|
+
temperature_c: number | null;
|
|
62
|
+
usage_percent: number;
|
|
63
|
+
};
|
|
64
|
+
memory: {
|
|
65
|
+
total_bytes: number;
|
|
66
|
+
used_bytes: number;
|
|
67
|
+
free_bytes: number;
|
|
68
|
+
usage_percent: number;
|
|
69
|
+
};
|
|
70
|
+
disk: {
|
|
71
|
+
total_bytes: number;
|
|
72
|
+
used_bytes: number;
|
|
73
|
+
free_bytes: number;
|
|
74
|
+
usage_percent: number;
|
|
75
|
+
};
|
|
76
|
+
uptime_seconds: number;
|
|
77
|
+
}
|
|
78
|
+
interface ResourceThresholds {
|
|
79
|
+
/** CPU temperature (°C) — emit "thermal-warning" above this. */
|
|
80
|
+
thermalThrottleC: number;
|
|
81
|
+
/** Memory usage ratio (0-1) — emit "memory-warning" above this. */
|
|
82
|
+
memoryThreshold: number;
|
|
83
|
+
/** Disk usage ratio (0-1) — emit "disk-warning" above this. */
|
|
84
|
+
diskThreshold: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Monitors system resources (CPU, memory, disk, temperature) at a
|
|
88
|
+
* configurable interval. Emits events when thresholds are exceeded.
|
|
89
|
+
*/
|
|
90
|
+
declare class ResourceMonitor extends EventEmitter {
|
|
91
|
+
private intervalMs;
|
|
92
|
+
private thresholds;
|
|
93
|
+
private timer;
|
|
94
|
+
private _lastSnapshot;
|
|
95
|
+
constructor(opts?: {
|
|
96
|
+
intervalMs?: number;
|
|
97
|
+
thresholds?: Partial<ResourceThresholds>;
|
|
98
|
+
});
|
|
99
|
+
get lastSnapshot(): ResourceSnapshot | null;
|
|
100
|
+
/** Take a single snapshot right now. */
|
|
101
|
+
snapshot(): ResourceSnapshot;
|
|
102
|
+
/** Start periodic monitoring. */
|
|
103
|
+
start(): void;
|
|
104
|
+
/** Stop periodic monitoring. */
|
|
105
|
+
stop(): void;
|
|
106
|
+
private check;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface EdgeRuntimeConfig {
|
|
110
|
+
/** Edge preset ID or custom preset object. */
|
|
111
|
+
preset: string | EdgePreset;
|
|
112
|
+
/** Agent instance to manage. */
|
|
113
|
+
agent: Agent;
|
|
114
|
+
/** Port for the health check HTTP server (default 9090). */
|
|
115
|
+
healthPort?: number;
|
|
116
|
+
/** Disable the health check endpoint. */
|
|
117
|
+
disableHealthCheck?: boolean;
|
|
118
|
+
/** Callback when agent is restarted by the watchdog. */
|
|
119
|
+
onWatchdogRestart?: (reason: string) => void;
|
|
120
|
+
/** Toolkits that can be shed under memory pressure (by name). */
|
|
121
|
+
sheddableToolkits?: string[];
|
|
122
|
+
}
|
|
123
|
+
interface EdgeRuntimeStatus {
|
|
124
|
+
state: "starting" | "running" | "degraded" | "stopped";
|
|
125
|
+
uptime_ms: number;
|
|
126
|
+
watchdog_restarts: number;
|
|
127
|
+
resources: ResourceSnapshot | null;
|
|
128
|
+
degraded_reason: string | null;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* EdgeRuntime — manages an Agent on constrained edge hardware.
|
|
132
|
+
*
|
|
133
|
+
* Features:
|
|
134
|
+
* - Watchdog: auto-detect unresponsive agent and emit restart event
|
|
135
|
+
* - Resource Monitor: CPU temp, memory, disk tracking with threshold events
|
|
136
|
+
* - Graceful degradation: shed non-critical tools under memory pressure
|
|
137
|
+
* - Health endpoint: lightweight HTTP `/health` for external monitoring
|
|
138
|
+
*/
|
|
139
|
+
declare class EdgeRuntime extends EventEmitter {
|
|
140
|
+
private config;
|
|
141
|
+
private preset;
|
|
142
|
+
private monitor;
|
|
143
|
+
private healthServer;
|
|
144
|
+
private watchdogTimer;
|
|
145
|
+
private lastActivity;
|
|
146
|
+
private startTime;
|
|
147
|
+
private watchdogRestarts;
|
|
148
|
+
private _state;
|
|
149
|
+
private degradedReason;
|
|
150
|
+
constructor(config: EdgeRuntimeConfig);
|
|
151
|
+
get state(): "starting" | "running" | "degraded" | "stopped";
|
|
152
|
+
/** Start the edge runtime: resource monitor, watchdog, and health endpoint. */
|
|
153
|
+
start(): Promise<void>;
|
|
154
|
+
/** Stop the runtime cleanly. */
|
|
155
|
+
stop(): Promise<void>;
|
|
156
|
+
/** Signal that the agent is alive — call this from agent hooks. */
|
|
157
|
+
heartbeat(): void;
|
|
158
|
+
/** Get current runtime status. */
|
|
159
|
+
getStatus(): EdgeRuntimeStatus;
|
|
160
|
+
/** Get the resource monitor for direct access. */
|
|
161
|
+
getMonitor(): ResourceMonitor;
|
|
162
|
+
private enterDegraded;
|
|
163
|
+
private startWatchdog;
|
|
164
|
+
private stopWatchdog;
|
|
165
|
+
private startHealthServer;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface OllamaStatus {
|
|
169
|
+
running: boolean;
|
|
170
|
+
version?: string;
|
|
171
|
+
models?: string[];
|
|
172
|
+
error?: string;
|
|
173
|
+
}
|
|
174
|
+
interface ModelRecommendation {
|
|
175
|
+
model: string;
|
|
176
|
+
label: string;
|
|
177
|
+
parameterSize: string;
|
|
178
|
+
ramRequired: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check whether Ollama is running and accessible.
|
|
182
|
+
*/
|
|
183
|
+
declare function checkOllama(baseUrl?: string): Promise<OllamaStatus>;
|
|
184
|
+
/**
|
|
185
|
+
* Ensure Ollama is running. If not, attempt to start the `ollama serve` process.
|
|
186
|
+
* Returns the status after attempting to start.
|
|
187
|
+
*/
|
|
188
|
+
declare function ensureOllama(baseUrl?: string): Promise<OllamaStatus>;
|
|
189
|
+
/**
|
|
190
|
+
* Pull a model if it's not already cached locally.
|
|
191
|
+
* Uses the Ollama HTTP API's /api/pull endpoint.
|
|
192
|
+
*/
|
|
193
|
+
declare function pullModel(model: string, opts?: {
|
|
194
|
+
baseUrl?: string;
|
|
195
|
+
onProgress?: (status: string) => void;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
success: boolean;
|
|
198
|
+
model: string;
|
|
199
|
+
error?: string;
|
|
200
|
+
}>;
|
|
201
|
+
/**
|
|
202
|
+
* Recommend the best model for the available RAM.
|
|
203
|
+
*
|
|
204
|
+
* @param ramMb - Available RAM in megabytes.
|
|
205
|
+
* @returns The best model that fits, or the smallest if none fit comfortably.
|
|
206
|
+
*/
|
|
207
|
+
declare function recommendModel(ramMb: number): ModelRecommendation;
|
|
208
|
+
/** List all known model tiers with their RAM requirements. */
|
|
209
|
+
declare function listModelTiers(): ModelRecommendation[];
|
|
210
|
+
/**
|
|
211
|
+
* Check if a specific model is cached locally.
|
|
212
|
+
*/
|
|
213
|
+
declare function hasModel(model: string, baseUrl?: string): Promise<boolean>;
|
|
214
|
+
|
|
215
|
+
interface EdgeCloudSyncConfig {
|
|
216
|
+
/** Cloud server base URL (e.g. "https://api.example.com"). */
|
|
217
|
+
cloudUrl: string;
|
|
218
|
+
/** Unique device/edge node identifier. */
|
|
219
|
+
deviceId: string;
|
|
220
|
+
/** Auth token for cloud API requests. */
|
|
221
|
+
authToken?: string;
|
|
222
|
+
/** Heartbeat interval in ms (default 30000). */
|
|
223
|
+
heartbeatIntervalMs?: number;
|
|
224
|
+
/** Local SQLite-like queue directory for offline events (default /tmp/radaros-edge-queue). */
|
|
225
|
+
queueDir?: string;
|
|
226
|
+
/** Max queued events before oldest are dropped (default 10000). */
|
|
227
|
+
maxQueueSize?: number;
|
|
228
|
+
/** Auto-flush interval in ms — attempt to push queued events (default 60000). */
|
|
229
|
+
flushIntervalMs?: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* EdgeCloudSync — connects an edge device to a cloud RadarOS instance.
|
|
233
|
+
*
|
|
234
|
+
* Features:
|
|
235
|
+
* - Heartbeat: periodic POST with device status and resource metrics
|
|
236
|
+
* - Config pull: fetch agent/team blueprints from the cloud admin API
|
|
237
|
+
* - Event push: stream agent run results back to cloud
|
|
238
|
+
* - Offline-first: queue events locally when cloud is unreachable, flush on reconnect
|
|
239
|
+
*/
|
|
240
|
+
declare class EdgeCloudSync extends EventEmitter {
|
|
241
|
+
private config;
|
|
242
|
+
private heartbeatTimer;
|
|
243
|
+
private flushTimer;
|
|
244
|
+
private queue;
|
|
245
|
+
private queueFile;
|
|
246
|
+
private maxQueueSize;
|
|
247
|
+
private connected;
|
|
248
|
+
private backoffMs;
|
|
249
|
+
private readonly maxBackoff;
|
|
250
|
+
constructor(config: EdgeCloudSyncConfig);
|
|
251
|
+
/** Start heartbeat and flush timers. */
|
|
252
|
+
start(): void;
|
|
253
|
+
/** Stop all timers. */
|
|
254
|
+
stop(): void;
|
|
255
|
+
/** Push an event to the cloud. Queues locally if offline. */
|
|
256
|
+
pushEvent(type: string, payload: unknown): void;
|
|
257
|
+
/** Pull agent/team blueprints from the cloud admin API. */
|
|
258
|
+
pullConfig(): Promise<{
|
|
259
|
+
agents: unknown[];
|
|
260
|
+
teams: unknown[];
|
|
261
|
+
workflows: unknown[];
|
|
262
|
+
}>;
|
|
263
|
+
/** Send heartbeat with device status. */
|
|
264
|
+
sendHeartbeat(resources?: ResourceSnapshot): Promise<void>;
|
|
265
|
+
/** Attempt to flush all queued events to the cloud. */
|
|
266
|
+
flush(): Promise<{
|
|
267
|
+
sent: number;
|
|
268
|
+
failed: number;
|
|
269
|
+
remaining: number;
|
|
270
|
+
}>;
|
|
271
|
+
get isConnected(): boolean;
|
|
272
|
+
get queueSize(): number;
|
|
273
|
+
private cloudGet;
|
|
274
|
+
private cloudPost;
|
|
275
|
+
private getHeaders;
|
|
276
|
+
private onConnected;
|
|
277
|
+
private onDisconnected;
|
|
278
|
+
private persistQueue;
|
|
279
|
+
private loadQueue;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
interface BleConfig {
|
|
283
|
+
/** Default scan timeout in ms (default 5000). */
|
|
284
|
+
scanTimeout?: number;
|
|
285
|
+
/** Filter scans to only these service UUIDs. */
|
|
286
|
+
serviceUuidFilter?: string[];
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* BleToolkit — Bluetooth Low Energy scanning and communication.
|
|
290
|
+
* Requires `@stoprocent/noble` as an optional peer dependency.
|
|
291
|
+
* Compatible with Raspberry Pi 5 and Pi 4.
|
|
292
|
+
*/
|
|
293
|
+
declare class BleToolkit extends Toolkit {
|
|
294
|
+
readonly name = "ble";
|
|
295
|
+
private scanTimeout;
|
|
296
|
+
private serviceFilter;
|
|
297
|
+
private connectedPeripherals;
|
|
298
|
+
constructor(config?: BleConfig);
|
|
299
|
+
getTools(): ToolDef[];
|
|
300
|
+
dispose(): void;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
interface CameraConfig {
|
|
304
|
+
/** Default image width (default 1280). */
|
|
305
|
+
width?: number;
|
|
306
|
+
/** Default image height (default 720). */
|
|
307
|
+
height?: number;
|
|
308
|
+
/** Image rotation in degrees: 0, 90, 180, 270 (default 0). */
|
|
309
|
+
rotation?: number;
|
|
310
|
+
/** Output directory for captured images/videos (default /tmp/radaros-camera). */
|
|
311
|
+
outputDir?: string;
|
|
312
|
+
/** Output format: "jpg" | "png" (default "jpg"). */
|
|
313
|
+
format?: "jpg" | "png";
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* CameraToolkit — capture photos and video using `libcamera-still` / `libcamera-vid`.
|
|
317
|
+
* Most reliable approach for Raspberry Pi 5 and Pi Camera Module 3.
|
|
318
|
+
* Falls back to `raspistill` / `raspivid` if libcamera is not available.
|
|
319
|
+
*/
|
|
320
|
+
declare class CameraToolkit extends Toolkit {
|
|
321
|
+
readonly name = "camera";
|
|
322
|
+
private width;
|
|
323
|
+
private height;
|
|
324
|
+
private rotation;
|
|
325
|
+
private outputDir;
|
|
326
|
+
private format;
|
|
327
|
+
private streamProcess;
|
|
328
|
+
constructor(config?: CameraConfig);
|
|
329
|
+
private getCaptureCommand;
|
|
330
|
+
private getVideoCommand;
|
|
331
|
+
getTools(): ToolDef[];
|
|
332
|
+
dispose(): void;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
interface GpioConfig {
|
|
336
|
+
/** GPIO chip number. Use 4 for Pi 5, 0 for Pi 4 and earlier. Default: 0. */
|
|
337
|
+
chipNumber?: number;
|
|
338
|
+
/** Allowlist of pin numbers agents may access. Empty = all pins allowed. */
|
|
339
|
+
allowedPins?: number[];
|
|
340
|
+
/** Max software PWM frequency in Hz (default 1000). */
|
|
341
|
+
maxPwmFrequency?: number;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* GpioToolkit — Raspberry Pi GPIO control via node-libgpiod.
|
|
345
|
+
* Compatible with Pi 5 (chip 4) and Pi 4 (chip 0).
|
|
346
|
+
*
|
|
347
|
+
* Requires `node-libgpiod` as an optional peer dependency.
|
|
348
|
+
*/
|
|
349
|
+
declare class GpioToolkit extends Toolkit {
|
|
350
|
+
readonly name = "gpio";
|
|
351
|
+
private chipNumber;
|
|
352
|
+
private allowedPins;
|
|
353
|
+
private maxPwmFreq;
|
|
354
|
+
private activeWatchers;
|
|
355
|
+
constructor(config?: GpioConfig);
|
|
356
|
+
private assertPinAllowed;
|
|
357
|
+
getTools(): ToolDef[];
|
|
358
|
+
/** Stop all active watchers. */
|
|
359
|
+
dispose(): void;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
interface SensorConfig {
|
|
363
|
+
/** I2C bus number (default 1 — standard on all Pi models). */
|
|
364
|
+
busNumber?: number;
|
|
365
|
+
/** Override addresses for known sensor types. */
|
|
366
|
+
addresses?: {
|
|
367
|
+
bme280?: number;
|
|
368
|
+
bmp180?: number;
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* SensorToolkit — read I2C sensors (BME280, BMP180, DHT22) on Raspberry Pi.
|
|
373
|
+
* Requires `i2c-bus` as an optional peer dependency.
|
|
374
|
+
*/
|
|
375
|
+
declare class SensorToolkit extends Toolkit {
|
|
376
|
+
readonly name = "sensor";
|
|
377
|
+
private busNumber;
|
|
378
|
+
private bme280Addr;
|
|
379
|
+
constructor(config?: SensorConfig);
|
|
380
|
+
getTools(): ToolDef[];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
interface ServoConfig {
|
|
384
|
+
/** GPIO pin number for the servo signal. */
|
|
385
|
+
pin: number;
|
|
386
|
+
/** GPIO chip number (default 0, use 4 for Pi 5). */
|
|
387
|
+
chipNumber?: number;
|
|
388
|
+
/** Minimum pulse width in microseconds (default 500). */
|
|
389
|
+
minPulseUs?: number;
|
|
390
|
+
/** Maximum pulse width in microseconds (default 2500). */
|
|
391
|
+
maxPulseUs?: number;
|
|
392
|
+
/** PWM frequency in Hz (default 50 — standard for servos). */
|
|
393
|
+
frequency?: number;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* ServoToolkit — control hobby servos via GPIO PWM on Raspberry Pi.
|
|
397
|
+
* Requires `node-libgpiod` as an optional peer dependency.
|
|
398
|
+
*/
|
|
399
|
+
declare class ServoToolkit extends Toolkit {
|
|
400
|
+
readonly name = "servo";
|
|
401
|
+
private pin;
|
|
402
|
+
private chipNumber;
|
|
403
|
+
private minPulseUs;
|
|
404
|
+
private maxPulseUs;
|
|
405
|
+
private frequency;
|
|
406
|
+
constructor(config: ServoConfig);
|
|
407
|
+
private pulseForDuration;
|
|
408
|
+
getTools(): ToolDef[];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
interface SystemConfig {
|
|
412
|
+
/** Include per-process info in process list (default false — can be slow). */
|
|
413
|
+
includeProcessDetails?: boolean;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* SystemToolkit — zero-dependency system information tools.
|
|
417
|
+
* Reads from `/proc/`, `/sys/`, and the Node.js `os` module.
|
|
418
|
+
* Works on Linux (Raspberry Pi) and degrades gracefully on macOS/Windows.
|
|
419
|
+
*/
|
|
420
|
+
declare class SystemToolkit extends Toolkit {
|
|
421
|
+
readonly name = "system";
|
|
422
|
+
private includeProcessDetails;
|
|
423
|
+
constructor(config?: SystemConfig);
|
|
424
|
+
getTools(): ToolDef[];
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export { type BleConfig, BleToolkit, type CameraConfig, CameraToolkit, EdgeCloudSync, type EdgeCloudSyncConfig, type EdgePreset, EdgeRuntime, type EdgeRuntimeConfig, type EdgeRuntimeStatus, type GpioConfig, GpioToolkit, type ModelRecommendation, type OllamaStatus, ResourceMonitor, type ResourceSnapshot, type ResourceThresholds, type SensorConfig, SensorToolkit, type ServoConfig, ServoToolkit, type SystemConfig, SystemToolkit, checkOllama, customEdgePreset, edgePreset, ensureOllama, hasModel, listEdgePresets, listModelTiers, pullModel, recommendModel, registerEdgeToolkits };
|