open-agents-ai 0.184.57 → 0.184.58
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 +71 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63288,43 +63288,93 @@ function startApiServer(options = {}) {
|
|
|
63288
63288
|
}
|
|
63289
63289
|
});
|
|
63290
63290
|
});
|
|
63291
|
+
let retried = false;
|
|
63291
63292
|
server.on("error", (err) => {
|
|
63292
|
-
if (err.code === "EADDRINUSE") {
|
|
63293
|
-
|
|
63293
|
+
if (err.code === "EADDRINUSE" && !retried) {
|
|
63294
|
+
retried = true;
|
|
63295
|
+
process.stderr.write(` Port ${port} in use \u2014 reclaiming...
|
|
63296
|
+
`);
|
|
63297
|
+
try {
|
|
63298
|
+
const { execSync: es } = __require("node:child_process");
|
|
63299
|
+
const pids = es(`lsof -ti :${port} 2>/dev/null || fuser ${port}/tcp 2>/dev/null || true`, { encoding: "utf8" }).trim().split(/[\n\s]+/).filter(Boolean);
|
|
63300
|
+
for (const pid of pids) {
|
|
63301
|
+
const numPid = parseInt(pid, 10);
|
|
63302
|
+
if (numPid && numPid !== process.pid) {
|
|
63303
|
+
try {
|
|
63304
|
+
process.kill(numPid, "SIGTERM");
|
|
63305
|
+
} catch {
|
|
63306
|
+
}
|
|
63307
|
+
setTimeout(() => {
|
|
63308
|
+
try {
|
|
63309
|
+
process.kill(numPid, "SIGKILL");
|
|
63310
|
+
} catch {
|
|
63311
|
+
}
|
|
63312
|
+
}, 500);
|
|
63313
|
+
}
|
|
63314
|
+
}
|
|
63315
|
+
} catch {
|
|
63316
|
+
}
|
|
63317
|
+
setTimeout(() => {
|
|
63318
|
+
server.listen(port, host);
|
|
63319
|
+
}, 2e3);
|
|
63320
|
+
} else if (err.code === "EADDRINUSE" && retried) {
|
|
63321
|
+
process.stderr.write(` Port ${port} still in use after reclaim attempt \u2014 API server not started.
|
|
63294
63322
|
`);
|
|
63295
63323
|
} else {
|
|
63296
63324
|
process.stderr.write(` API server error: ${err.message}
|
|
63297
63325
|
`);
|
|
63298
63326
|
}
|
|
63299
63327
|
});
|
|
63300
|
-
|
|
63301
|
-
|
|
63302
|
-
|
|
63303
|
-
|
|
63304
|
-
|
|
63328
|
+
endpointRegistry.push({
|
|
63329
|
+
label: (() => {
|
|
63330
|
+
const u = config.backendUrl;
|
|
63331
|
+
if (u.includes("127.0.0.1") || u.includes("localhost"))
|
|
63332
|
+
return "local";
|
|
63333
|
+
try {
|
|
63334
|
+
return new URL(u).hostname.split(".")[0];
|
|
63335
|
+
} catch {
|
|
63336
|
+
return "primary";
|
|
63337
|
+
}
|
|
63338
|
+
})(),
|
|
63339
|
+
url: config.backendUrl,
|
|
63340
|
+
type: config.backendType || "ollama",
|
|
63341
|
+
authKey: config.apiKey
|
|
63342
|
+
});
|
|
63343
|
+
server.listen(port, host, () => {
|
|
63344
|
+
const version = getVersion3();
|
|
63345
|
+
process.stderr.write(`
|
|
63305
63346
|
open-agents API server v${version}
|
|
63306
63347
|
`);
|
|
63307
|
-
|
|
63348
|
+
process.stderr.write(` Listening on http://${host}:${port}
|
|
63308
63349
|
`);
|
|
63309
|
-
|
|
63350
|
+
process.stderr.write(` Primary: ${config.backendUrl} (${config.backendType || "ollama"})
|
|
63310
63351
|
`);
|
|
63311
|
-
|
|
63312
|
-
|
|
63352
|
+
if (process.env["OA_API_KEYS"]) {
|
|
63353
|
+
const keyCount = process.env["OA_API_KEYS"].split(",").length;
|
|
63354
|
+
process.stderr.write(` Auth: ${keyCount} scoped key(s) (read/run/admin)
|
|
63313
63355
|
`);
|
|
63314
|
-
|
|
63315
|
-
|
|
63316
|
-
const keyCount = process.env["OA_API_KEYS"].split(",").length;
|
|
63317
|
-
process.stderr.write(` Auth: ${keyCount} scoped key(s) (read/run/admin)
|
|
63356
|
+
} else if (process.env["OA_API_KEY"]) {
|
|
63357
|
+
process.stderr.write(` Auth: single Bearer token (admin scope)
|
|
63318
63358
|
`);
|
|
63319
|
-
|
|
63320
|
-
|
|
63359
|
+
} else {
|
|
63360
|
+
process.stderr.write(` Auth: disabled (set OA_API_KEY or OA_API_KEYS to enable)
|
|
63321
63361
|
`);
|
|
63322
|
-
|
|
63323
|
-
|
|
63362
|
+
}
|
|
63363
|
+
process.stderr.write(` Discovering sponsors in background...
|
|
63364
|
+
|
|
63324
63365
|
`);
|
|
63325
|
-
|
|
63326
|
-
|
|
63366
|
+
refreshEndpointRegistry().then(() => {
|
|
63367
|
+
if (endpointRegistry.length > 1) {
|
|
63368
|
+
process.stderr.write(` Sponsors: ${endpointRegistry.length - 1} endpoint(s) discovered
|
|
63369
|
+
`);
|
|
63370
|
+
for (const ep of endpointRegistry.slice(1)) {
|
|
63371
|
+
process.stderr.write(` ${ep.label}: ${ep.url} (${ep.type})${ep.authKey ? " [auth]" : ""}
|
|
63327
63372
|
`);
|
|
63373
|
+
}
|
|
63374
|
+
process.stderr.write(`
|
|
63375
|
+
`);
|
|
63376
|
+
}
|
|
63377
|
+
}).catch(() => {
|
|
63328
63378
|
});
|
|
63329
63379
|
});
|
|
63330
63380
|
const shutdown = () => {
|
package/package.json
CHANGED