@proagentstore/cli 0.1.14 → 0.1.15
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 +81 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1053,6 +1053,30 @@ function printStep(label, status) {
|
|
|
1053
1053
|
const icon = status === "ok" ? chalk.green("\u2713") : status === "fail" ? chalk.red("\u2717") : chalk.yellow("\u2026");
|
|
1054
1054
|
console.log(pad + icon + " " + label);
|
|
1055
1055
|
}
|
|
1056
|
+
async function waitForKey(keys) {
|
|
1057
|
+
return new Promise((resolve5) => {
|
|
1058
|
+
readline.emitKeypressEvents(process.stdin);
|
|
1059
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
1060
|
+
process.stdin.resume();
|
|
1061
|
+
const onKeypress = (str, key) => {
|
|
1062
|
+
if (key?.ctrl && key.name === "c") {
|
|
1063
|
+
cleanup();
|
|
1064
|
+
process.exit(0);
|
|
1065
|
+
}
|
|
1066
|
+
const val = (str || "").trim().toLowerCase();
|
|
1067
|
+
if (keys.includes(val)) {
|
|
1068
|
+
cleanup();
|
|
1069
|
+
resolve5(val);
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
const cleanup = () => {
|
|
1073
|
+
process.stdin.off("keypress", onKeypress);
|
|
1074
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
1075
|
+
process.stdin.pause();
|
|
1076
|
+
};
|
|
1077
|
+
process.stdin.on("keypress", onKeypress);
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1056
1080
|
|
|
1057
1081
|
// src/commands/up.ts
|
|
1058
1082
|
var API_BASE2 = "https://api.proagentstore.online";
|
|
@@ -1106,17 +1130,18 @@ var upCommand = new Command7("up").description("Start the browser runner for all
|
|
|
1106
1130
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1107
1131
|
env: { ...process.env, PAGS_TOKEN: session.token }
|
|
1108
1132
|
});
|
|
1109
|
-
|
|
1133
|
+
const logs = [];
|
|
1110
1134
|
const handleOutput = (data2) => {
|
|
1111
1135
|
const text = data2.toString("utf-8");
|
|
1112
1136
|
for (const line of text.split("\n")) {
|
|
1113
1137
|
const trimmed = line.trim();
|
|
1114
1138
|
if (!trimmed) continue;
|
|
1139
|
+
logs.push(trimmed);
|
|
1140
|
+
if (logs.length > 200) logs.shift();
|
|
1115
1141
|
const tunnelMatch = trimmed.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/i);
|
|
1116
1142
|
if (tunnelMatch) {
|
|
1117
|
-
tunnelUrl = tunnelMatch[0];
|
|
1118
1143
|
state.tunnel = "online";
|
|
1119
|
-
state.tunnelUrl =
|
|
1144
|
+
state.tunnelUrl = tunnelMatch[0];
|
|
1120
1145
|
state.lastEvent = "Tunnel created";
|
|
1121
1146
|
printStatus(state);
|
|
1122
1147
|
continue;
|
|
@@ -1129,28 +1154,33 @@ var upCommand = new Command7("up").description("Start the browser runner for all
|
|
|
1129
1154
|
}
|
|
1130
1155
|
if (trimmed.includes("Runtime registered") || trimmed.includes("CONNECTED")) {
|
|
1131
1156
|
state.registration = "registered";
|
|
1132
|
-
state.lastEvent = "Registered with PAGS";
|
|
1157
|
+
state.lastEvent = "Registered with PAGS \u2014 ready for tasks";
|
|
1133
1158
|
printStatus(state);
|
|
1134
1159
|
continue;
|
|
1135
1160
|
}
|
|
1136
|
-
if (trimmed.includes("fetch failed")
|
|
1137
|
-
state.
|
|
1138
|
-
|
|
1139
|
-
state.registration = "failed";
|
|
1140
|
-
}
|
|
1161
|
+
if (trimmed.includes("fetch failed")) {
|
|
1162
|
+
state.registration = "failed";
|
|
1163
|
+
state.lastEvent = "PAGS registration failed (will retry on next task)";
|
|
1141
1164
|
printStatus(state);
|
|
1142
1165
|
continue;
|
|
1143
1166
|
}
|
|
1144
|
-
if (trimmed.includes("INF ")
|
|
1145
|
-
|
|
1167
|
+
if (trimmed.includes("INF ")) continue;
|
|
1168
|
+
if (/error|Error|EADDRINUSE|ECONNREFUSED|failed/i.test(trimmed)) {
|
|
1169
|
+
state.lastEvent = trimmed.slice(0, 80);
|
|
1170
|
+
printStatus(state);
|
|
1171
|
+
}
|
|
1146
1172
|
}
|
|
1147
1173
|
};
|
|
1148
1174
|
child.stdout?.on("data", handleOutput);
|
|
1149
1175
|
child.stderr?.on("data", handleOutput);
|
|
1176
|
+
let childDead = false;
|
|
1150
1177
|
child.on("exit", (code) => {
|
|
1178
|
+
childDead = true;
|
|
1151
1179
|
if (code && code !== 0) {
|
|
1152
1180
|
state.runner = "error";
|
|
1153
|
-
state.lastEvent = `Runner exited
|
|
1181
|
+
state.lastEvent = `Runner exited (code ${code})`;
|
|
1182
|
+
const recent = logs.slice(-5).filter((l) => !l.includes("INF "));
|
|
1183
|
+
if (recent.length) state.lastEvent += ": " + recent[recent.length - 1].slice(0, 60);
|
|
1154
1184
|
printStatus(state);
|
|
1155
1185
|
}
|
|
1156
1186
|
});
|
|
@@ -1162,9 +1192,45 @@ var upCommand = new Command7("up").description("Start the browser runner for all
|
|
|
1162
1192
|
};
|
|
1163
1193
|
process.on("SIGINT", shutdown);
|
|
1164
1194
|
process.on("SIGTERM", shutdown);
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1195
|
+
while (true) {
|
|
1196
|
+
const key = await waitForKey(["r", "l", "q"]);
|
|
1197
|
+
if (key === "q") {
|
|
1198
|
+
shutdown();
|
|
1199
|
+
break;
|
|
1200
|
+
}
|
|
1201
|
+
if (key === "l") {
|
|
1202
|
+
clearScreen();
|
|
1203
|
+
writeLine(" Recent logs (last 30 lines):");
|
|
1204
|
+
writeLine("");
|
|
1205
|
+
for (const line of logs.slice(-30)) {
|
|
1206
|
+
writeLine(" " + line);
|
|
1207
|
+
}
|
|
1208
|
+
writeLine("");
|
|
1209
|
+
writeLine(" Press any key to go back...");
|
|
1210
|
+
await waitForKey(["r", "l", "q", " ", "\r"]);
|
|
1211
|
+
printStatus(state);
|
|
1212
|
+
}
|
|
1213
|
+
if (key === "r") {
|
|
1214
|
+
if (childDead) {
|
|
1215
|
+
writeLine(" Restarting runner...");
|
|
1216
|
+
state.runner = "starting";
|
|
1217
|
+
state.tunnel = "offline";
|
|
1218
|
+
state.tunnelUrl = "";
|
|
1219
|
+
state.registration = "pending";
|
|
1220
|
+
state.lastEvent = "Restarting...";
|
|
1221
|
+
const { execSync } = await import("child_process");
|
|
1222
|
+
try {
|
|
1223
|
+
execSync(`${process.execPath} ${process.argv[1]} up${opts.headless ? " --headless" : ""}`, {
|
|
1224
|
+
stdio: "inherit",
|
|
1225
|
+
env: process.env
|
|
1226
|
+
});
|
|
1227
|
+
} catch {
|
|
1228
|
+
}
|
|
1229
|
+
process.exit(0);
|
|
1230
|
+
}
|
|
1231
|
+
printStatus(state);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1168
1234
|
});
|
|
1169
1235
|
|
|
1170
1236
|
// src/index.ts
|