open-agents-ai 0.103.46 → 0.103.48
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 +61 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28537,7 +28537,7 @@ ${this.formatConnectionInfo()}`);
|
|
|
28537
28537
|
}
|
|
28538
28538
|
};
|
|
28539
28539
|
P2P_STATE_FILE_NAME = "expose-p2p-state.json";
|
|
28540
|
-
ExposeP2PGateway = class extends EventEmitter3 {
|
|
28540
|
+
ExposeP2PGateway = class _ExposeP2PGateway extends EventEmitter3 {
|
|
28541
28541
|
_nexusTool;
|
|
28542
28542
|
// NexusTool instance
|
|
28543
28543
|
_kind;
|
|
@@ -28669,6 +28669,7 @@ ${this.formatConnectionInfo()}`);
|
|
|
28669
28669
|
margin: this._margin,
|
|
28670
28670
|
passthrough: this._passthrough || void 0,
|
|
28671
28671
|
loadbalance: this._loadbalance || void 0,
|
|
28672
|
+
endpointAuth: this._endpointAuth,
|
|
28672
28673
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
28673
28674
|
});
|
|
28674
28675
|
}
|
|
@@ -28685,20 +28686,66 @@ ${this.formatConnectionInfo()}`);
|
|
|
28685
28686
|
}
|
|
28686
28687
|
/**
|
|
28687
28688
|
* Check for and reconnect to a surviving P2P expose from a previous session.
|
|
28688
|
-
*
|
|
28689
|
-
*
|
|
28690
|
-
*
|
|
28691
|
-
*
|
|
28692
|
-
* 3. Only a fresh start() → doConnect() → expose can guarantee correct state
|
|
28693
|
-
*
|
|
28694
|
-
* Instead, we clean up the stale state so the next /expose command starts fresh.
|
|
28689
|
+
* The daemon survives OA restarts, but we MUST re-verify it on reconnect:
|
|
28690
|
+
* 1. doConnect() checks script hash — kills + respawns if daemon code is stale
|
|
28691
|
+
* 2. Re-sends the expose command to clear old capabilities and register fresh ones
|
|
28692
|
+
* This guarantees the correct models are exposed (Chutes vs Ollama) even after OA restart.
|
|
28695
28693
|
*/
|
|
28696
|
-
static async checkAndReconnect(
|
|
28697
|
-
const state = readP2PExposeState(
|
|
28698
|
-
if (state)
|
|
28699
|
-
|
|
28694
|
+
static async checkAndReconnect(stateDir, nexusTool, options, currentConfig) {
|
|
28695
|
+
const state = readP2PExposeState(stateDir);
|
|
28696
|
+
if (!state)
|
|
28697
|
+
return null;
|
|
28698
|
+
const nexusDir = nexusTool.getNexusDir();
|
|
28699
|
+
const statusPath = join35(nexusDir, "status.json");
|
|
28700
|
+
try {
|
|
28701
|
+
if (!existsSync27(statusPath)) {
|
|
28702
|
+
removeP2PExposeState(stateDir);
|
|
28703
|
+
return null;
|
|
28704
|
+
}
|
|
28705
|
+
const status = JSON.parse(readFileSync19(statusPath, "utf8"));
|
|
28706
|
+
if (!status.connected || !status.peerId) {
|
|
28707
|
+
removeP2PExposeState(stateDir);
|
|
28708
|
+
return null;
|
|
28709
|
+
}
|
|
28710
|
+
} catch {
|
|
28711
|
+
removeP2PExposeState(stateDir);
|
|
28712
|
+
return null;
|
|
28713
|
+
}
|
|
28714
|
+
let effectiveState = { ...state };
|
|
28715
|
+
if (currentConfig) {
|
|
28716
|
+
const currentUrl = currentConfig.backendUrl;
|
|
28717
|
+
const isCurrentLocal = currentUrl.includes("127.0.0.1") || currentUrl.includes("localhost");
|
|
28718
|
+
const isCurrentPeer = currentUrl.startsWith("peer://");
|
|
28719
|
+
if (state.passthrough) {
|
|
28720
|
+
const normalizedUrl = currentUrl.replace(/\/+$/, "").replace(/\/chat\/completions$/, "").replace(/\/completions$/, "").replace(/\/models(\/.*)?$/, "").replace(/\/v1$/, "").replace(/\/+$/, "");
|
|
28721
|
+
effectiveState.targetUrl = normalizedUrl;
|
|
28722
|
+
effectiveState.endpointAuth = currentConfig.apiKey;
|
|
28723
|
+
} else if (!isCurrentLocal && !isCurrentPeer && state.kind === "ollama") {
|
|
28724
|
+
removeP2PExposeState(stateDir);
|
|
28725
|
+
options.onInfo?.("P2P expose skipped: endpoint changed (use /expose forward for remote backends)");
|
|
28726
|
+
return null;
|
|
28727
|
+
}
|
|
28728
|
+
}
|
|
28729
|
+
const gateway = new _ExposeP2PGateway({
|
|
28730
|
+
kind: effectiveState.kind,
|
|
28731
|
+
targetUrl: effectiveState.targetUrl,
|
|
28732
|
+
authKey: effectiveState.authKey,
|
|
28733
|
+
stateDir,
|
|
28734
|
+
margin: effectiveState.margin,
|
|
28735
|
+
passthrough: effectiveState.passthrough,
|
|
28736
|
+
loadbalance: effectiveState.loadbalance,
|
|
28737
|
+
endpointAuth: effectiveState.endpointAuth,
|
|
28738
|
+
...options
|
|
28739
|
+
}, nexusTool);
|
|
28740
|
+
try {
|
|
28741
|
+
await gateway.start();
|
|
28742
|
+
options.onInfo?.(`P2P expose reconnected: ${gateway._peerId ?? state.peerId}`);
|
|
28743
|
+
return gateway;
|
|
28744
|
+
} catch (err) {
|
|
28745
|
+
removeP2PExposeState(stateDir);
|
|
28746
|
+
options.onError?.(`P2P expose reconnect failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
28747
|
+
return null;
|
|
28700
28748
|
}
|
|
28701
|
-
return null;
|
|
28702
28749
|
}
|
|
28703
28750
|
/** Poll the daemon's metering.jsonl and status.json for stats */
|
|
28704
28751
|
startMeteringPoll(nexusDir) {
|
|
@@ -46392,7 +46439,7 @@ Rationale: ${proposal.rationale}${provenanceNote}`;
|
|
|
46392
46439
|
const reconnectedP2P = await ExposeP2PGateway.checkAndReconnect(oaDir, new NexusTool(repoRoot), {
|
|
46393
46440
|
onInfo: (msg) => writeContent(() => renderInfo(msg)),
|
|
46394
46441
|
onError: (msg) => writeContent(() => renderWarning(msg))
|
|
46395
|
-
});
|
|
46442
|
+
}, { backendUrl: currentConfig.backendUrl, apiKey: currentConfig.apiKey });
|
|
46396
46443
|
if (reconnectedP2P) {
|
|
46397
46444
|
p2pGateway = reconnectedP2P;
|
|
46398
46445
|
reconnectedP2P.on("stats", (stats) => {
|
package/package.json
CHANGED