@xdarkicex/openclaw-memory-libravdb 1.5.5 → 1.6.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/dist/cli.js +19 -21
- package/dist/context-engine.d.ts +3 -3
- package/dist/context-engine.js +19 -123
- package/dist/dream-promotion.d.ts +4 -6
- package/dist/dream-promotion.js +22 -13
- package/dist/index.js +25240 -29191
- package/dist/ingest-queue.d.ts +9 -2
- package/dist/ingest-queue.js +13 -5
- package/dist/libravdb-client.d.ts +59 -0
- package/dist/libravdb-client.js +296 -0
- package/dist/markdown-ingest.d.ts +2 -5
- package/dist/markdown-ingest.js +40 -8
- package/dist/memory-provider.d.ts +2 -2
- package/dist/memory-provider.js +1 -1
- package/dist/memory-runtime.d.ts +4 -33
- package/dist/memory-runtime.js +40 -51
- package/dist/plugin-runtime.d.ts +4 -6
- package/dist/plugin-runtime.js +33 -72
- package/dist/types.d.ts +1 -21
- package/openclaw.plugin.json +1 -1
- package/package.json +7 -4
- package/dist/grpc-client.d.ts +0 -44
- package/dist/grpc-client.js +0 -188
- package/dist/rpc-protobuf-codecs.d.ts +0 -71
- package/dist/rpc-protobuf-codecs.js +0 -91
- package/dist/rpc.d.ts +0 -15
- package/dist/rpc.js +0 -203
- package/dist/sidecar.d.ts +0 -40
- package/dist/sidecar.js +0 -588
package/dist/sidecar.js
DELETED
|
@@ -1,588 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import net from "node:net";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
const STARTUP_CONNECT_MAX_RETRIES = 5;
|
|
6
|
-
const STARTUP_CONNECT_BASE_DELAY_MS = 100;
|
|
7
|
-
const STARTUP_CONNECT_MAX_TOTAL_WAIT_MS = 2000;
|
|
8
|
-
const CONNECTION_STABILITY_WINDOW_MS = 15_000;
|
|
9
|
-
class PlaceholderSocket {
|
|
10
|
-
onData = new Set();
|
|
11
|
-
onClose = new Set();
|
|
12
|
-
onError = new Set();
|
|
13
|
-
connectOnce = new Set();
|
|
14
|
-
errorOnce = new Set();
|
|
15
|
-
constructor() {
|
|
16
|
-
queueMicrotask(() => {
|
|
17
|
-
for (const handler of this.connectOnce) {
|
|
18
|
-
handler();
|
|
19
|
-
}
|
|
20
|
-
this.connectOnce.clear();
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
setEncoding(_encoding) { }
|
|
24
|
-
on(event, handler) {
|
|
25
|
-
if (event === "data") {
|
|
26
|
-
this.onData.add(handler);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (event === "error") {
|
|
30
|
-
this.onError.add(handler);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.onClose.add(handler);
|
|
34
|
-
}
|
|
35
|
-
once(event, handler) {
|
|
36
|
-
if (event === "connect") {
|
|
37
|
-
this.connectOnce.add(handler);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
this.errorOnce.add(handler);
|
|
41
|
-
}
|
|
42
|
-
off(event, handler) {
|
|
43
|
-
if (event === "connect") {
|
|
44
|
-
this.connectOnce.delete(handler);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.errorOnce.delete(handler);
|
|
48
|
-
}
|
|
49
|
-
write(chunk) {
|
|
50
|
-
try {
|
|
51
|
-
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, "utf8");
|
|
52
|
-
let offset = 0;
|
|
53
|
-
// Consume the one-time magic byte if present
|
|
54
|
-
if (buf.byteLength > 0 && buf[0] === 0x02)
|
|
55
|
-
offset = 1;
|
|
56
|
-
// Parse length-prefixed frames
|
|
57
|
-
while (offset + 4 <= buf.byteLength) {
|
|
58
|
-
const len = buf.readUInt32BE(offset);
|
|
59
|
-
offset += 4;
|
|
60
|
-
if (offset + len > buf.byteLength)
|
|
61
|
-
break;
|
|
62
|
-
const msg = JSON.parse(buf.subarray(offset, offset + len).toString("utf8"));
|
|
63
|
-
offset += len;
|
|
64
|
-
const responseJson = JSON.stringify({
|
|
65
|
-
jsonrpc: "2.0",
|
|
66
|
-
id: msg.id,
|
|
67
|
-
result: msg.method === "health" ? { ok: true } : {},
|
|
68
|
-
});
|
|
69
|
-
// Emit as a properly framed binary response
|
|
70
|
-
const payload = Buffer.from(responseJson, "utf8");
|
|
71
|
-
const header = Buffer.alloc(4);
|
|
72
|
-
header.writeUInt32BE(payload.byteLength, 0);
|
|
73
|
-
const frame = Buffer.concat([header, payload]);
|
|
74
|
-
for (const handler of this.onData) {
|
|
75
|
-
handler(frame);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
81
|
-
this.emitError(err);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
destroy() {
|
|
85
|
-
for (const handler of this.onClose) {
|
|
86
|
-
handler();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
emitError(error) {
|
|
90
|
-
for (const handler of this.onError) {
|
|
91
|
-
handler(error);
|
|
92
|
-
}
|
|
93
|
-
for (const handler of this.errorOnce) {
|
|
94
|
-
handler(error);
|
|
95
|
-
}
|
|
96
|
-
this.errorOnce.clear();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
class SupervisorSocket {
|
|
100
|
-
onData = new Set();
|
|
101
|
-
onClose = new Set();
|
|
102
|
-
onError = new Set();
|
|
103
|
-
connectOnce = new Set();
|
|
104
|
-
errorOnce = new Set();
|
|
105
|
-
current;
|
|
106
|
-
encoding;
|
|
107
|
-
generation = 0;
|
|
108
|
-
bind(socket) {
|
|
109
|
-
this.current = socket;
|
|
110
|
-
this.generation += 1;
|
|
111
|
-
const generation = this.generation;
|
|
112
|
-
if (this.encoding) {
|
|
113
|
-
socket.setEncoding(this.encoding);
|
|
114
|
-
}
|
|
115
|
-
socket.on("data", (chunk) => {
|
|
116
|
-
if (generation !== this.generation) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
for (const handler of this.onData) {
|
|
120
|
-
handler(chunk);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
socket.on("close", () => {
|
|
124
|
-
if (generation !== this.generation) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
this.current = undefined;
|
|
128
|
-
for (const handler of this.onClose) {
|
|
129
|
-
handler();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
socket.on("error", (error) => {
|
|
133
|
-
if (generation !== this.generation) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this.current = undefined;
|
|
137
|
-
for (const handler of this.onError) {
|
|
138
|
-
handler(error);
|
|
139
|
-
}
|
|
140
|
-
for (const handler of this.errorOnce) {
|
|
141
|
-
handler(error);
|
|
142
|
-
}
|
|
143
|
-
this.errorOnce.clear();
|
|
144
|
-
});
|
|
145
|
-
for (const handler of this.connectOnce) {
|
|
146
|
-
handler();
|
|
147
|
-
}
|
|
148
|
-
this.connectOnce.clear();
|
|
149
|
-
}
|
|
150
|
-
setEncoding(encoding) {
|
|
151
|
-
this.encoding = encoding;
|
|
152
|
-
this.current?.setEncoding(encoding);
|
|
153
|
-
}
|
|
154
|
-
on(event, handler) {
|
|
155
|
-
if (event === "data") {
|
|
156
|
-
this.onData.add(handler);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (event === "error") {
|
|
160
|
-
this.onError.add(handler);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
this.onClose.add(handler);
|
|
164
|
-
}
|
|
165
|
-
once(event, handler) {
|
|
166
|
-
if (event === "connect") {
|
|
167
|
-
if (this.current) {
|
|
168
|
-
handler();
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
this.connectOnce.add(handler);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
this.errorOnce.add(handler);
|
|
175
|
-
}
|
|
176
|
-
off(event, handler) {
|
|
177
|
-
if (event === "connect") {
|
|
178
|
-
this.connectOnce.delete(handler);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
this.errorOnce.delete(handler);
|
|
182
|
-
}
|
|
183
|
-
write(chunk) {
|
|
184
|
-
if (!this.current) {
|
|
185
|
-
throw new Error("Sidecar socket unavailable");
|
|
186
|
-
}
|
|
187
|
-
this.current.write(chunk); // Cast/pass down safely
|
|
188
|
-
}
|
|
189
|
-
destroy() {
|
|
190
|
-
this.current?.destroy();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
class SidecarSupervisor {
|
|
194
|
-
cfg;
|
|
195
|
-
logger;
|
|
196
|
-
runtime;
|
|
197
|
-
retries = 0;
|
|
198
|
-
degraded = false;
|
|
199
|
-
shuttingDown = false;
|
|
200
|
-
reconnectScheduled = false;
|
|
201
|
-
stabilityTimer = null;
|
|
202
|
-
socket;
|
|
203
|
-
constructor(cfg, logger, runtime) {
|
|
204
|
-
this.cfg = cfg;
|
|
205
|
-
this.logger = logger;
|
|
206
|
-
this.runtime = runtime;
|
|
207
|
-
this.socket = new SupervisorSocket();
|
|
208
|
-
}
|
|
209
|
-
async start() {
|
|
210
|
-
const endpoint = await this.runtime.resolveEndpoint(this.cfg);
|
|
211
|
-
const socket = await this.connectEndpointWithRetry(endpoint);
|
|
212
|
-
this.reconnectScheduled = false;
|
|
213
|
-
this.scheduleStabilityReset();
|
|
214
|
-
if (this.socket instanceof SupervisorSocket) {
|
|
215
|
-
this.socket.bind(socket);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
this.socket = socket;
|
|
219
|
-
}
|
|
220
|
-
return socket;
|
|
221
|
-
}
|
|
222
|
-
isDegraded() {
|
|
223
|
-
return this.degraded;
|
|
224
|
-
}
|
|
225
|
-
async shutdown() {
|
|
226
|
-
this.shuttingDown = true;
|
|
227
|
-
this.clearStabilityTimer();
|
|
228
|
-
this.socket.destroy();
|
|
229
|
-
}
|
|
230
|
-
scheduleStabilityReset() {
|
|
231
|
-
this.clearStabilityTimer();
|
|
232
|
-
const windowMs = this.runtime.stabilityWindowMs ?? CONNECTION_STABILITY_WINDOW_MS;
|
|
233
|
-
if (windowMs <= 0) {
|
|
234
|
-
this.retries = 0;
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
this.stabilityTimer = setTimeout(() => {
|
|
238
|
-
this.stabilityTimer = null;
|
|
239
|
-
this.retries = 0;
|
|
240
|
-
this.logger.info?.("[libravdb] sidecar connection stable; retry counter reset");
|
|
241
|
-
}, windowMs);
|
|
242
|
-
this.stabilityTimer.unref?.();
|
|
243
|
-
}
|
|
244
|
-
clearStabilityTimer() {
|
|
245
|
-
if (this.stabilityTimer) {
|
|
246
|
-
clearTimeout(this.stabilityTimer);
|
|
247
|
-
this.stabilityTimer = null;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
async connectEndpointWithRetry(endpoint) {
|
|
251
|
-
if (isTcpEndpoint(endpoint)) {
|
|
252
|
-
this.logger.info?.(`[libravdb] using TCP endpoint ${endpoint}`);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
this.logger.info?.(`[libravdb] using Unix socket ${endpoint}`);
|
|
256
|
-
}
|
|
257
|
-
let waitedMs = 0;
|
|
258
|
-
for (let attempt = 0;; attempt += 1) {
|
|
259
|
-
try {
|
|
260
|
-
return await this.connectEndpoint(endpoint);
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
if (!isStartupConnectRetryableError(error) || attempt >= STARTUP_CONNECT_MAX_RETRIES - 1) {
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
const delayMs = computeStartupConnectRetryDelay(attempt, waitedMs);
|
|
267
|
-
if (delayMs <= 0) {
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
270
|
-
waitedMs += delayMs;
|
|
271
|
-
this.logger.info?.(`[libravdb] Daemon not ready, retrying connection (attempt ${attempt + 1}/${STARTUP_CONNECT_MAX_RETRIES})...`);
|
|
272
|
-
await sleep(delayMs);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
async connectEndpoint(endpoint) {
|
|
277
|
-
const socket = this.runtime.createSocket(endpoint);
|
|
278
|
-
return await new Promise((resolve, reject) => {
|
|
279
|
-
socket.once("connect", () => {
|
|
280
|
-
socket.on("close", () => {
|
|
281
|
-
void this.handleExit(1);
|
|
282
|
-
});
|
|
283
|
-
resolve(socket);
|
|
284
|
-
});
|
|
285
|
-
socket.once("error", (error) => {
|
|
286
|
-
socket.destroy();
|
|
287
|
-
reject(formatConnectionError(endpoint, error));
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
async handleExit(code) {
|
|
292
|
-
if (this.shuttingDown) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (code === 0) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
if (this.reconnectScheduled) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
this.clearStabilityTimer();
|
|
302
|
-
const maxRetries = this.cfg.maxRetries ?? 3;
|
|
303
|
-
if (this.retries >= maxRetries) {
|
|
304
|
-
this.logger.error("[libravdb] sidecar retries exhausted; degraded mode");
|
|
305
|
-
this.degraded = true;
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
const backoffMs = computeBackoffMs(this.retries);
|
|
309
|
-
this.retries += 1;
|
|
310
|
-
this.reconnectScheduled = true;
|
|
311
|
-
this.runtime.scheduleRestart(backoffMs, () => {
|
|
312
|
-
if (this.shuttingDown) {
|
|
313
|
-
this.reconnectScheduled = false;
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
void this.start().catch((error) => {
|
|
317
|
-
this.reconnectScheduled = false;
|
|
318
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
319
|
-
this.logger.error(`[libravdb] sidecar reconnect failed: ${message}`);
|
|
320
|
-
void this.handleExit(1);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
export async function startSidecar(cfg, logger = console, runtime = createDefaultRuntime()) {
|
|
326
|
-
const supervisor = new SidecarSupervisor(cfg, logger, runtime);
|
|
327
|
-
await supervisor.start();
|
|
328
|
-
return supervisor;
|
|
329
|
-
}
|
|
330
|
-
export function computeBackoffMs(retries) {
|
|
331
|
-
return Math.min(500 * Math.pow(2, retries), 16000);
|
|
332
|
-
}
|
|
333
|
-
export function computeStartupConnectRetryDelay(attempt, waitedMs = 0) {
|
|
334
|
-
if (attempt < 0) {
|
|
335
|
-
return 0;
|
|
336
|
-
}
|
|
337
|
-
const remainingMs = STARTUP_CONNECT_MAX_TOTAL_WAIT_MS - waitedMs;
|
|
338
|
-
if (remainingMs <= 0) {
|
|
339
|
-
return 0;
|
|
340
|
-
}
|
|
341
|
-
return Math.min(STARTUP_CONNECT_BASE_DELAY_MS * Math.pow(2, attempt), remainingMs);
|
|
342
|
-
}
|
|
343
|
-
export function isTcpEndpoint(endpoint) {
|
|
344
|
-
return endpoint.startsWith("tcp:");
|
|
345
|
-
}
|
|
346
|
-
export function parseTcpEndpoint(endpoint) {
|
|
347
|
-
if (!isTcpEndpoint(endpoint)) {
|
|
348
|
-
return null;
|
|
349
|
-
}
|
|
350
|
-
const address = endpoint.slice("tcp:".length).trim();
|
|
351
|
-
const separator = address.lastIndexOf(":");
|
|
352
|
-
if (separator <= 0 || separator === address.length - 1) {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
let host = address.slice(0, separator).trim();
|
|
356
|
-
const port = Number(address.slice(separator + 1).trim());
|
|
357
|
-
if (host.startsWith("[") || host.endsWith("]")) {
|
|
358
|
-
if (!host.startsWith("[") || !host.endsWith("]")) {
|
|
359
|
-
return null;
|
|
360
|
-
}
|
|
361
|
-
host = host.slice(1, -1).trim();
|
|
362
|
-
}
|
|
363
|
-
if (host.length === 0 || !Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
return { host, port };
|
|
367
|
-
}
|
|
368
|
-
export function resolveEndpoint(cfg) {
|
|
369
|
-
const endpoint = resolveConfiguredEndpoint(cfg);
|
|
370
|
-
return endpoint.replace(/^unix:/, "");
|
|
371
|
-
}
|
|
372
|
-
export function resolveConfiguredEndpoint(cfg) {
|
|
373
|
-
const value = cfg.sidecarPath?.trim();
|
|
374
|
-
if (!value || value === "auto") {
|
|
375
|
-
return defaultEndpoint();
|
|
376
|
-
}
|
|
377
|
-
const endpoint = normalizeConfiguredEndpoint(value);
|
|
378
|
-
if (!endpoint) {
|
|
379
|
-
throw new Error(`LibraVDB sidecarPath must be a daemon endpoint like unix:/path/to/libravdb.sock or tcp:127.0.0.1:37421. Executable paths are no longer supported.`);
|
|
380
|
-
}
|
|
381
|
-
return endpoint;
|
|
382
|
-
}
|
|
383
|
-
export function daemonProvisioningHint() {
|
|
384
|
-
return "If you installed the npm package, install and start libravdbd separately; the package does not provision the daemon binary, ONNX Runtime, or model assets.";
|
|
385
|
-
}
|
|
386
|
-
export function defaultEndpoint(platform = process.platform, homeDir = os.homedir(), pathExists = fs.existsSync) {
|
|
387
|
-
// Honour the daemon's own env var first (set by Homebrew LaunchAgent / systemd unit).
|
|
388
|
-
const envEndpoint = normalizeConfiguredEndpoint(process.env.LIBRAVDB_RPC_ENDPOINT);
|
|
389
|
-
if (envEndpoint) {
|
|
390
|
-
return envEndpoint;
|
|
391
|
-
}
|
|
392
|
-
if (platform === "win32") {
|
|
393
|
-
return "tcp:127.0.0.1:37421";
|
|
394
|
-
}
|
|
395
|
-
const joinSocketPath = path.posix.join;
|
|
396
|
-
const sockName = "libravdb.sock";
|
|
397
|
-
const candidateDirs = [
|
|
398
|
-
// User-local (npm plugin convention)
|
|
399
|
-
homeDir?.trim() ? joinSocketPath(homeDir, ".libravdbd", "run") : null,
|
|
400
|
-
// Homebrew (Apple Silicon) — matches the Homebrew formula LaunchAgent
|
|
401
|
-
"/opt/homebrew/var/libravdbd/run",
|
|
402
|
-
// Homebrew (Intel Mac) / manual Linux installs
|
|
403
|
-
"/usr/local/var/libravdbd/run",
|
|
404
|
-
].filter((d) => d !== null);
|
|
405
|
-
for (const dir of candidateDirs) {
|
|
406
|
-
const sockPath = joinSocketPath(dir, sockName);
|
|
407
|
-
try {
|
|
408
|
-
if (pathExists(sockPath)) {
|
|
409
|
-
return `unix:${sockPath}`;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
catch {
|
|
413
|
-
// Permission error or similar — skip this candidate.
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
// Fallback to the original user-local path so error messages stay familiar.
|
|
417
|
-
const baseDir = homeDir?.trim()
|
|
418
|
-
? joinSocketPath(homeDir, ".libravdbd", "run")
|
|
419
|
-
: joinSocketPath(".", ".libravdbd", "run");
|
|
420
|
-
return `unix:${joinSocketPath(baseDir, sockName)}`;
|
|
421
|
-
}
|
|
422
|
-
export function buildSidecarEnv(cfg) {
|
|
423
|
-
const env = {};
|
|
424
|
-
if (cfg.dbPath) {
|
|
425
|
-
env.LIBRAVDB_DB_PATH = cfg.dbPath;
|
|
426
|
-
}
|
|
427
|
-
if (cfg.embeddingRuntimePath) {
|
|
428
|
-
env.LIBRAVDB_ONNX_RUNTIME = cfg.embeddingRuntimePath;
|
|
429
|
-
}
|
|
430
|
-
env.LIBRAVDB_ONNX_DEVICE = cfg.onnxDevice ?? "cpu";
|
|
431
|
-
if (cfg.embeddingBackend) {
|
|
432
|
-
env.LIBRAVDB_EMBEDDING_BACKEND = cfg.embeddingBackend;
|
|
433
|
-
}
|
|
434
|
-
if (cfg.embeddingProfile) {
|
|
435
|
-
env.LIBRAVDB_EMBEDDING_PROFILE = cfg.embeddingProfile;
|
|
436
|
-
}
|
|
437
|
-
if (cfg.fallbackProfile) {
|
|
438
|
-
env.LIBRAVDB_FALLBACK_PROFILE = cfg.fallbackProfile;
|
|
439
|
-
}
|
|
440
|
-
if (cfg.embeddingModelPath) {
|
|
441
|
-
env.LIBRAVDB_EMBEDDING_MODEL = cfg.embeddingModelPath;
|
|
442
|
-
}
|
|
443
|
-
if (cfg.embeddingTokenizerPath) {
|
|
444
|
-
env.LIBRAVDB_EMBEDDING_TOKENIZER = cfg.embeddingTokenizerPath;
|
|
445
|
-
}
|
|
446
|
-
if (typeof cfg.embeddingDimensions === "number" && cfg.embeddingDimensions > 0) {
|
|
447
|
-
env.LIBRAVDB_EMBEDDING_DIMENSIONS = String(cfg.embeddingDimensions);
|
|
448
|
-
}
|
|
449
|
-
if (typeof cfg.embeddingNormalize === "boolean") {
|
|
450
|
-
env.LIBRAVDB_EMBEDDING_NORMALIZE = String(cfg.embeddingNormalize);
|
|
451
|
-
}
|
|
452
|
-
if (cfg.summarizerBackend) {
|
|
453
|
-
env.LIBRAVDB_SUMMARIZER_BACKEND = cfg.summarizerBackend;
|
|
454
|
-
}
|
|
455
|
-
if (cfg.summarizerProfile) {
|
|
456
|
-
env.LIBRAVDB_SUMMARIZER_PROFILE = cfg.summarizerProfile;
|
|
457
|
-
}
|
|
458
|
-
if (cfg.summarizerRuntimePath) {
|
|
459
|
-
env.LIBRAVDB_SUMMARIZER_RUNTIME = cfg.summarizerRuntimePath;
|
|
460
|
-
}
|
|
461
|
-
if (cfg.summarizerModelPath) {
|
|
462
|
-
env.LIBRAVDB_SUMMARIZER_MODEL_PATH = cfg.summarizerModelPath;
|
|
463
|
-
}
|
|
464
|
-
if (cfg.summarizerTokenizerPath) {
|
|
465
|
-
env.LIBRAVDB_SUMMARIZER_TOKENIZER = cfg.summarizerTokenizerPath;
|
|
466
|
-
}
|
|
467
|
-
if (cfg.summarizerModel) {
|
|
468
|
-
env.LIBRAVDB_SUMMARIZER_MODEL = cfg.summarizerModel;
|
|
469
|
-
}
|
|
470
|
-
if (cfg.summarizerEndpoint) {
|
|
471
|
-
env.LIBRAVDB_SUMMARIZER_ENDPOINT = cfg.summarizerEndpoint;
|
|
472
|
-
}
|
|
473
|
-
if (cfg.ollamaUrl && !env.LIBRAVDB_SUMMARIZER_ENDPOINT) {
|
|
474
|
-
env.LIBRAVDB_SUMMARIZER_ENDPOINT = cfg.ollamaUrl;
|
|
475
|
-
}
|
|
476
|
-
if (cfg.compactModel && !env.LIBRAVDB_SUMMARIZER_MODEL) {
|
|
477
|
-
env.LIBRAVDB_SUMMARIZER_MODEL = cfg.compactModel;
|
|
478
|
-
}
|
|
479
|
-
if (typeof cfg.lifecycleJournalMaxEntries === "number" && cfg.lifecycleJournalMaxEntries > 0) {
|
|
480
|
-
env.LIBRAVDB_LIFECYCLE_JOURNAL_MAX_ENTRIES = String(cfg.lifecycleJournalMaxEntries);
|
|
481
|
-
}
|
|
482
|
-
return env;
|
|
483
|
-
}
|
|
484
|
-
function createDefaultRuntime() {
|
|
485
|
-
return {
|
|
486
|
-
resolveEndpoint(cfg) {
|
|
487
|
-
return resolveEndpoint(cfg);
|
|
488
|
-
},
|
|
489
|
-
createSocket(endpoint) {
|
|
490
|
-
if (isTcpEndpoint(endpoint)) {
|
|
491
|
-
const parsed = parseTcpEndpoint(endpoint);
|
|
492
|
-
if (!parsed) {
|
|
493
|
-
throw new Error(`Invalid TCP sidecar endpoint: ${endpoint}`);
|
|
494
|
-
}
|
|
495
|
-
return net.connect(parsed);
|
|
496
|
-
}
|
|
497
|
-
return net.connect(endpoint);
|
|
498
|
-
},
|
|
499
|
-
scheduleRestart(delayMs, restart) {
|
|
500
|
-
setTimeout(restart, delayMs);
|
|
501
|
-
},
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
function isStartupConnectRetryableError(error) {
|
|
505
|
-
const code = typeof error?.code === "string"
|
|
506
|
-
? error.code
|
|
507
|
-
: "";
|
|
508
|
-
return code === "ENOENT" || code === "ECONNREFUSED";
|
|
509
|
-
}
|
|
510
|
-
function formatConnectionError(endpoint, error) {
|
|
511
|
-
const code = typeof error.code === "string"
|
|
512
|
-
? error.code
|
|
513
|
-
: "";
|
|
514
|
-
const annotated = error instanceof Error ? error : new Error(String(error));
|
|
515
|
-
if (code) {
|
|
516
|
-
annotated.code = code;
|
|
517
|
-
}
|
|
518
|
-
if (code === "ENOENT" || code === "ECONNREFUSED") {
|
|
519
|
-
const unavailable = new Error(`LibraVDB daemon unavailable at ${describeEndpoint(endpoint)}. ${daemonProvisioningHint()} Or set sidecarPath to a running daemon endpoint.`);
|
|
520
|
-
unavailable.code = code;
|
|
521
|
-
return unavailable;
|
|
522
|
-
}
|
|
523
|
-
return annotated;
|
|
524
|
-
}
|
|
525
|
-
function describeEndpoint(endpoint) {
|
|
526
|
-
if (isTcpEndpoint(endpoint)) {
|
|
527
|
-
return endpoint;
|
|
528
|
-
}
|
|
529
|
-
return `unix:${endpoint}`;
|
|
530
|
-
}
|
|
531
|
-
function isConfiguredEndpoint(value) {
|
|
532
|
-
if (!value)
|
|
533
|
-
return false;
|
|
534
|
-
if (value.startsWith("unix:")) {
|
|
535
|
-
return value.slice("unix:".length).trim().length > 0;
|
|
536
|
-
}
|
|
537
|
-
return parseTcpEndpoint(value) !== null;
|
|
538
|
-
}
|
|
539
|
-
function normalizeConfiguredEndpoint(value) {
|
|
540
|
-
const trimmed = value?.trim();
|
|
541
|
-
if (!trimmed || trimmed === "auto") {
|
|
542
|
-
return null;
|
|
543
|
-
}
|
|
544
|
-
if (trimmed.startsWith("unix:")) {
|
|
545
|
-
const socketPath = trimmed.slice("unix:".length).trim();
|
|
546
|
-
return socketPath ? `unix:${socketPath}` : null;
|
|
547
|
-
}
|
|
548
|
-
return isConfiguredEndpoint(trimmed) ? trimmed : null;
|
|
549
|
-
}
|
|
550
|
-
export { PlaceholderSocket };
|
|
551
|
-
function sleep(delayMs) {
|
|
552
|
-
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
553
|
-
}
|
|
554
|
-
export async function probeSidecarEndpoint(cfg) {
|
|
555
|
-
const endpoint = resolveConfiguredEndpoint(cfg);
|
|
556
|
-
try {
|
|
557
|
-
await new Promise((resolve, reject) => {
|
|
558
|
-
if (isTcpEndpoint(endpoint)) {
|
|
559
|
-
const parsed = parseTcpEndpoint(endpoint);
|
|
560
|
-
if (!parsed) {
|
|
561
|
-
reject(new Error("invalid tcp endpoint"));
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
const socket = net.connect(parsed, () => {
|
|
565
|
-
socket.destroy();
|
|
566
|
-
resolve();
|
|
567
|
-
});
|
|
568
|
-
socket.setTimeout(500);
|
|
569
|
-
socket.on("error", reject);
|
|
570
|
-
socket.on("timeout", reject);
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
const socketPath = endpoint.replace(/^unix:/, "");
|
|
574
|
-
const socket = net.connect(socketPath, () => {
|
|
575
|
-
socket.destroy();
|
|
576
|
-
resolve();
|
|
577
|
-
});
|
|
578
|
-
socket.setTimeout(500);
|
|
579
|
-
socket.on("error", reject);
|
|
580
|
-
socket.on("timeout", reject);
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return endpoint;
|
|
584
|
-
}
|
|
585
|
-
catch {
|
|
586
|
-
return null;
|
|
587
|
-
}
|
|
588
|
-
}
|