atabey-shared 0.1.0-beta.0 → 0.1.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/README.md +63 -24
- package/dist/agent-identity.d.ts +1 -34
- package/dist/agent-identity.js +1 -76
- package/dist/agent-identity.js.map +1 -1
- package/dist/api-catalog.d.ts +1 -57
- package/dist/api-catalog.js +1 -253
- package/dist/api-catalog.js.map +1 -1
- package/dist/audit-chain.d.ts +1 -80
- package/dist/audit-chain.js +1 -261
- package/dist/audit-chain.js.map +1 -1
- package/dist/audit.d.ts +1 -121
- package/dist/audit.js +1 -321
- package/dist/audit.js.map +1 -1
- package/dist/constants.d.ts +1 -153
- package/dist/constants.js +1 -214
- package/dist/constants.js.map +1 -1
- package/dist/database.d.ts +1 -5
- package/dist/database.js +1 -12
- package/dist/database.js.map +1 -1
- package/dist/errors.d.ts +1 -46
- package/dist/errors.js +1 -68
- package/dist/errors.js.map +1 -1
- package/dist/file-lock.d.ts +1 -93
- package/dist/file-lock.js +1 -239
- package/dist/file-lock.js.map +1 -1
- package/dist/fs.d.ts +1 -9
- package/dist/fs.js +1 -53
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +2 -31
- package/dist/index.js +2 -31
- package/dist/index.js.map +1 -1
- package/dist/job-queue.d.ts +1 -53
- package/dist/job-queue.js +1 -126
- package/dist/job-queue.js.map +1 -1
- package/dist/lock.d.ts +1 -82
- package/dist/lock.js +1 -158
- package/dist/lock.js.map +1 -1
- package/dist/logger.d.ts +1 -31
- package/dist/logger.js +1 -152
- package/dist/logger.js.map +1 -1
- package/dist/memory-prune.d.ts +1 -18
- package/dist/memory-prune.js +1 -47
- package/dist/memory-prune.js.map +1 -1
- package/dist/migrations.d.ts +1 -69
- package/dist/migrations.js +1 -374
- package/dist/migrations.js.map +1 -1
- package/dist/modules/agent/agent-identity.d.ts +34 -0
- package/dist/modules/agent/agent-identity.js +77 -0
- package/dist/modules/agent/agent-identity.js.map +1 -0
- package/dist/modules/agent/api-catalog.d.ts +57 -0
- package/dist/modules/agent/api-catalog.js +254 -0
- package/dist/modules/agent/api-catalog.js.map +1 -0
- package/dist/modules/agent/index.d.ts +3 -0
- package/dist/modules/agent/index.js +4 -0
- package/dist/modules/agent/index.js.map +1 -0
- package/dist/modules/agent/tokenizer.d.ts +54 -0
- package/dist/modules/agent/tokenizer.js +272 -0
- package/dist/modules/agent/tokenizer.js.map +1 -0
- package/dist/modules/concurrency/file-lock.d.ts +93 -0
- package/dist/modules/concurrency/file-lock.js +240 -0
- package/dist/modules/concurrency/file-lock.js.map +1 -0
- package/dist/modules/concurrency/index.d.ts +6 -0
- package/dist/modules/concurrency/index.js +7 -0
- package/dist/modules/concurrency/index.js.map +1 -0
- package/dist/modules/concurrency/job-queue.d.ts +76 -0
- package/dist/modules/concurrency/job-queue.js +200 -0
- package/dist/modules/concurrency/job-queue.js.map +1 -0
- package/dist/modules/concurrency/lock.d.ts +82 -0
- package/dist/modules/concurrency/lock.js +159 -0
- package/dist/modules/concurrency/lock.js.map +1 -0
- package/dist/modules/concurrency/resilience.d.ts +84 -0
- package/dist/modules/concurrency/resilience.js +217 -0
- package/dist/modules/concurrency/resilience.js.map +1 -0
- package/dist/modules/concurrency/worker-pool.d.ts +52 -0
- package/dist/modules/concurrency/worker-pool.js +229 -0
- package/dist/modules/concurrency/worker-pool.js.map +1 -0
- package/dist/modules/concurrency/worker-thread.d.ts +21 -0
- package/dist/modules/concurrency/worker-thread.js +67 -0
- package/dist/modules/concurrency/worker-thread.js.map +1 -0
- package/dist/modules/index.d.ts +14 -0
- package/dist/modules/index.js +15 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/observability/audit-chain.d.ts +80 -0
- package/dist/modules/observability/audit-chain.js +262 -0
- package/dist/modules/observability/audit-chain.js.map +1 -0
- package/dist/modules/observability/audit.d.ts +121 -0
- package/dist/modules/observability/audit.js +322 -0
- package/dist/modules/observability/audit.js.map +1 -0
- package/dist/modules/observability/index.d.ts +4 -0
- package/dist/modules/observability/index.js +5 -0
- package/dist/modules/observability/index.js.map +1 -0
- package/dist/modules/observability/logger.d.ts +31 -0
- package/dist/modules/observability/logger.js +153 -0
- package/dist/modules/observability/logger.js.map +1 -0
- package/dist/modules/observability/otel.d.ts +39 -0
- package/dist/modules/observability/otel.js +93 -0
- package/dist/modules/observability/otel.js.map +1 -0
- package/dist/modules/primitives/constants.d.ts +150 -0
- package/dist/modules/primitives/constants.js +212 -0
- package/dist/modules/primitives/constants.js.map +1 -0
- package/dist/modules/primitives/errors.d.ts +46 -0
- package/dist/modules/primitives/errors.js +69 -0
- package/dist/modules/primitives/errors.js.map +1 -0
- package/dist/modules/primitives/fs.d.ts +9 -0
- package/dist/modules/primitives/fs.js +54 -0
- package/dist/modules/primitives/fs.js.map +1 -0
- package/dist/modules/primitives/index.d.ts +7 -0
- package/dist/modules/primitives/index.js +8 -0
- package/dist/modules/primitives/index.js.map +1 -0
- package/dist/modules/primitives/outbound-http.d.ts +32 -0
- package/dist/modules/primitives/outbound-http.js +88 -0
- package/dist/modules/primitives/outbound-http.js.map +1 -0
- package/dist/modules/primitives/string.d.ts +1 -0
- package/dist/modules/primitives/string.js +30 -0
- package/dist/modules/primitives/string.js.map +1 -0
- package/dist/modules/primitives/time.d.ts +5 -0
- package/dist/modules/primitives/time.js +35 -0
- package/dist/modules/primitives/time.js.map +1 -0
- package/dist/modules/primitives/types.d.ts +27 -0
- package/dist/modules/primitives/types.js +17 -0
- package/dist/modules/primitives/types.js.map +1 -0
- package/dist/modules/sandbox/index.d.ts +3 -0
- package/dist/modules/sandbox/index.js +4 -0
- package/dist/modules/sandbox/index.js.map +1 -0
- package/dist/modules/sandbox/sandbox-fs.d.ts +28 -0
- package/dist/modules/sandbox/sandbox-fs.js +143 -0
- package/dist/modules/sandbox/sandbox-fs.js.map +1 -0
- package/dist/modules/sandbox/sandbox-runtime.d.ts +78 -0
- package/dist/modules/sandbox/sandbox-runtime.js +282 -0
- package/dist/modules/sandbox/sandbox-runtime.js.map +1 -0
- package/dist/modules/sandbox/sandbox.d.ts +54 -0
- package/dist/modules/sandbox/sandbox.js +179 -0
- package/dist/modules/sandbox/sandbox.js.map +1 -0
- package/dist/modules/security/index.d.ts +5 -0
- package/dist/modules/security/index.js +6 -0
- package/dist/modules/security/index.js.map +1 -0
- package/dist/modules/security/pii.d.ts +70 -0
- package/dist/modules/security/pii.js +276 -0
- package/dist/modules/security/pii.js.map +1 -0
- package/dist/modules/security/policy-gate.d.ts +42 -0
- package/dist/modules/security/policy-gate.js +172 -0
- package/dist/modules/security/policy-gate.js.map +1 -0
- package/dist/modules/security/retention.d.ts +68 -0
- package/dist/modules/security/retention.js +218 -0
- package/dist/modules/security/retention.js.map +1 -0
- package/dist/modules/security/secrets.d.ts +99 -0
- package/dist/modules/security/secrets.js +371 -0
- package/dist/modules/security/secrets.js.map +1 -0
- package/dist/modules/security/tls.d.ts +87 -0
- package/dist/modules/security/tls.js +154 -0
- package/dist/modules/security/tls.js.map +1 -0
- package/dist/modules/storage/database.d.ts +6 -0
- package/dist/modules/storage/database.js +16 -0
- package/dist/modules/storage/database.js.map +1 -0
- package/dist/modules/storage/index.d.ts +4 -0
- package/dist/modules/storage/index.js +5 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/memory-prune.d.ts +18 -0
- package/dist/modules/storage/memory-prune.js +48 -0
- package/dist/modules/storage/memory-prune.js.map +1 -0
- package/dist/modules/storage/migrations.d.ts +69 -0
- package/dist/modules/storage/migrations.js +394 -0
- package/dist/modules/storage/migrations.js.map +1 -0
- package/dist/modules/storage/storage.d.ts +341 -0
- package/dist/modules/storage/storage.js +1004 -0
- package/dist/modules/storage/storage.js.map +1 -0
- package/dist/otel.d.ts +1 -39
- package/dist/otel.js +1 -92
- package/dist/otel.js.map +1 -1
- package/dist/outbound-http.d.ts +1 -32
- package/dist/outbound-http.js +1 -87
- package/dist/outbound-http.js.map +1 -1
- package/dist/pii.d.ts +1 -70
- package/dist/pii.js +1 -275
- package/dist/pii.js.map +1 -1
- package/dist/policy-gate.d.ts +1 -42
- package/dist/policy-gate.js +1 -171
- package/dist/policy-gate.js.map +1 -1
- package/dist/resilience.d.ts +1 -84
- package/dist/resilience.js +1 -216
- package/dist/resilience.js.map +1 -1
- package/dist/retention.d.ts +1 -68
- package/dist/retention.js +1 -217
- package/dist/retention.js.map +1 -1
- package/dist/sandbox-fs.d.ts +1 -28
- package/dist/sandbox-fs.js +1 -142
- package/dist/sandbox-fs.js.map +1 -1
- package/dist/sandbox-runtime.d.ts +1 -78
- package/dist/sandbox-runtime.js +1 -281
- package/dist/sandbox-runtime.js.map +1 -1
- package/dist/sandbox.d.ts +1 -54
- package/dist/sandbox.js +1 -178
- package/dist/sandbox.js.map +1 -1
- package/dist/secrets.d.ts +1 -99
- package/dist/secrets.js +1 -370
- package/dist/secrets.js.map +1 -1
- package/dist/storage.d.ts +1 -341
- package/dist/storage.js +1 -1003
- package/dist/storage.js.map +1 -1
- package/dist/string.d.ts +1 -1
- package/dist/string.js +1 -29
- package/dist/string.js.map +1 -1
- package/dist/time.d.ts +1 -5
- package/dist/time.js +1 -34
- package/dist/time.js.map +1 -1
- package/dist/tls.d.ts +1 -87
- package/dist/tls.js +1 -153
- package/dist/tls.js.map +1 -1
- package/dist/tokenizer.d.ts +1 -54
- package/dist/tokenizer.js +1 -271
- package/dist/tokenizer.js.map +1 -1
- package/dist/types.d.ts +1 -27
- package/dist/types.js +1 -16
- package/dist/types.js.map +1 -1
- package/dist/worker-pool.d.ts +1 -52
- package/dist/worker-pool.js +1 -228
- package/dist/worker-pool.js.map +1 -1
- package/dist/worker-thread.d.ts +1 -21
- package/dist/worker-thread.js +1 -66
- package/dist/worker-thread.js.map +1 -1
- package/package.json +44 -34
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Worker Pool — worker_threads based, no Redis/BullMQ.
|
|
3
|
+
*
|
|
4
|
+
* Heavy / isolable work runs off the main thread. Concurrency is capped
|
|
5
|
+
* (default os.cpus().length) via an internal queue so RAM/CPU stay bounded.
|
|
6
|
+
*
|
|
7
|
+
* Thread-safety note: SQLite (better-sqlite3) bindings are NOT thread-safe.
|
|
8
|
+
* Worker threads MUST NOT access AtabeyStorage or any SQLite connection.
|
|
9
|
+
* Only CPU-bound isolable work (hash, tokenize, etc.) should be dispatched
|
|
10
|
+
* to the worker pool.
|
|
11
|
+
*/
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
import os from "os";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
import { Worker } from "worker_threads";
|
|
17
|
+
function defaultWorkerScript() {
|
|
18
|
+
// Compiled ESM layout: dist/worker-thread.js next to this module
|
|
19
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const jsScript = path.join(here, "worker-thread.js");
|
|
21
|
+
const tsScript = path.join(here, "worker-thread.ts");
|
|
22
|
+
// Prefer compiled JS; fall back to TS for dev (tsx/ts-node)
|
|
23
|
+
if (fs.existsSync(jsScript))
|
|
24
|
+
return jsScript;
|
|
25
|
+
if (fs.existsSync(tsScript))
|
|
26
|
+
return tsScript;
|
|
27
|
+
// Fallback: try resolving via import.meta.resolve for monorepo layouts
|
|
28
|
+
try {
|
|
29
|
+
const resolved = import.meta.resolve("./worker-thread.js");
|
|
30
|
+
if (resolved)
|
|
31
|
+
return new URL(resolved).pathname;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// ignore
|
|
35
|
+
}
|
|
36
|
+
return jsScript;
|
|
37
|
+
}
|
|
38
|
+
export class WorkerPool {
|
|
39
|
+
maxConcurrency;
|
|
40
|
+
minWorkers;
|
|
41
|
+
jobTimeoutMs;
|
|
42
|
+
workerScript;
|
|
43
|
+
workers = [];
|
|
44
|
+
queue = [];
|
|
45
|
+
inflight = new Map();
|
|
46
|
+
jobSeq = 0;
|
|
47
|
+
closed = false;
|
|
48
|
+
constructor(options = {}) {
|
|
49
|
+
const cpus = Math.max(1, os.cpus()?.length || 1);
|
|
50
|
+
const requested = options.maxConcurrency ?? cpus;
|
|
51
|
+
this.maxConcurrency = Math.max(1, Math.min(requested, 16));
|
|
52
|
+
this.minWorkers = Math.max(0, Math.min(options.minWorkers ?? Math.min(2, this.maxConcurrency), this.maxConcurrency));
|
|
53
|
+
this.jobTimeoutMs = options.jobTimeoutMs ?? 30_000;
|
|
54
|
+
this.workerScript = options.workerScript ?? defaultWorkerScript();
|
|
55
|
+
for (let i = 0; i < this.minWorkers; i++) {
|
|
56
|
+
this.spawnWorker();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Run a named job type on a worker thread.
|
|
61
|
+
* Returns when the worker posts a result (or on timeout/error).
|
|
62
|
+
*/
|
|
63
|
+
run(type, payload) {
|
|
64
|
+
if (this.closed) {
|
|
65
|
+
return Promise.reject(new Error("[WorkerPool] Pool is closed."));
|
|
66
|
+
}
|
|
67
|
+
const id = `wjob-${++this.jobSeq}-${Date.now()}`;
|
|
68
|
+
const job = { id, type, payload };
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const timer = setTimeout(() => {
|
|
71
|
+
this.inflight.delete(id);
|
|
72
|
+
// Free (and recycle) the worker stuck on this job so a hung job
|
|
73
|
+
// cannot permanently occupy the pool and deadlock every caller.
|
|
74
|
+
const stuck = this.workers.find((w) => w.currentJobId === id);
|
|
75
|
+
if (stuck) {
|
|
76
|
+
stuck.busy = false;
|
|
77
|
+
stuck.currentJobId = null;
|
|
78
|
+
this.removeWorker(stuck);
|
|
79
|
+
void stuck.worker.terminate().catch(() => { });
|
|
80
|
+
}
|
|
81
|
+
reject(new Error(`[WorkerPool] Job ${id} timed out after ${this.jobTimeoutMs}ms`));
|
|
82
|
+
this.dispatch();
|
|
83
|
+
if (!this.closed && this.workers.length < this.minWorkers) {
|
|
84
|
+
this.spawnWorker();
|
|
85
|
+
}
|
|
86
|
+
}, this.jobTimeoutMs);
|
|
87
|
+
const pending = {
|
|
88
|
+
job,
|
|
89
|
+
resolve: (v) => resolve(v),
|
|
90
|
+
reject,
|
|
91
|
+
timer,
|
|
92
|
+
};
|
|
93
|
+
this.queue.push(pending);
|
|
94
|
+
this.dispatch();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getStats() {
|
|
98
|
+
return {
|
|
99
|
+
maxConcurrency: this.maxConcurrency,
|
|
100
|
+
workers: this.workers.length,
|
|
101
|
+
busy: this.workers.filter((w) => w.busy).length,
|
|
102
|
+
pending: this.queue.length,
|
|
103
|
+
inflight: this.inflight.size,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async close() {
|
|
107
|
+
this.closed = true;
|
|
108
|
+
while (this.queue.length > 0) {
|
|
109
|
+
const p = this.queue.shift();
|
|
110
|
+
if (p) {
|
|
111
|
+
clearTimeout(p.timer);
|
|
112
|
+
p.reject(new Error("[WorkerPool] Pool closed while job was queued."));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Settle any in-flight jobs so their awaiters don't hang forever.
|
|
116
|
+
for (const pending of this.inflight.values()) {
|
|
117
|
+
clearTimeout(pending.timer);
|
|
118
|
+
pending.reject(new Error("[WorkerPool] Pool closed while the job was in flight."));
|
|
119
|
+
}
|
|
120
|
+
this.inflight.clear();
|
|
121
|
+
await Promise.all(this.workers.map((pw) => new Promise((resolve) => {
|
|
122
|
+
pw.worker.once("exit", () => resolve());
|
|
123
|
+
void pw.worker.terminate();
|
|
124
|
+
})));
|
|
125
|
+
this.workers.length = 0;
|
|
126
|
+
}
|
|
127
|
+
failWorkerJob(pw, error) {
|
|
128
|
+
const jobId = pw.currentJobId;
|
|
129
|
+
pw.busy = false;
|
|
130
|
+
pw.currentJobId = null;
|
|
131
|
+
if (!jobId)
|
|
132
|
+
return;
|
|
133
|
+
const pending = this.inflight.get(jobId);
|
|
134
|
+
if (!pending)
|
|
135
|
+
return;
|
|
136
|
+
clearTimeout(pending.timer);
|
|
137
|
+
this.inflight.delete(jobId);
|
|
138
|
+
pending.reject(error);
|
|
139
|
+
}
|
|
140
|
+
spawnWorker() {
|
|
141
|
+
const worker = new Worker(this.workerScript);
|
|
142
|
+
const pw = { worker, busy: false, currentJobId: null };
|
|
143
|
+
worker.on("message", (msg) => {
|
|
144
|
+
const pending = this.inflight.get(msg.id);
|
|
145
|
+
pw.busy = false;
|
|
146
|
+
pw.currentJobId = null;
|
|
147
|
+
if (!pending) {
|
|
148
|
+
this.dispatch();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
clearTimeout(pending.timer);
|
|
152
|
+
this.inflight.delete(msg.id);
|
|
153
|
+
if (msg.ok) {
|
|
154
|
+
pending.resolve(msg.result);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
pending.reject(new Error(msg.error || "Worker job failed"));
|
|
158
|
+
}
|
|
159
|
+
this.dispatch();
|
|
160
|
+
});
|
|
161
|
+
worker.on("error", (err) => {
|
|
162
|
+
this.failWorkerJob(pw, err instanceof Error ? err : new Error(String(err)));
|
|
163
|
+
this.removeWorker(pw);
|
|
164
|
+
if (!this.closed) {
|
|
165
|
+
this.spawnWorker();
|
|
166
|
+
}
|
|
167
|
+
this.dispatch();
|
|
168
|
+
});
|
|
169
|
+
worker.on("exit", (code) => {
|
|
170
|
+
if (pw.busy && pw.currentJobId) {
|
|
171
|
+
this.failWorkerJob(pw, new Error(`[WorkerPool] Worker exited with code ${code} while running job ${pw.currentJobId}`));
|
|
172
|
+
}
|
|
173
|
+
this.removeWorker(pw);
|
|
174
|
+
if (!this.closed && code !== 0) {
|
|
175
|
+
// Replace crashed worker so pool size recovers
|
|
176
|
+
if (this.workers.length < this.minWorkers) {
|
|
177
|
+
this.spawnWorker();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this.dispatch();
|
|
181
|
+
});
|
|
182
|
+
this.workers.push(pw);
|
|
183
|
+
return pw;
|
|
184
|
+
}
|
|
185
|
+
removeWorker(pw) {
|
|
186
|
+
const idx = this.workers.indexOf(pw);
|
|
187
|
+
if (idx >= 0)
|
|
188
|
+
this.workers.splice(idx, 1);
|
|
189
|
+
}
|
|
190
|
+
dispatch() {
|
|
191
|
+
if (this.closed)
|
|
192
|
+
return;
|
|
193
|
+
while (this.queue.length > 0) {
|
|
194
|
+
let free = this.workers.find((w) => !w.busy);
|
|
195
|
+
if (!free && this.workers.length < this.maxConcurrency) {
|
|
196
|
+
free = this.spawnWorker();
|
|
197
|
+
}
|
|
198
|
+
if (!free)
|
|
199
|
+
break;
|
|
200
|
+
const pending = this.queue.shift();
|
|
201
|
+
if (!pending)
|
|
202
|
+
break;
|
|
203
|
+
free.busy = true;
|
|
204
|
+
free.currentJobId = pending.job.id;
|
|
205
|
+
this.inflight.set(pending.job.id, pending);
|
|
206
|
+
free.worker.postMessage(pending.job);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let defaultPool = null;
|
|
211
|
+
export function getDefaultWorkerPool(options) {
|
|
212
|
+
if (!defaultPool) {
|
|
213
|
+
const fromEnv = process.env.ATABEY_WORKER_CONCURRENCY
|
|
214
|
+
? parseInt(process.env.ATABEY_WORKER_CONCURRENCY, 10)
|
|
215
|
+
: undefined;
|
|
216
|
+
defaultPool = new WorkerPool({
|
|
217
|
+
maxConcurrency: options?.maxConcurrency ?? (Number.isFinite(fromEnv) ? fromEnv : undefined),
|
|
218
|
+
...options,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return defaultPool;
|
|
222
|
+
}
|
|
223
|
+
export async function resetDefaultWorkerPool() {
|
|
224
|
+
if (defaultPool) {
|
|
225
|
+
await defaultPool.close();
|
|
226
|
+
defaultPool = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../src/modules/concurrency/worker-pool.ts"],"names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OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;CACJ;AAED,IAAI,WAAW,GAAsB,IAAI,CAAC;AAE1C,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC5D,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB;YACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,EAAE,CAAC;YACrD,CAAC,CAAC,SAAS,CAAC;QAChB,WAAW,GAAG,IAAI,UAAU,CAAC;YACzB,cAAc,EAAE,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;YAC3F,GAAG,OAAO;SACb,CAAC,CAAC;IACP,CAAC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB;IACxC,IAAI,WAAW,EAAE,CAAC;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAC1B,WAAW,GAAG,IAAI,CAAC;IACvB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic worker_threads entrypoint for Atabey WorkerPool.
|
|
3
|
+
* Receives serializable jobs and returns serializable results.
|
|
4
|
+
*
|
|
5
|
+
* Supported job types (extensible):
|
|
6
|
+
* - "ping" — health check
|
|
7
|
+
* - "hash" — simple string hash (CPU sample)
|
|
8
|
+
* - "tokenize" — tokenization for TF-IDF style work
|
|
9
|
+
* - "sleep" — test helper
|
|
10
|
+
*/
|
|
11
|
+
export interface WorkerJob {
|
|
12
|
+
id: string;
|
|
13
|
+
type: string;
|
|
14
|
+
payload?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface WorkerResult {
|
|
17
|
+
id: string;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
result?: unknown;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic worker_threads entrypoint for Atabey WorkerPool.
|
|
3
|
+
* Receives serializable jobs and returns serializable results.
|
|
4
|
+
*
|
|
5
|
+
* Supported job types (extensible):
|
|
6
|
+
* - "ping" — health check
|
|
7
|
+
* - "hash" — simple string hash (CPU sample)
|
|
8
|
+
* - "tokenize" — tokenization for TF-IDF style work
|
|
9
|
+
* - "sleep" — test helper
|
|
10
|
+
*/
|
|
11
|
+
import { parentPort } from "worker_threads";
|
|
12
|
+
function tokenize(text) {
|
|
13
|
+
return text
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.replace(/[^\w\s-]/g, " ")
|
|
16
|
+
.split(/\s+/)
|
|
17
|
+
.filter((t) => t.length > 1);
|
|
18
|
+
}
|
|
19
|
+
function simpleHash(input) {
|
|
20
|
+
let h = 0;
|
|
21
|
+
for (let i = 0; i < input.length; i++) {
|
|
22
|
+
h = (Math.imul(31, h) + input.charCodeAt(i)) | 0;
|
|
23
|
+
}
|
|
24
|
+
return h >>> 0;
|
|
25
|
+
}
|
|
26
|
+
async function handleJob(job) {
|
|
27
|
+
switch (job.type) {
|
|
28
|
+
case "ping":
|
|
29
|
+
return { pong: true, pid: process.pid, ts: Date.now() };
|
|
30
|
+
case "hash": {
|
|
31
|
+
const text = String(job.payload?.text ?? "");
|
|
32
|
+
return { hash: simpleHash(text), length: text.length };
|
|
33
|
+
}
|
|
34
|
+
case "tokenize": {
|
|
35
|
+
const text = String(job.payload?.text ?? "");
|
|
36
|
+
const tokens = tokenize(text);
|
|
37
|
+
return { tokens, count: tokens.length };
|
|
38
|
+
}
|
|
39
|
+
case "sleep": {
|
|
40
|
+
const ms = Math.min(10_000, Math.max(0, Number(job.payload?.ms ?? 0)));
|
|
41
|
+
await new Promise((r) => setTimeout(r, ms));
|
|
42
|
+
return { slept: ms };
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Unknown worker job type: ${job.type}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (parentPort) {
|
|
49
|
+
parentPort.on("message", (job) => {
|
|
50
|
+
void (async () => {
|
|
51
|
+
try {
|
|
52
|
+
const result = await handleJob(job);
|
|
53
|
+
const msg = { id: job.id, ok: true, result };
|
|
54
|
+
parentPort.postMessage(msg);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const msg = {
|
|
58
|
+
id: job.id,
|
|
59
|
+
ok: false,
|
|
60
|
+
error: err instanceof Error ? err.message : String(err),
|
|
61
|
+
};
|
|
62
|
+
parentPort.postMessage(msg);
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=worker-thread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-thread.js","sourceRoot":"","sources":["../../../src/modules/concurrency/worker-thread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAe5C,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI;SACN,WAAW,EAAE;SACb,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;SACzB,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC7B,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;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AC,CAAC;YAC5C,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QACzB,CAAC;QAED;YACI,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;AACL,CAAC;AAED,IAAI,UAAU,EAAE,CAAC;IACb,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAc,EAAE,EAAE;QACxC,KAAK,CAAC,KAAK,IAAI,EAAE;YACb,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;gBACpC,MAAM,GAAG,GAAiB,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBAC3D,UAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,MAAM,GAAG,GAAiB;oBACtB,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;iBAC1D,CAAC;gBACF,UAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;QACL,CAAC,CAAC,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./storage/index.js";
|
|
2
|
+
export * from "./security/index.js";
|
|
3
|
+
export * from "./concurrency/index.js";
|
|
4
|
+
export * from "./sandbox/index.js";
|
|
5
|
+
export * from "./observability/index.js";
|
|
6
|
+
export * from "./agent/index.js";
|
|
7
|
+
export * from "./primitives/index.js";
|
|
8
|
+
export * as Storage from "./storage/index.js";
|
|
9
|
+
export * as Security from "./security/index.js";
|
|
10
|
+
export * as Concurrency from "./concurrency/index.js";
|
|
11
|
+
export * as Sandbox from "./sandbox/index.js";
|
|
12
|
+
export * as Observability from "./observability/index.js";
|
|
13
|
+
export * as Agent from "./agent/index.js";
|
|
14
|
+
export * as Primitives from "./primitives/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./storage/index.js";
|
|
2
|
+
export * from "./security/index.js";
|
|
3
|
+
export * from "./concurrency/index.js";
|
|
4
|
+
export * from "./sandbox/index.js";
|
|
5
|
+
export * from "./observability/index.js";
|
|
6
|
+
export * from "./agent/index.js";
|
|
7
|
+
export * from "./primitives/index.js";
|
|
8
|
+
export * as Storage from "./storage/index.js";
|
|
9
|
+
export * as Security from "./security/index.js";
|
|
10
|
+
export * as Concurrency from "./concurrency/index.js";
|
|
11
|
+
export * as Sandbox from "./sandbox/index.js";
|
|
12
|
+
export * as Observability from "./observability/index.js";
|
|
13
|
+
export * as Agent from "./agent/index.js";
|
|
14
|
+
export * as Primitives from "./primitives/index.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tamper-evident audit hash chain helpers (Phase 1.4).
|
|
3
|
+
*
|
|
4
|
+
* Chain: each entry stores prev_hash (previous entry hash or GENESIS) and hash = SHA-256(payload).
|
|
5
|
+
* Any mutation of historical rows fails verification.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AUDIT_CHAIN_GENESIS = "GENESIS";
|
|
8
|
+
export declare function resolveAuditChainKey(): Buffer | null;
|
|
9
|
+
/** Test helper — clears the memoized key. */
|
|
10
|
+
export declare function clearAuditChainKeyCache(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Keyed digest for audit chain entries.
|
|
13
|
+
* Uses HMAC-SHA256 when a key is available; otherwise falls back to plain
|
|
14
|
+
* SHA-256 with a one-time warning (degraded, not recommended).
|
|
15
|
+
*/
|
|
16
|
+
export declare function chainDigest(payload: string): string;
|
|
17
|
+
/** @deprecated Use chainDigest() — unkeyed SHA-256 is not tamper-evident. */
|
|
18
|
+
export declare function sha256Hex(payload: string): string;
|
|
19
|
+
export interface ChainAnchor {
|
|
20
|
+
tip: string;
|
|
21
|
+
count: number;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function writeChainAnchor(name: string, tip: string, count: number): void;
|
|
25
|
+
export declare function readChainAnchor(name: string): ChainAnchor | null;
|
|
26
|
+
export declare function clearChainAnchor(name: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Canonical payload for agent execution logs (Storage.saveLog).
|
|
29
|
+
*
|
|
30
|
+
* v2: fields are length-delimited via JSON to remove `|`-join boundary
|
|
31
|
+
* ambiguity (previously agent="a|b" collided with action="b|c"). Changing this
|
|
32
|
+
* invalidates verification of rows written by older (v1) builds.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildAgentLogChainPayload(fields: {
|
|
35
|
+
prevHash: string;
|
|
36
|
+
agent: string;
|
|
37
|
+
action: string;
|
|
38
|
+
traceId: string;
|
|
39
|
+
status: string;
|
|
40
|
+
summary: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
}): string;
|
|
43
|
+
/**
|
|
44
|
+
* Canonical payload for structured Audit.log entries (v2, length-delimited).
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildStructuredAuditChainPayload(fields: {
|
|
47
|
+
prevHash: string;
|
|
48
|
+
agent: string;
|
|
49
|
+
action: string;
|
|
50
|
+
status: string;
|
|
51
|
+
traceId: string;
|
|
52
|
+
timestamp: string;
|
|
53
|
+
detailsJson: string;
|
|
54
|
+
errorMessage: string;
|
|
55
|
+
}): string;
|
|
56
|
+
export interface ChainRow {
|
|
57
|
+
id: number;
|
|
58
|
+
prev_hash: string | null;
|
|
59
|
+
hash: string | null;
|
|
60
|
+
}
|
|
61
|
+
export interface ChainVerifyResult {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
checked: number;
|
|
64
|
+
failedLogId?: number;
|
|
65
|
+
reason?: string;
|
|
66
|
+
tip?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Verify a sequence of rows already ordered by id ASC.
|
|
70
|
+
* `computePayload(row, prevHash)` must rebuild the exact string used at insert time.
|
|
71
|
+
*
|
|
72
|
+
* @param options.digest keyed digest used at insert time (default: chainDigest)
|
|
73
|
+
* @param options.expectedTip last appended hash (from an external anchor) — detects truncation
|
|
74
|
+
* @param options.expectedCount number of chained rows expected — detects deletion at the tail
|
|
75
|
+
*/
|
|
76
|
+
export declare function verifyHashChain<T extends ChainRow>(rows: T[], computePayload: (row: T, prevHash: string) => string, options?: {
|
|
77
|
+
digest?: (payload: string) => string;
|
|
78
|
+
expectedTip?: string;
|
|
79
|
+
expectedCount?: number;
|
|
80
|
+
}): ChainVerifyResult;
|