@vicvic-im/agent-bot 0.1.1 → 0.1.2
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/README.md +1 -1
- package/dist/bin-server.cjs +1292 -0
- package/dist/bin-server.cjs.map +1 -0
- package/dist/bin-server.d.ts +2 -0
- package/dist/bin-server.d.ts.map +1 -0
- package/dist/bin-server.js +19 -0
- package/dist/bin-server.js.map +1 -0
- package/dist/{chunk-QQ2NXJ3L.js → chunk-6CK4XIJB.js} +2 -2
- package/dist/{chunk-SCVC76UL.js → chunk-X5QSWCDH.js} +19 -35
- package/dist/chunk-X5QSWCDH.js.map +1 -0
- package/dist/cli.cjs +48 -49
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +32 -17
- package/dist/cli.js.map +1 -1
- package/dist/core/pm2.d.ts +7 -0
- package/dist/core/pm2.d.ts.map +1 -0
- package/dist/index.cjs +12 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/server.cjs +12 -26
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-SCVC76UL.js.map +0 -1
- /package/dist/{chunk-QQ2NXJ3L.js.map → chunk-6CK4XIJB.js.map} +0 -0
package/dist/cli.cjs
CHANGED
|
@@ -24,8 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/cli.ts
|
|
27
|
-
var
|
|
28
|
-
var
|
|
27
|
+
var import_node_child_process3 = require("child_process");
|
|
28
|
+
var import_node_path6 = require("path");
|
|
29
29
|
var import_commander = require("commander");
|
|
30
30
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
31
31
|
|
|
@@ -136,11 +136,11 @@ function parseEnv(value) {
|
|
|
136
136
|
if (value === void 0 || value === null) return void 0;
|
|
137
137
|
const record = asRecord(value, "agent.env");
|
|
138
138
|
const env = {};
|
|
139
|
-
for (const [key,
|
|
140
|
-
if (typeof
|
|
139
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
140
|
+
if (typeof entry !== "string") {
|
|
141
141
|
throw new ConfigError(`Invalid "agent.env.${key}": expected a string`);
|
|
142
142
|
}
|
|
143
|
-
env[key] =
|
|
143
|
+
env[key] = entry;
|
|
144
144
|
}
|
|
145
145
|
return env;
|
|
146
146
|
}
|
|
@@ -184,7 +184,7 @@ function parseAgent(root, configDir) {
|
|
|
184
184
|
return {
|
|
185
185
|
name: agentName,
|
|
186
186
|
command: optionalString(agentRaw.command, "agent.command"),
|
|
187
|
-
args: Array.isArray(argsRaw) ? argsRaw.map((
|
|
187
|
+
args: Array.isArray(argsRaw) ? argsRaw.map((entry) => String(entry)) : void 0,
|
|
188
188
|
cwd,
|
|
189
189
|
model: optionalString(agentRaw.model, "agent.model") ?? null,
|
|
190
190
|
env: parseEnv(agentRaw.env)
|
|
@@ -318,7 +318,7 @@ var import_node_fs3 = require("fs");
|
|
|
318
318
|
var import_node_path3 = require("path");
|
|
319
319
|
function resolveServerEntry(cliPath2) {
|
|
320
320
|
const real = (0, import_node_fs3.realpathSync)(cliPath2);
|
|
321
|
-
const candidate = (0, import_node_path3.join)((0, import_node_path3.dirname)(real), "server.js");
|
|
321
|
+
const candidate = (0, import_node_path3.join)((0, import_node_path3.dirname)(real), "bin-server.js");
|
|
322
322
|
if (!(0, import_node_fs3.existsSync)(candidate)) {
|
|
323
323
|
throw new Error(`Server bundle not found at ${candidate}. Reinstall @vicvic-im/agent-bot.`);
|
|
324
324
|
}
|
|
@@ -333,11 +333,29 @@ function readPackageVersion(cliPath2) {
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
// src/
|
|
337
|
-
var
|
|
336
|
+
// src/core/pm2.ts
|
|
337
|
+
var import_node_child_process = require("child_process");
|
|
338
|
+
var ENV_BIN = "/usr/bin/env";
|
|
339
|
+
function hasPm2(exec = import_node_child_process.execFileSync) {
|
|
340
|
+
try {
|
|
341
|
+
exec(ENV_BIN, ["pm2", "--version"], { stdio: "ignore" });
|
|
342
|
+
return true;
|
|
343
|
+
} catch {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function ensurePm2(exec = import_node_child_process.execFileSync) {
|
|
348
|
+
if (hasPm2(exec)) return true;
|
|
349
|
+
try {
|
|
350
|
+
exec(ENV_BIN, ["npm", "i", "-g", "pm2"], { stdio: "inherit" });
|
|
351
|
+
return hasPm2(exec);
|
|
352
|
+
} catch {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
338
356
|
|
|
339
357
|
// src/agents/acp.ts
|
|
340
|
-
var
|
|
358
|
+
var import_node_child_process2 = require("child_process");
|
|
341
359
|
var import_node_stream = require("stream");
|
|
342
360
|
var acp = __toESM(require("@agentclientprotocol/sdk"), 1);
|
|
343
361
|
|
|
@@ -404,7 +422,7 @@ var AcpAgent = class {
|
|
|
404
422
|
const definition = definitionOf(this.name);
|
|
405
423
|
const command = this.config.command ?? definition.command.command;
|
|
406
424
|
const args = this.config.args ?? definition.command.args;
|
|
407
|
-
const child = (0,
|
|
425
|
+
const child = (0, import_node_child_process2.spawn)(command, args, {
|
|
408
426
|
cwd: this.config.cwd,
|
|
409
427
|
env: { ...process.env, ...this.config.env },
|
|
410
428
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -543,7 +561,7 @@ var AcpAgent = class {
|
|
|
543
561
|
);
|
|
544
562
|
pending.catch(() => void 0);
|
|
545
563
|
const response = await Promise.race([pending, aborted]);
|
|
546
|
-
await new Promise((
|
|
564
|
+
await new Promise((resolve4) => setImmediate(resolve4));
|
|
547
565
|
if (response.stopReason === "cancelled" || request.signal.aborted) {
|
|
548
566
|
throw new AgentAbortError();
|
|
549
567
|
}
|
|
@@ -576,7 +594,7 @@ var AcpAgent = class {
|
|
|
576
594
|
return true;
|
|
577
595
|
}
|
|
578
596
|
const option = this.configOptions.find(
|
|
579
|
-
(
|
|
597
|
+
(entry) => entry.type === "select" && (entry.id === "model" || entry.category === "model")
|
|
580
598
|
);
|
|
581
599
|
if (!option) return false;
|
|
582
600
|
await this.ctx.request(acp.methods.agent.session.setConfigOption, {
|
|
@@ -602,8 +620,8 @@ var AcpAgent = class {
|
|
|
602
620
|
} catch {
|
|
603
621
|
}
|
|
604
622
|
if (!child || child.exitCode !== null) return;
|
|
605
|
-
const exited = new Promise((
|
|
606
|
-
child.once("exit", () =>
|
|
623
|
+
const exited = new Promise((resolve4) => {
|
|
624
|
+
child.once("exit", () => resolve4());
|
|
607
625
|
});
|
|
608
626
|
child.kill("SIGTERM");
|
|
609
627
|
const timer = setTimeout(() => child.kill("SIGKILL"), 3e3);
|
|
@@ -720,7 +738,7 @@ var BotQueue = class {
|
|
|
720
738
|
};
|
|
721
739
|
|
|
722
740
|
// src/version.ts
|
|
723
|
-
var VBOT_VERSION = "0.1.
|
|
741
|
+
var VBOT_VERSION = "0.1.2";
|
|
724
742
|
|
|
725
743
|
// src/core/dispatcher.ts
|
|
726
744
|
var HELP_TEXT = `Available commands:
|
|
@@ -801,7 +819,7 @@ function handleAgent(runtime, args, send) {
|
|
|
801
819
|
const name = args.join(" ").trim();
|
|
802
820
|
if (!name) {
|
|
803
821
|
const current = runtime.config().agent.name;
|
|
804
|
-
const list = AGENT_NAMES.map((
|
|
822
|
+
const list = AGENT_NAMES.map((entry) => `${entry === current ? "*" : " "} ${entry}`).join("\n");
|
|
805
823
|
send(`Current agent: ${current}
|
|
806
824
|
Available agents:
|
|
807
825
|
${list}`);
|
|
@@ -1085,10 +1103,10 @@ var VicvicWire = class {
|
|
|
1085
1103
|
if (!socket || socket.readyState !== import_ws.default.OPEN) {
|
|
1086
1104
|
throw new Error("Bot connection is not open");
|
|
1087
1105
|
}
|
|
1088
|
-
await new Promise((
|
|
1106
|
+
await new Promise((resolve4, reject) => {
|
|
1089
1107
|
socket.send(JSON.stringify({ type: "reply", msgUid, text }), (error) => {
|
|
1090
1108
|
if (error) reject(error);
|
|
1091
|
-
else
|
|
1109
|
+
else resolve4();
|
|
1092
1110
|
});
|
|
1093
1111
|
});
|
|
1094
1112
|
}
|
|
@@ -1382,35 +1400,14 @@ ${error.stderr}`);
|
|
|
1382
1400
|
console.error("[server] agent run failed:", error);
|
|
1383
1401
|
replySafe(reply, `Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1384
1402
|
}
|
|
1385
|
-
var entry = process.argv[1] ?? "";
|
|
1386
|
-
if (/(^|[\\/])server\.(js|cjs|ts)$/.test(entry)) {
|
|
1387
|
-
const configPath = process.argv[2];
|
|
1388
|
-
if (!configPath) {
|
|
1389
|
-
console.error("Usage: server.js <config-path>");
|
|
1390
|
-
process.exit(1);
|
|
1391
|
-
}
|
|
1392
|
-
runBot((0, import_node_path6.resolve)(configPath)).catch((error) => {
|
|
1393
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
1394
|
-
const expected = error instanceof ConfigError || error instanceof LockError;
|
|
1395
|
-
process.exit(expected ? 2 : 1);
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
1403
|
|
|
1399
1404
|
// src/cli.ts
|
|
1400
1405
|
function processName(cwd) {
|
|
1401
|
-
return `vbot-${(0,
|
|
1402
|
-
}
|
|
1403
|
-
var ENV_BIN = "/usr/bin/env";
|
|
1404
|
-
function hasPm2() {
|
|
1405
|
-
try {
|
|
1406
|
-
(0, import_node_child_process2.execFileSync)(ENV_BIN, ["pm2", "--version"], { stdio: "ignore" });
|
|
1407
|
-
return true;
|
|
1408
|
-
} catch {
|
|
1409
|
-
return false;
|
|
1410
|
-
}
|
|
1406
|
+
return `vbot-${(0, import_node_path6.basename)((0, import_node_path6.resolve)(cwd)).replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
1411
1407
|
}
|
|
1408
|
+
var ENV_BIN2 = "/usr/bin/env";
|
|
1412
1409
|
function pm2(args, capture = false) {
|
|
1413
|
-
return (0,
|
|
1410
|
+
return (0, import_node_child_process3.execFileSync)(ENV_BIN2, ["pm2", ...args], {
|
|
1414
1411
|
stdio: capture ? "pipe" : "inherit",
|
|
1415
1412
|
encoding: "utf8"
|
|
1416
1413
|
});
|
|
@@ -1434,12 +1431,14 @@ var program = new import_commander.Command();
|
|
|
1434
1431
|
program.name("vbot").description("Connect local coding agents to vicvic.im").version(readPackageVersion(cliPath()));
|
|
1435
1432
|
program.command("start").description("Start vbot (prompts for config on first run)").option("--foreground", "run in the foreground instead of pm2").option("-c, --config <path>", "config file path").action(async (options) => {
|
|
1436
1433
|
const { path } = await ensureConfig(options.config);
|
|
1437
|
-
if (options.foreground
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1434
|
+
if (options.foreground) {
|
|
1435
|
+
await runBot(path);
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
if (!hasPm2()) console.log(import_picocolors2.default.yellow("pm2 not found, installing globally..."));
|
|
1439
|
+
if (!ensurePm2()) {
|
|
1440
|
+
console.error(import_picocolors2.default.red("Failed to install pm2. Please install manually: npm i -g pm2"));
|
|
1441
|
+
console.log(import_picocolors2.default.yellow("Running in the foreground instead."));
|
|
1443
1442
|
await runBot(path);
|
|
1444
1443
|
return;
|
|
1445
1444
|
}
|