open-agents-ai 0.103.21 → 0.103.23
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 +70 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27508,7 +27508,30 @@ var init_expose = __esm({
|
|
|
27508
27508
|
this.server.listen(port, "127.0.0.1", () => resolve31());
|
|
27509
27509
|
this.server.on("error", reject);
|
|
27510
27510
|
});
|
|
27511
|
-
|
|
27511
|
+
let lastStartErr;
|
|
27512
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
27513
|
+
try {
|
|
27514
|
+
this._tunnelUrl = await this.startCloudflared(port);
|
|
27515
|
+
break;
|
|
27516
|
+
} catch (err) {
|
|
27517
|
+
lastStartErr = err instanceof Error ? err : new Error(String(err));
|
|
27518
|
+
const is429 = lastStartErr.message.includes("429") || lastStartErr.message.includes("Too Many Requests");
|
|
27519
|
+
if (is429 && attempt < 2) {
|
|
27520
|
+
const delaySec = (attempt + 1) * 15;
|
|
27521
|
+
this.options.onInfo?.(`Cloudflare rate limited \u2014 retrying in ${delaySec}s (attempt ${attempt + 2}/3)...`);
|
|
27522
|
+
await new Promise((r) => setTimeout(r, delaySec * 1e3));
|
|
27523
|
+
continue;
|
|
27524
|
+
}
|
|
27525
|
+
if (this.server) {
|
|
27526
|
+
await new Promise((r) => this.server.close(() => r()));
|
|
27527
|
+
this.server = null;
|
|
27528
|
+
}
|
|
27529
|
+
throw lastStartErr;
|
|
27530
|
+
}
|
|
27531
|
+
}
|
|
27532
|
+
if (!this._tunnelUrl) {
|
|
27533
|
+
throw lastStartErr ?? new Error("Cloudflared tunnel start failed after retries");
|
|
27534
|
+
}
|
|
27512
27535
|
this._stats.status = "active";
|
|
27513
27536
|
this.emitStats();
|
|
27514
27537
|
if (this._stateDir) {
|
|
@@ -27931,25 +27954,37 @@ var init_expose = __esm({
|
|
|
27931
27954
|
async restartCloudflared() {
|
|
27932
27955
|
if (!this.server || this._proxyPort === 0)
|
|
27933
27956
|
return;
|
|
27934
|
-
|
|
27935
|
-
|
|
27936
|
-
|
|
27937
|
-
|
|
27938
|
-
|
|
27957
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
27958
|
+
try {
|
|
27959
|
+
this._tunnelUrl = await this.startCloudflared(this._proxyPort);
|
|
27960
|
+
this._stats.status = "active";
|
|
27961
|
+
this.emitStats();
|
|
27962
|
+
this.options.onInfo?.(`Tunnel restarted with new URL \u2014 share with consumers:
|
|
27939
27963
|
${this.formatConnectionInfo()}`);
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
27943
|
-
|
|
27944
|
-
|
|
27945
|
-
|
|
27946
|
-
|
|
27947
|
-
|
|
27948
|
-
|
|
27949
|
-
|
|
27964
|
+
if (this._stateDir) {
|
|
27965
|
+
writeExposeState(this._stateDir, {
|
|
27966
|
+
pid: this._cloudflaredPid,
|
|
27967
|
+
tunnelUrl: this._tunnelUrl,
|
|
27968
|
+
authKey: this._authKey,
|
|
27969
|
+
proxyPort: this._proxyPort,
|
|
27970
|
+
targetUrl: this._targetUrl,
|
|
27971
|
+
kind: this._kind,
|
|
27972
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
27973
|
+
});
|
|
27974
|
+
}
|
|
27975
|
+
return;
|
|
27976
|
+
} catch (err) {
|
|
27977
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
27978
|
+
const is429 = msg.includes("429") || msg.includes("Too Many Requests");
|
|
27979
|
+
if (is429 && attempt < 2) {
|
|
27980
|
+
const delaySec = (attempt + 1) * 15;
|
|
27981
|
+
this.options.onInfo?.(`Cloudflare rate limited \u2014 retrying in ${delaySec}s...`);
|
|
27982
|
+
await new Promise((r) => setTimeout(r, delaySec * 1e3));
|
|
27983
|
+
continue;
|
|
27984
|
+
}
|
|
27985
|
+
this.options.onError?.(`Tunnel restart failed: ${msg}`);
|
|
27986
|
+
return;
|
|
27950
27987
|
}
|
|
27951
|
-
} catch (err) {
|
|
27952
|
-
this.options.onError?.(`Tunnel restart failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
27953
27988
|
}
|
|
27954
27989
|
}
|
|
27955
27990
|
/**
|
|
@@ -29703,7 +29738,7 @@ async function fetchOpenAIModels(baseUrl, apiKey) {
|
|
|
29703
29738
|
}
|
|
29704
29739
|
const resp = await fetch(url, {
|
|
29705
29740
|
headers,
|
|
29706
|
-
signal: AbortSignal.timeout(
|
|
29741
|
+
signal: AbortSignal.timeout(15e3)
|
|
29707
29742
|
});
|
|
29708
29743
|
if (!resp.ok) {
|
|
29709
29744
|
throw new Error(`Failed to fetch models: HTTP ${resp.status}`);
|
|
@@ -29768,25 +29803,33 @@ async function fetchModels(baseUrl, apiKey) {
|
|
|
29768
29803
|
}
|
|
29769
29804
|
const provider = detectProvider(baseUrl);
|
|
29770
29805
|
if (provider.id === "ollama") {
|
|
29806
|
+
let ollamaErr;
|
|
29771
29807
|
try {
|
|
29772
29808
|
return await fetchOllamaModels(baseUrl);
|
|
29773
|
-
} catch {
|
|
29809
|
+
} catch (err) {
|
|
29810
|
+
ollamaErr = err instanceof Error ? err : new Error(String(err));
|
|
29774
29811
|
try {
|
|
29775
29812
|
return await fetchOpenAIModels(baseUrl, apiKey);
|
|
29776
29813
|
} catch {
|
|
29777
|
-
throw new Error(
|
|
29814
|
+
throw new Error(`Cannot reach Ollama at ${baseUrl}: ${ollamaErr.message}`);
|
|
29778
29815
|
}
|
|
29779
29816
|
}
|
|
29780
29817
|
}
|
|
29781
|
-
|
|
29782
|
-
|
|
29783
|
-
} catch {
|
|
29818
|
+
let lastErr;
|
|
29819
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
29784
29820
|
try {
|
|
29785
|
-
return await
|
|
29786
|
-
} catch {
|
|
29787
|
-
|
|
29821
|
+
return await fetchOpenAIModels(baseUrl, apiKey);
|
|
29822
|
+
} catch (err) {
|
|
29823
|
+
lastErr = err instanceof Error ? err : new Error(String(err));
|
|
29824
|
+
if (attempt === 0)
|
|
29825
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
29788
29826
|
}
|
|
29789
29827
|
}
|
|
29828
|
+
try {
|
|
29829
|
+
return await fetchOllamaModels(baseUrl);
|
|
29830
|
+
} catch {
|
|
29831
|
+
throw new Error(`Cannot fetch models from ${provider.label} at ${baseUrl}: ${lastErr?.message ?? "unknown error"}`);
|
|
29832
|
+
}
|
|
29790
29833
|
}
|
|
29791
29834
|
function findModel(models, query) {
|
|
29792
29835
|
const exact = models.find((m) => m.name === query);
|
package/package.json
CHANGED