open-agents-ai 0.187.368 → 0.187.369

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.
Files changed (2) hide show
  1. package/dist/index.js +82 -41
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -551413,16 +551413,17 @@ var init_commands = __esm({
551413
551413
  if (findSlashCommand("access")) return;
551414
551414
  registerSlashCommand({
551415
551415
  name: "access",
551416
- description: "Show/set OA_ACCESS (loopback|lan|any) and restart daemon",
551416
+ description: "Show/set OA_ACCESS (loopback|lan|any). Live-mutates the daemon; auto-generates API key on 'any'.",
551417
551417
  handler: async ({ arg, hasLocal, ctx: ctx3 }) => {
551418
551418
  const normalize2 = (v) => v.toLowerCase().trim();
551419
+ const normalizeMode = (v) => v === "all" ? "any" : v;
551419
551420
  const curAccess = normalize2(process.env["OA_ACCESS"] ?? "");
551420
551421
  const curHost = process.env["OA_HOST"] ?? "0.0.0.0:11435";
551421
551422
  const allowed = /* @__PURE__ */ new Set(["loopback", "lan", "any"]);
551422
- const val = normalize2(arg);
551423
+ const val = normalizeMode(normalize2(arg));
551423
551424
  if (!val) {
551424
551425
  renderInfo2(`Access: ${curAccess || "(default)"} Host: ${curHost}`);
551425
- renderInfo2("Use /access loopback|lan|any to change (restarts daemon).\n");
551426
+ renderInfo2("Use /access loopback|lan|any to change.\n");
551426
551427
  return "handled";
551427
551428
  }
551428
551429
  if (!allowed.has(val)) {
@@ -551430,16 +551431,90 @@ var init_commands = __esm({
551430
551431
  return "handled";
551431
551432
  }
551432
551433
  process.env["OA_ACCESS"] = val;
551434
+ if (val === "any" && !process.env["OA_API_KEY"]) {
551435
+ try {
551436
+ const { randomBytes: randomBytes23 } = await import("node:crypto");
551437
+ const { homedir: homedir41 } = await import("node:os");
551438
+ const { mkdirSync: mkdirSync58, writeFileSync: writeFileSync51 } = await import("node:fs");
551439
+ const { join: join110 } = await import("node:path");
551440
+ const apiKey = randomBytes23(16).toString("hex");
551441
+ process.env["OA_API_KEY"] = apiKey;
551442
+ const dir = join110(homedir41(), ".open-agents");
551443
+ mkdirSync58(dir, { recursive: true });
551444
+ writeFileSync51(join110(dir, "api.key"), apiKey + "\n", "utf8");
551445
+ renderInfo2(`Generated API key: ${c3.bold(c3.yellow(apiKey))}`);
551446
+ renderInfo2("Use Authorization: Bearer <key> or click 'key' in the Web UI header to paste it.");
551447
+ } catch (e2) {
551448
+ renderWarning2(`Failed to generate API key: ${e2 instanceof Error ? e2.message : String(e2)}`);
551449
+ }
551450
+ }
551433
551451
  if (hasLocal) {
551434
551452
  ctx3.saveLocalSettings({ oaAccess: val });
551435
551453
  } else {
551436
551454
  ctx3.saveSettings({ oaAccess: val });
551437
551455
  }
551438
- const { stopDaemon: stopDaemon2, ensureDaemon: ensureDaemon2 } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
551439
- stopDaemon2();
551440
- await new Promise((r2) => setTimeout(r2, 800));
551456
+ const port = parseInt(process.env["OA_PORT"] || "11435", 10);
551457
+ try {
551458
+ const { homedir: homedir41 } = await import("node:os");
551459
+ const { mkdirSync: mkdirSync58, writeFileSync: writeFileSync51 } = await import("node:fs");
551460
+ const { join: join110 } = await import("node:path");
551461
+ const dir = join110(homedir41(), ".open-agents");
551462
+ mkdirSync58(dir, { recursive: true });
551463
+ writeFileSync51(join110(dir, "access"), `${val}
551464
+ `, "utf8");
551465
+ } catch {
551466
+ }
551467
+ const baseUrl = `http://127.0.0.1:${port}`;
551468
+ const authHeaders = () => {
551469
+ const token = process.env["OA_API_KEY"] || "";
551470
+ return token ? { Authorization: `Bearer ${token}` } : {};
551471
+ };
551472
+ let liveOk = false;
551473
+ try {
551474
+ const resp = await fetch(`${baseUrl}/v1/admin/access`, {
551475
+ method: "POST",
551476
+ headers: { "Content-Type": "application/json", ...authHeaders() },
551477
+ body: JSON.stringify({ mode: val }),
551478
+ signal: AbortSignal.timeout(3e3)
551479
+ });
551480
+ liveOk = resp.ok;
551481
+ } catch {
551482
+ }
551483
+ const readCurrent = async () => {
551484
+ try {
551485
+ const r2 = await fetch(`${baseUrl}/v1/admin/access`, { headers: authHeaders(), signal: AbortSignal.timeout(2e3) });
551486
+ if (!r2.ok) return null;
551487
+ const j = await r2.json();
551488
+ return typeof j.mode === "string" ? j.mode : null;
551489
+ } catch {
551490
+ return null;
551491
+ }
551492
+ };
551493
+ const current = await readCurrent();
551494
+ if (liveOk && current === val) {
551495
+ renderInfo2(`Access policy now '${val}' (live, no restart). Persisted to ~/.open-agents/access.`);
551496
+ return "handled";
551497
+ }
551498
+ renderInfo2(`Live switch did not take effect (daemon reports ${current ?? "unreachable"}). Force-restarting daemon...`);
551499
+ const { forceKillDaemon: forceKillDaemon2, ensureDaemon: ensureDaemon2 } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
551500
+ const killed = await forceKillDaemon2(port);
551501
+ if (killed > 0) renderInfo2(`Force-killed ${killed} process(es) bound to port ${port}.`);
551441
551502
  const ok2 = await ensureDaemon2();
551442
- renderInfo2(ok2 ? "Daemon restarted to apply access policy." : "Failed to restart daemon.");
551503
+ if (!ok2) {
551504
+ renderError2("Failed to start a fresh daemon after force-kill.");
551505
+ return "handled";
551506
+ }
551507
+ let finalMode = null;
551508
+ for (let i2 = 0; i2 < 10; i2++) {
551509
+ finalMode = await readCurrent();
551510
+ if (finalMode) break;
551511
+ await new Promise((r2) => setTimeout(r2, 250));
551512
+ }
551513
+ if (finalMode === val) {
551514
+ renderInfo2(`Access policy now '${val}' (daemon restarted, verified).`);
551515
+ } else {
551516
+ renderWarning2(`Daemon restarted but reports mode='${finalMode ?? "unreachable"}'. Expected '${val}'.`);
551517
+ }
551443
551518
  return "handled";
551444
551519
  }
551445
551520
  });
@@ -580196,40 +580271,6 @@ async function startInteractive(config, repoPath) {
580196
580271
  const repoRoot = resolve36(repoPath ?? cwd());
580197
580272
  try {
580198
580273
  const { registerSlashCommand: registerSlashCommand2 } = await Promise.resolve().then(() => (init_commands(), commands_exports));
580199
- registerSlashCommand2({
580200
- name: "access",
580201
- description: "Show/set OA_ACCESS (loopback|lan|any) and restart daemon",
580202
- handler: async ({ arg, hasLocal, ctx: ctx3 }) => {
580203
- const normalize2 = (v) => v.toLowerCase().trim();
580204
- const curAccess = normalize2(process.env["OA_ACCESS"] ?? "");
580205
- const curHost = process.env["OA_HOST"] ?? "0.0.0.0:11435";
580206
- const allowed = /* @__PURE__ */ new Set(["loopback", "lan", "any"]);
580207
- const val = normalize2(arg || "");
580208
- if (!val) {
580209
- process.stdout.write(`
580210
- Access: ${curAccess || "(default)"} Host: ${curHost}
580211
-
580212
- `);
580213
- return "handled";
580214
- }
580215
- if (!allowed.has(val)) {
580216
- process.stdout.write("\n Invalid access mode. Use: loopback, lan, or any.\n\n");
580217
- return "handled";
580218
- }
580219
- process.env["OA_ACCESS"] = val;
580220
- if (hasLocal) {
580221
- ctx3.saveLocalSettings({ oaAccess: val });
580222
- } else {
580223
- ctx3.saveSettings({ oaAccess: val });
580224
- }
580225
- const { stopDaemon: stopDaemon2, ensureDaemon: ensureDaemon2 } = await Promise.resolve().then(() => (init_daemon(), daemon_exports));
580226
- stopDaemon2();
580227
- await new Promise((r2) => setTimeout(r2, 800));
580228
- const ok2 = await ensureDaemon2();
580229
- process.stdout.write(ok2 ? "\n Daemon restarted to apply access policy.\n\n" : "\n Failed to restart daemon.\n\n");
580230
- return "handled";
580231
- }
580232
- });
580233
580274
  registerSlashCommand2({
580234
580275
  name: "host",
580235
580276
  description: "Set OA_HOST host:port and restart daemon",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-agents-ai",
3
- "version": "0.187.368",
3
+ "version": "0.187.369",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",