@csdwd/ai-teams-agent 0.3.11 → 0.3.14
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 +51 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -875,6 +875,12 @@ function parseServerToEmployeeMessage(value) {
|
|
|
875
875
|
if (type === "task.cancel") {
|
|
876
876
|
return { type, taskId: nonEmptyStringField(message, "taskId") };
|
|
877
877
|
}
|
|
878
|
+
if (type === "queue.resume") {
|
|
879
|
+
return { type };
|
|
880
|
+
}
|
|
881
|
+
if (type === "agent.registered") {
|
|
882
|
+
return { type, consecutiveQueueFailures: nonNegativeNumberField(message, "consecutiveQueueFailures") };
|
|
883
|
+
}
|
|
878
884
|
throw new ProtocolError(`Unsupported server-to-employee message type: ${type}`);
|
|
879
885
|
}
|
|
880
886
|
function objectValue(value, label) {
|
|
@@ -921,6 +927,13 @@ function positiveNumberField(record, key) {
|
|
|
921
927
|
}
|
|
922
928
|
return value;
|
|
923
929
|
}
|
|
930
|
+
function nonNegativeNumberField(record, key) {
|
|
931
|
+
const value = record[key];
|
|
932
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
933
|
+
throw new ProtocolError(`${key} must be a non-negative number.`);
|
|
934
|
+
}
|
|
935
|
+
return value;
|
|
936
|
+
}
|
|
924
937
|
function optionalCliConfigField(record, key) {
|
|
925
938
|
const value = record[key];
|
|
926
939
|
if (value === void 0 || value === null) {
|
|
@@ -1075,6 +1088,8 @@ function connect(state, getMainTask, getQueueTask, onMessage) {
|
|
|
1075
1088
|
var mainTask = null;
|
|
1076
1089
|
var queueTask = null;
|
|
1077
1090
|
var agentState = loadState();
|
|
1091
|
+
var consecutiveQueueFailures = 0;
|
|
1092
|
+
var MAX_CONSECUTIVE_QUEUE_FAILURES = 5;
|
|
1078
1093
|
var connState = {
|
|
1079
1094
|
socket: null,
|
|
1080
1095
|
reconnectTimer: null,
|
|
@@ -1128,7 +1143,9 @@ function finishTask(taskId, status, payload) {
|
|
|
1128
1143
|
slot.set(null);
|
|
1129
1144
|
recordTaskFinish(current, status, payload);
|
|
1130
1145
|
if (status === "completed") {
|
|
1131
|
-
if (current.targetMode
|
|
1146
|
+
if (current.targetMode === "queue") {
|
|
1147
|
+
consecutiveQueueFailures = 0;
|
|
1148
|
+
} else {
|
|
1132
1149
|
agentState.sessionReady = true;
|
|
1133
1150
|
persistState(agentState);
|
|
1134
1151
|
}
|
|
@@ -1152,7 +1169,14 @@ function finishTask(taskId, status, payload) {
|
|
|
1152
1169
|
taskId,
|
|
1153
1170
|
error: typeof payload === "string" ? payload : "\u4EFB\u52A1\u6267\u884C\u5931\u8D25\u3002"
|
|
1154
1171
|
});
|
|
1155
|
-
if (current.targetMode === "queue")
|
|
1172
|
+
if (current.targetMode === "queue") {
|
|
1173
|
+
consecutiveQueueFailures += 1;
|
|
1174
|
+
if (consecutiveQueueFailures >= MAX_CONSECUTIVE_QUEUE_FAILURES) {
|
|
1175
|
+
console.log(`[agent:${EMPLOYEE_ID}] \u8FDE\u7EED ${consecutiveQueueFailures} \u6B21\u961F\u5217\u4EFB\u52A1\u5931\u8D25\uFF0C\u6682\u505C\u63A5\u53D7\u65B0\u7684\u961F\u5217\u4EFB\u52A1\u3002\u7B49\u5F85\u624B\u52A8\u6062\u590D\u3002`);
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
requestTask2();
|
|
1179
|
+
}
|
|
1156
1180
|
}
|
|
1157
1181
|
var runnerDeps = {
|
|
1158
1182
|
findActiveTask,
|
|
@@ -1166,6 +1190,14 @@ var runnerDeps = {
|
|
|
1166
1190
|
}
|
|
1167
1191
|
};
|
|
1168
1192
|
function startTask(message) {
|
|
1193
|
+
if (message.targetMode === "queue" && consecutiveQueueFailures >= MAX_CONSECUTIVE_QUEUE_FAILURES) {
|
|
1194
|
+
send2({
|
|
1195
|
+
type: "task.failed",
|
|
1196
|
+
taskId: message.taskId,
|
|
1197
|
+
error: `Agent \u8FDE\u7EED ${consecutiveQueueFailures} \u6B21\u961F\u5217\u4EFB\u52A1\u5931\u8D25\uFF0C\u6682\u505C\u63A5\u53D7\u65B0\u961F\u5217\u4EFB\u52A1\uFF0C\u7B49\u5F85\u624B\u52A8\u6062\u590D\u3002`
|
|
1198
|
+
});
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1169
1201
|
const slot = slotForTargetMode(message.targetMode);
|
|
1170
1202
|
if (slot.get()) {
|
|
1171
1203
|
send2({
|
|
@@ -1219,6 +1251,22 @@ function handleServerMessage(message) {
|
|
|
1219
1251
|
startTask(message);
|
|
1220
1252
|
return;
|
|
1221
1253
|
}
|
|
1254
|
+
if (message.type === "agent.registered") {
|
|
1255
|
+
const serverCount = message.consecutiveQueueFailures;
|
|
1256
|
+
if (serverCount > consecutiveQueueFailures) {
|
|
1257
|
+
consecutiveQueueFailures = serverCount;
|
|
1258
|
+
if (consecutiveQueueFailures >= MAX_CONSECUTIVE_QUEUE_FAILURES) {
|
|
1259
|
+
console.log(`[agent:${EMPLOYEE_ID}] \u4ECE\u670D\u52A1\u5668\u540C\u6B65\u8FDE\u7EED\u5931\u8D25\u8BA1\u6570 ${consecutiveQueueFailures}\uFF0C\u6682\u505C\u63A5\u53D7\u961F\u5217\u4EFB\u52A1\u3002`);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (message.type === "queue.resume") {
|
|
1265
|
+
consecutiveQueueFailures = 0;
|
|
1266
|
+
console.log(`[agent:${EMPLOYEE_ID}] \u961F\u5217\u4EFB\u52A1\u5DF2\u6062\u590D\uFF0C\u91CD\u65B0\u5F00\u59CB\u63A5\u53D7\u4EFB\u52A1\u3002`);
|
|
1267
|
+
requestTask2();
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1222
1270
|
cancelTask(message.taskId);
|
|
1223
1271
|
}
|
|
1224
1272
|
function connect2() {
|
|
@@ -1286,7 +1334,7 @@ if (isCli) {
|
|
|
1286
1334
|
getArgValue2 = getArgValue, resolveWorkspace3 = resolveWorkspace2, resolveAgentDir2 = resolveAgentDir, resolvePidFile2 = resolvePidFile, resolveLogDir2 = resolveLogDir, applyCliArgsToEnv2 = applyCliArgsToEnv;
|
|
1287
1335
|
const args = process.argv.slice(2);
|
|
1288
1336
|
if (args.includes("--version") || args.includes("-v")) {
|
|
1289
|
-
console.log("0.3.
|
|
1337
|
+
console.log("0.3.14");
|
|
1290
1338
|
process.exit(0);
|
|
1291
1339
|
}
|
|
1292
1340
|
if (args.includes("--help") || args.includes("-h")) {
|