open-agents-ai 0.186.15 → 0.186.17
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 +88 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8895,36 +8895,13 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
|
|
|
8895
8895
|
const currentScriptHash = createHash("sha256").update(DAEMON_SCRIPT).digest("hex").slice(0, 16);
|
|
8896
8896
|
const existingPid = this.getDaemonPid();
|
|
8897
8897
|
if (existingPid) {
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
const diskHash = createHash("sha256").update(onDisk).digest("hex").slice(0, 16);
|
|
8904
|
-
if (diskHash === currentScriptHash) {
|
|
8905
|
-
needsRestart = false;
|
|
8906
|
-
}
|
|
8907
|
-
} catch {
|
|
8908
|
-
}
|
|
8898
|
+
let processAlive = false;
|
|
8899
|
+
try {
|
|
8900
|
+
process.kill(existingPid, 0);
|
|
8901
|
+
processAlive = true;
|
|
8902
|
+
} catch {
|
|
8909
8903
|
}
|
|
8910
|
-
if (
|
|
8911
|
-
try {
|
|
8912
|
-
process.kill(existingPid, "SIGTERM");
|
|
8913
|
-
} catch {
|
|
8914
|
-
}
|
|
8915
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
8916
|
-
try {
|
|
8917
|
-
process.kill(existingPid, 0);
|
|
8918
|
-
process.kill(existingPid, "SIGKILL");
|
|
8919
|
-
} catch {
|
|
8920
|
-
}
|
|
8921
|
-
for (const f of ["daemon.pid", "status.json", "cmd.json", "resp.json"]) {
|
|
8922
|
-
const p = join14(this.nexusDir, f);
|
|
8923
|
-
if (existsSync11(p))
|
|
8924
|
-
await unlink(p).catch(() => {
|
|
8925
|
-
});
|
|
8926
|
-
}
|
|
8927
|
-
} else {
|
|
8904
|
+
if (processAlive) {
|
|
8928
8905
|
const statusFile2 = join14(this.nexusDir, "status.json");
|
|
8929
8906
|
if (existsSync11(statusFile2)) {
|
|
8930
8907
|
try {
|
|
@@ -8933,14 +8910,46 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
|
|
|
8933
8910
|
await this.ensureWallet();
|
|
8934
8911
|
return `Already connected (pid: ${existingPid}, peerId: ${status.peerId})`;
|
|
8935
8912
|
}
|
|
8913
|
+
if (status.error) {
|
|
8914
|
+
try {
|
|
8915
|
+
process.kill(existingPid, "SIGTERM");
|
|
8916
|
+
} catch {
|
|
8917
|
+
}
|
|
8918
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
8919
|
+
}
|
|
8920
|
+
return await this.waitForDaemonReady(existingPid);
|
|
8936
8921
|
} catch {
|
|
8937
8922
|
}
|
|
8938
8923
|
}
|
|
8924
|
+
for (let i = 0; i < 10; i++) {
|
|
8925
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
8926
|
+
if (existsSync11(statusFile2)) {
|
|
8927
|
+
try {
|
|
8928
|
+
const status = JSON.parse(await readFile8(statusFile2, "utf8"));
|
|
8929
|
+
if (status.connected && status.peerId) {
|
|
8930
|
+
await this.ensureWallet();
|
|
8931
|
+
return `Already connected (pid: ${existingPid}, peerId: ${status.peerId})`;
|
|
8932
|
+
}
|
|
8933
|
+
} catch {
|
|
8934
|
+
}
|
|
8935
|
+
}
|
|
8936
|
+
}
|
|
8939
8937
|
try {
|
|
8940
8938
|
process.kill(existingPid, "SIGTERM");
|
|
8941
8939
|
} catch {
|
|
8942
8940
|
}
|
|
8943
8941
|
await new Promise((r) => setTimeout(r, 500));
|
|
8942
|
+
try {
|
|
8943
|
+
process.kill(existingPid, 0);
|
|
8944
|
+
process.kill(existingPid, "SIGKILL");
|
|
8945
|
+
} catch {
|
|
8946
|
+
}
|
|
8947
|
+
}
|
|
8948
|
+
for (const f of ["daemon.pid", "status.json", "cmd.json", "resp.json"]) {
|
|
8949
|
+
const p = join14(this.nexusDir, f);
|
|
8950
|
+
if (existsSync11(p))
|
|
8951
|
+
await unlink(p).catch(() => {
|
|
8952
|
+
});
|
|
8944
8953
|
}
|
|
8945
8954
|
}
|
|
8946
8955
|
for (const f of ["daemon.pid", "status.json", "cmd.json", "resp.json"]) {
|
|
@@ -9144,6 +9153,28 @@ process.on('SIGINT', () => process.emit('SIGTERM'));
|
|
|
9144
9153
|
}
|
|
9145
9154
|
return `Daemon failed to start.${earlyError ? "\n" + earlyError : ""}${earlyOutput ? "\n" + earlyOutput : ""}`;
|
|
9146
9155
|
}
|
|
9156
|
+
/** Wait for an already-spawned daemon to write connected status (up to 20s). */
|
|
9157
|
+
async waitForDaemonReady(pid) {
|
|
9158
|
+
const statusFile = join14(this.nexusDir, "status.json");
|
|
9159
|
+
for (let i = 0; i < 40; i++) {
|
|
9160
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
9161
|
+
if (existsSync11(statusFile)) {
|
|
9162
|
+
try {
|
|
9163
|
+
const status = JSON.parse(await readFile8(statusFile, "utf8"));
|
|
9164
|
+
if (status.error)
|
|
9165
|
+
return `Nexus daemon failed: ${status.error}`;
|
|
9166
|
+
if (status.connected && status.peerId) {
|
|
9167
|
+
await this.ensureWallet();
|
|
9168
|
+
return `Connected to nexus P2P network.
|
|
9169
|
+
Peer ID: ${status.peerId}
|
|
9170
|
+
Daemon PID: ${status.pid}`;
|
|
9171
|
+
}
|
|
9172
|
+
} catch {
|
|
9173
|
+
}
|
|
9174
|
+
}
|
|
9175
|
+
}
|
|
9176
|
+
return `Daemon spawned (pid: ${pid}) but still connecting. Check status in a moment.`;
|
|
9177
|
+
}
|
|
9147
9178
|
async doDisconnect() {
|
|
9148
9179
|
const pid = this.getDaemonPid();
|
|
9149
9180
|
if (!pid)
|
|
@@ -53183,9 +53214,15 @@ async function handleSponsoredEndpoint(ctx, local) {
|
|
|
53183
53214
|
if (isConnected) {
|
|
53184
53215
|
renderInfo("Using existing nexus connection...");
|
|
53185
53216
|
} else {
|
|
53186
|
-
|
|
53187
|
-
|
|
53188
|
-
|
|
53217
|
+
const hasPid = statusResult.includes("PID:") || statusResult.includes("pid:");
|
|
53218
|
+
if (!hasPid) {
|
|
53219
|
+
renderInfo("Starting nexus daemon...");
|
|
53220
|
+
await nexusTool.execute({ action: "connect" });
|
|
53221
|
+
await new Promise((r) => setTimeout(r, 3e3));
|
|
53222
|
+
} else {
|
|
53223
|
+
renderInfo("Waiting for nexus daemon to connect...");
|
|
53224
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
53225
|
+
}
|
|
53189
53226
|
}
|
|
53190
53227
|
renderInfo("Querying sponsors on the mesh...");
|
|
53191
53228
|
const discoverResult = await nexusTool.execute({
|
|
@@ -71731,10 +71768,25 @@ Rationale: ${proposal.rationale}${provenanceNote}`;
|
|
|
71731
71768
|
}
|
|
71732
71769
|
if (!ollamaAlive) {
|
|
71733
71770
|
try {
|
|
71734
|
-
const
|
|
71771
|
+
const savedSponsorsPath = join75(repoRoot, ".oa", "sponsor", "known-sponsors.json");
|
|
71772
|
+
let savedSponsors = [];
|
|
71773
|
+
try {
|
|
71774
|
+
if (existsSync58(savedSponsorsPath)) {
|
|
71775
|
+
savedSponsors = JSON.parse(readFileSync47(savedSponsorsPath, "utf8"));
|
|
71776
|
+
const oneHourAgo = Date.now() - 36e5;
|
|
71777
|
+
savedSponsors = savedSponsors.filter((s) => (s.lastVerified || 0) > oneHourAgo);
|
|
71778
|
+
}
|
|
71779
|
+
} catch {
|
|
71780
|
+
}
|
|
71781
|
+
const spResp = await fetch("https://openagents.nexus/api/v1/sponsors", { signal: AbortSignal.timeout(8e3) });
|
|
71735
71782
|
if (spResp.ok) {
|
|
71736
71783
|
const spData = await spResp.json();
|
|
71737
|
-
|
|
71784
|
+
let active = (spData.sponsors || []).filter((s) => s.status === "active" && s.tunnelUrl);
|
|
71785
|
+
for (const saved of savedSponsors) {
|
|
71786
|
+
if (saved.tunnelUrl && !active.some((a) => a.tunnelUrl === saved.tunnelUrl || a.name === saved.name)) {
|
|
71787
|
+
active.push({ ...saved, status: "active" });
|
|
71788
|
+
}
|
|
71789
|
+
}
|
|
71738
71790
|
const tunnelSponsors = active.filter((s) => /trycloudflare\.com/i.test(s.tunnelUrl));
|
|
71739
71791
|
const directSponsors = active.filter((s) => !/trycloudflare\.com/i.test(s.tunnelUrl));
|
|
71740
71792
|
const sorted = [...tunnelSponsors, ...directSponsors];
|
|
@@ -71747,13 +71799,13 @@ Rationale: ${proposal.rationale}${provenanceNote}`;
|
|
|
71747
71799
|
const headers = {};
|
|
71748
71800
|
if (sponsor.authKey)
|
|
71749
71801
|
headers["Authorization"] = `Bearer ${sponsor.authKey}`;
|
|
71750
|
-
const probe = await fetch(testUrl, { headers, signal: AbortSignal.timeout(
|
|
71802
|
+
const probe = await fetch(testUrl, { headers, signal: AbortSignal.timeout(15e3) });
|
|
71751
71803
|
if (probe.ok) {
|
|
71752
71804
|
best = sponsor;
|
|
71753
71805
|
break;
|
|
71754
71806
|
}
|
|
71755
71807
|
if (probe.status === 401 && sponsor.authKey) {
|
|
71756
|
-
const noAuthProbe = await fetch(testUrl, { signal: AbortSignal.timeout(
|
|
71808
|
+
const noAuthProbe = await fetch(testUrl, { signal: AbortSignal.timeout(1e4) });
|
|
71757
71809
|
if (noAuthProbe.ok) {
|
|
71758
71810
|
best = sponsor;
|
|
71759
71811
|
bestNoAuth = true;
|
package/package.json
CHANGED