open-agents-ai 0.103.24 → 0.103.26
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.js +74 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12046,7 +12046,7 @@ ${truncated}`, durationMs: performance.now() - start };
|
|
|
12046
12046
|
|
|
12047
12047
|
// packages/execution/dist/tools/nexus.js
|
|
12048
12048
|
import { readFile as readFile13, writeFile as writeFile12, mkdir as mkdir8, chmod, unlink, readdir as readdir3, open as fsOpen } from "node:fs/promises";
|
|
12049
|
-
import { existsSync as existsSync23, readFileSync as readFileSync16 } from "node:fs";
|
|
12049
|
+
import { existsSync as existsSync23, readFileSync as readFileSync16, watch as fsWatchLocal } from "node:fs";
|
|
12050
12050
|
import { resolve as resolve26, join as join30 } from "node:path";
|
|
12051
12051
|
import { randomBytes as randomBytes6, createCipheriv, createDecipheriv, scryptSync, createHash } from "node:crypto";
|
|
12052
12052
|
import { execSync as execSync22, spawn as spawn11 } from "node:child_process";
|
|
@@ -12072,7 +12072,7 @@ var init_nexus = __esm({
|
|
|
12072
12072
|
*/
|
|
12073
12073
|
|
|
12074
12074
|
import { NexusClient, createFileAuditHook } from 'open-agents-nexus';
|
|
12075
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync, readdirSync, appendFileSync } from 'node:fs';
|
|
12075
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync, readdirSync, appendFileSync, watch as fsWatch } from 'node:fs';
|
|
12076
12076
|
import { join } from 'node:path';
|
|
12077
12077
|
|
|
12078
12078
|
const nexusDir = process.argv[2];
|
|
@@ -12672,8 +12672,8 @@ async function handleCmd(cmd) {
|
|
|
12672
12672
|
// Wait for input data to arrive (invoke protocol sends data after accept)
|
|
12673
12673
|
var waitMs = 0;
|
|
12674
12674
|
while (!inputDone && dataChunks.length === 0 && waitMs < 5000) {
|
|
12675
|
-
await new Promise(function(r) { setTimeout(r,
|
|
12676
|
-
waitMs +=
|
|
12675
|
+
await new Promise(function(r) { setTimeout(r, 10); });
|
|
12676
|
+
waitMs += 10;
|
|
12677
12677
|
}
|
|
12678
12678
|
prompt = dataChunks.join('');
|
|
12679
12679
|
dlog('expose: received ' + dataChunks.length + ' chunks, prompt_len=' + prompt.length + ' inputDone=' + inputDone);
|
|
@@ -12904,9 +12904,10 @@ async function handleCmd(cmd) {
|
|
|
12904
12904
|
}
|
|
12905
12905
|
}
|
|
12906
12906
|
|
|
12907
|
-
// Command polling loop \u2014 check for cmd.json every
|
|
12907
|
+
// Command polling loop \u2014 check for cmd.json every 50ms (fast IPC)
|
|
12908
|
+
// fs.existsSync + readFileSync costs ~0.01ms per call, negligible CPU at 50ms interval.
|
|
12908
12909
|
let lastCmdId = '';
|
|
12909
|
-
|
|
12910
|
+
function checkCmd() {
|
|
12910
12911
|
try {
|
|
12911
12912
|
if (!existsSync(cmdFile)) return;
|
|
12912
12913
|
const raw = readFileSync(cmdFile, 'utf8');
|
|
@@ -12917,7 +12918,14 @@ setInterval(() => {
|
|
|
12917
12918
|
writeResp(cmd.id, { ok: false, output: 'Error: ' + (err.message || String(err)) });
|
|
12918
12919
|
});
|
|
12919
12920
|
} catch {}
|
|
12920
|
-
}
|
|
12921
|
+
}
|
|
12922
|
+
setInterval(checkCmd, 50);
|
|
12923
|
+
// Also watch for cmd.json changes for instant notification (best-effort)
|
|
12924
|
+
try {
|
|
12925
|
+
fsWatch(nexusDir, { persistent: false }, function(evType, filename) {
|
|
12926
|
+
if (filename === 'cmd.json') checkCmd();
|
|
12927
|
+
});
|
|
12928
|
+
} catch {}
|
|
12921
12929
|
|
|
12922
12930
|
// Crash protection \u2014 prevent unhandled errors from killing the daemon
|
|
12923
12931
|
process.on('uncaughtException', (err) => {
|
|
@@ -13310,11 +13318,59 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
|
|
|
13310
13318
|
await unlink(respFile).catch(() => {
|
|
13311
13319
|
});
|
|
13312
13320
|
await writeFile12(cmdFile, JSON.stringify({ id: cmdId, action, args }, null, 2));
|
|
13313
|
-
const
|
|
13314
|
-
|
|
13315
|
-
|
|
13316
|
-
|
|
13317
|
-
|
|
13321
|
+
const pollMs = 50;
|
|
13322
|
+
const polls = Math.ceil(timeoutMs / pollMs);
|
|
13323
|
+
let resolved = false;
|
|
13324
|
+
let watcher = null;
|
|
13325
|
+
const watchResolve = new Promise((watchDone) => {
|
|
13326
|
+
try {
|
|
13327
|
+
watcher = fsWatchLocal(this.nexusDir, { persistent: false }, (_evType, filename) => {
|
|
13328
|
+
if (resolved || filename !== "resp.json")
|
|
13329
|
+
return;
|
|
13330
|
+
try {
|
|
13331
|
+
if (!existsSync23(respFile))
|
|
13332
|
+
return;
|
|
13333
|
+
const resp = JSON.parse(readFileSync16(respFile, "utf8"));
|
|
13334
|
+
if (resp.id === cmdId) {
|
|
13335
|
+
resolved = true;
|
|
13336
|
+
watchDone(resp.output || (resp.ok ? "OK" : "Failed"));
|
|
13337
|
+
}
|
|
13338
|
+
} catch {
|
|
13339
|
+
}
|
|
13340
|
+
});
|
|
13341
|
+
} catch {
|
|
13342
|
+
}
|
|
13343
|
+
});
|
|
13344
|
+
const pollResolve = (async () => {
|
|
13345
|
+
for (let i = 0; i < polls && !resolved; i++) {
|
|
13346
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
13347
|
+
if (resolved)
|
|
13348
|
+
return null;
|
|
13349
|
+
if (!existsSync23(respFile))
|
|
13350
|
+
continue;
|
|
13351
|
+
try {
|
|
13352
|
+
const resp = JSON.parse(await readFile13(respFile, "utf8"));
|
|
13353
|
+
if (resp.id === cmdId) {
|
|
13354
|
+
resolved = true;
|
|
13355
|
+
return resp.output || (resp.ok ? "OK" : "Failed");
|
|
13356
|
+
}
|
|
13357
|
+
} catch {
|
|
13358
|
+
}
|
|
13359
|
+
}
|
|
13360
|
+
return null;
|
|
13361
|
+
})();
|
|
13362
|
+
try {
|
|
13363
|
+
const result = await Promise.race([watchResolve, pollResolve]);
|
|
13364
|
+
if (result)
|
|
13365
|
+
return result;
|
|
13366
|
+
} finally {
|
|
13367
|
+
resolved = true;
|
|
13368
|
+
try {
|
|
13369
|
+
watcher?.close();
|
|
13370
|
+
} catch {
|
|
13371
|
+
}
|
|
13372
|
+
}
|
|
13373
|
+
if (existsSync23(respFile)) {
|
|
13318
13374
|
try {
|
|
13319
13375
|
const resp = JSON.parse(await readFile13(respFile, "utf8"));
|
|
13320
13376
|
if (resp.id === cmdId) {
|
|
@@ -34012,12 +34068,15 @@ async function handleEndpoint(arg, ctx, local = false) {
|
|
|
34012
34068
|
}
|
|
34013
34069
|
return;
|
|
34014
34070
|
}
|
|
34015
|
-
const
|
|
34071
|
+
const normalizedArg = arg.replace(/\u2014/g, "--").replace(/\u2013/g, "--");
|
|
34072
|
+
const parts = normalizedArg.split(/\s+/);
|
|
34016
34073
|
const url = parts[0];
|
|
34017
34074
|
let apiKey;
|
|
34018
34075
|
const authIdx = parts.indexOf("--auth");
|
|
34019
|
-
|
|
34020
|
-
|
|
34076
|
+
const authIdx2 = authIdx === -1 ? parts.indexOf("-auth") : authIdx;
|
|
34077
|
+
const effectiveAuthIdx = authIdx !== -1 ? authIdx : authIdx2;
|
|
34078
|
+
if (effectiveAuthIdx !== -1 && parts[effectiveAuthIdx + 1]) {
|
|
34079
|
+
apiKey = parts[effectiveAuthIdx + 1];
|
|
34021
34080
|
}
|
|
34022
34081
|
if (url.startsWith("12D3KooW") && url.length > 40 && !url.includes("://")) {
|
|
34023
34082
|
await handlePeerEndpoint(url, apiKey, ctx, local);
|
package/package.json
CHANGED