@trillboards/edge-core 0.2.2 → 0.2.3
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/MemoryAttenuationManager.d.ts +164 -0
- package/dist/MemoryAttenuationManager.d.ts.map +1 -0
- package/dist/MemoryAttenuationManager.js +400 -0
- package/dist/MemoryAttenuationManager.js.map +1 -0
- package/dist/ModelManager.d.ts +166 -0
- package/dist/ModelManager.d.ts.map +1 -0
- package/dist/ModelManager.js +580 -0
- package/dist/ModelManager.js.map +1 -0
- package/dist/StatusServer.d.ts +99 -0
- package/dist/StatusServer.d.ts.map +1 -0
- package/dist/StatusServer.js +262 -0
- package/dist/StatusServer.js.map +1 -0
- package/dist/ZKAudienceProver.d.ts +137 -0
- package/dist/ZKAudienceProver.d.ts.map +1 -0
- package/dist/ZKAudienceProver.js +321 -0
- package/dist/ZKAudienceProver.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModelManager — Model lifecycle management with OTA (over-the-air) updates.
|
|
3
|
+
* Port of CTV agent's ModelManager.kt (387 lines), adapted for Node.js/ONNX.
|
|
4
|
+
*
|
|
5
|
+
* Manages registration, version-checking, and atomic download of ML model files.
|
|
6
|
+
* Downloads use a .tmp + rename pattern to prevent corrupted model loads.
|
|
7
|
+
* The version check timer is unref()'d so it does not keep the process alive.
|
|
8
|
+
*
|
|
9
|
+
* Events emitted:
|
|
10
|
+
* 'modelUpdated' — { name, oldVersion, newVersion, path }
|
|
11
|
+
* 'updateAvailable' — { name, currentVersion, availableVersion }
|
|
12
|
+
* 'downloadProgress' — { name, bytesDownloaded, totalBytes, percent }
|
|
13
|
+
* 'downloadError' — { name, error }
|
|
14
|
+
* 'checkComplete' — { checkedCount, updatesAvailable }
|
|
15
|
+
*/
|
|
16
|
+
/// <reference types="node" />
|
|
17
|
+
import { EventEmitter } from 'events';
|
|
18
|
+
export interface ModelInfo {
|
|
19
|
+
/** Model identifier, e.g. 'blazeface', 'yamnet', 'ageGender'. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Semver version string, e.g. '1.2.0'. */
|
|
22
|
+
version: string;
|
|
23
|
+
/** Absolute path to the .onnx file on disk. */
|
|
24
|
+
filePath: string;
|
|
25
|
+
/** SHA-256 hex digest of the current file. */
|
|
26
|
+
sha256: string;
|
|
27
|
+
/** File size in bytes. */
|
|
28
|
+
sizeBytes: number;
|
|
29
|
+
/** Timestamp (ms) of last version check against the API. */
|
|
30
|
+
lastChecked: number;
|
|
31
|
+
/** Timestamp (ms) of last successful download. */
|
|
32
|
+
lastUpdated: number;
|
|
33
|
+
}
|
|
34
|
+
export interface ModelVersionResponse {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
sha256: string;
|
|
38
|
+
downloadUrl: string;
|
|
39
|
+
sizeBytes: number;
|
|
40
|
+
releaseNotes?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ModelManagerOptions {
|
|
43
|
+
/** Directory for storing model files and manifest. */
|
|
44
|
+
modelsDir: string;
|
|
45
|
+
/** Backend API base URL (e.g. 'https://api.trillboards.com'). */
|
|
46
|
+
apiBaseUrl: string;
|
|
47
|
+
/** Device fingerprint for the version-check API call. */
|
|
48
|
+
deviceFingerprint: string;
|
|
49
|
+
/** Interval between automatic version checks. Default: 3600000 (1 hour). */
|
|
50
|
+
checkIntervalMs?: number;
|
|
51
|
+
/** Maximum concurrent model downloads. Default: 1. */
|
|
52
|
+
maxConcurrentDownloads?: number;
|
|
53
|
+
/** Whether to auto-download discovered updates. Default: true. */
|
|
54
|
+
autoUpdate?: boolean;
|
|
55
|
+
/** Request timeout for API calls in milliseconds. Default: 30000. */
|
|
56
|
+
requestTimeoutMs?: number;
|
|
57
|
+
/** Request timeout for file downloads in milliseconds. Default: 300000 (5 min). */
|
|
58
|
+
downloadTimeoutMs?: number;
|
|
59
|
+
/** Maximum number of HTTP redirects to follow. Default: 5. */
|
|
60
|
+
maxRedirects?: number;
|
|
61
|
+
}
|
|
62
|
+
export declare class ModelManager extends EventEmitter {
|
|
63
|
+
private models;
|
|
64
|
+
private readonly options;
|
|
65
|
+
private checkTimer;
|
|
66
|
+
private downloading;
|
|
67
|
+
private readonly manifestPath;
|
|
68
|
+
constructor(options: ModelManagerOptions);
|
|
69
|
+
/**
|
|
70
|
+
* Initialize — ensure models directory exists, load manifest, compute
|
|
71
|
+
* hashes for any registered model files already on disk.
|
|
72
|
+
*/
|
|
73
|
+
initialize(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Start periodic version checking. The timer is unref()'d so it does not
|
|
76
|
+
* prevent the Node.js process from exiting naturally.
|
|
77
|
+
*/
|
|
78
|
+
start(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Stop periodic checking and cancel any in-flight state tracking.
|
|
81
|
+
*/
|
|
82
|
+
stop(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Register a model to track. Called during EdgeAgent init for each model type.
|
|
85
|
+
* If the file exists on disk, its SHA-256 is computed immediately.
|
|
86
|
+
* If the manifest already has version info for this name, it is merged.
|
|
87
|
+
*/
|
|
88
|
+
registerModel(name: string, filePath: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Check for updates for all registered models by calling the backend API.
|
|
91
|
+
* Endpoint: GET /v1/federated/models?deviceFingerprint=X&modelType=Y
|
|
92
|
+
*
|
|
93
|
+
* Returns the list of ModelVersionResponse objects for which a newer
|
|
94
|
+
* version is available. If autoUpdate is enabled, downloads are
|
|
95
|
+
* initiated automatically (respecting maxConcurrentDownloads).
|
|
96
|
+
*/
|
|
97
|
+
checkForUpdates(): Promise<ModelVersionResponse[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Download a specific model update.
|
|
100
|
+
*
|
|
101
|
+
* 1. Download to a .tmp file alongside the target path
|
|
102
|
+
* 2. Verify SHA-256 checksum matches the expected value
|
|
103
|
+
* 3. Atomic swap: rename .tmp -> target .onnx path
|
|
104
|
+
* 4. Update manifest with new version info
|
|
105
|
+
* 5. Emit 'modelUpdated' event
|
|
106
|
+
*
|
|
107
|
+
* Returns true if the model was successfully downloaded and verified.
|
|
108
|
+
*/
|
|
109
|
+
downloadUpdate(update: ModelVersionResponse): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Get info about a registered model. Returns null if not registered.
|
|
112
|
+
*/
|
|
113
|
+
getModel(name: string): ModelInfo | null;
|
|
114
|
+
/**
|
|
115
|
+
* Get all registered models.
|
|
116
|
+
*/
|
|
117
|
+
getModels(): ModelInfo[];
|
|
118
|
+
/**
|
|
119
|
+
* Check if a model's file exists on disk.
|
|
120
|
+
*/
|
|
121
|
+
hasModel(name: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Check if a download is currently in progress for a model.
|
|
124
|
+
*/
|
|
125
|
+
isDownloading(name: string): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Compute the SHA-256 hex digest of a file using a streaming reader.
|
|
128
|
+
*/
|
|
129
|
+
private computeFileHash;
|
|
130
|
+
/**
|
|
131
|
+
* Download a file from a URL to a local destination path.
|
|
132
|
+
* Follows HTTP redirects (up to maxRedirects), emits progress events,
|
|
133
|
+
* and enforces a download timeout.
|
|
134
|
+
*/
|
|
135
|
+
private downloadFile;
|
|
136
|
+
private downloadFileWithRedirects;
|
|
137
|
+
/**
|
|
138
|
+
* Load model manifest from disk. If the file does not exist or is corrupt,
|
|
139
|
+
* start with an empty manifest — never crash.
|
|
140
|
+
*/
|
|
141
|
+
private loadManifest;
|
|
142
|
+
/**
|
|
143
|
+
* Save the current model state to the manifest file on disk.
|
|
144
|
+
* Uses atomic write: write to .tmp, then rename.
|
|
145
|
+
*/
|
|
146
|
+
private saveManifest;
|
|
147
|
+
/**
|
|
148
|
+
* Make an HTTPS GET request to the backend API and return parsed JSON.
|
|
149
|
+
*/
|
|
150
|
+
private apiGet;
|
|
151
|
+
/**
|
|
152
|
+
* Verify that a model file exists on disk, recompute its hash if present,
|
|
153
|
+
* or clear stale info if the file has been deleted.
|
|
154
|
+
*/
|
|
155
|
+
private verifyModelOnDisk;
|
|
156
|
+
/**
|
|
157
|
+
* Semver comparison: returns true if `available` is strictly newer than `current`.
|
|
158
|
+
* Handles non-semver gracefully by falling back to string comparison.
|
|
159
|
+
*/
|
|
160
|
+
private isNewerVersion;
|
|
161
|
+
/**
|
|
162
|
+
* Safely remove a .tmp file if it exists. Never throws.
|
|
163
|
+
*/
|
|
164
|
+
private cleanupTmpFile;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=ModelManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelManager.d.ts","sourceRoot":"","sources":["../src/ModelManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAStC,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,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