@lawrenceliang-btc/atel-sdk 0.8.13 → 0.8.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/bin/atel.mjs +15 -4
- package/package.json +1 -1
package/bin/atel.mjs
CHANGED
|
@@ -555,7 +555,8 @@ async function cmdStart(port) {
|
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
async function pushResultWithRetry(task, taskId, resultPayload, opts = {}) {
|
|
558
|
-
const maxAttempts = opts.maxAttempts || 4
|
|
558
|
+
const maxAttempts = opts.maxAttempts || 3; // Reduced from 4 to 3
|
|
559
|
+
const retryDelays = [1000, 2000, 4000]; // Exponential backoff: 1s, 2s, 4s
|
|
559
560
|
let lastErr = null;
|
|
560
561
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
561
562
|
try {
|
|
@@ -564,9 +565,14 @@ async function cmdStart(port) {
|
|
|
564
565
|
} catch (e) {
|
|
565
566
|
lastErr = e;
|
|
566
567
|
log({ event: 'result_push_retry', taskId, attempt, maxAttempts, error: e.message });
|
|
567
|
-
if (attempt < maxAttempts)
|
|
568
|
+
if (attempt < maxAttempts) {
|
|
569
|
+
const delay = retryDelays[attempt - 1] || 4000;
|
|
570
|
+
await sleep(delay);
|
|
571
|
+
}
|
|
568
572
|
}
|
|
569
573
|
}
|
|
574
|
+
// After max retries, give up and log
|
|
575
|
+
log({ event: 'result_push_failed', taskId, to: task.from, error: lastErr?.message || 'unknown_error', attempts: maxAttempts });
|
|
570
576
|
return { ok: false, error: lastErr?.message || 'unknown_error', attempts: maxAttempts };
|
|
571
577
|
}
|
|
572
578
|
|
|
@@ -1432,7 +1438,7 @@ async function cmdStart(port) {
|
|
|
1432
1438
|
log({ event: 'result_push_recovered', taskId: item.taskId, to: item.task?.from, via: push.targetUrl, relay: push.isRelay, attempts: (item.retryCount || 0) + push.attempts });
|
|
1433
1439
|
} else {
|
|
1434
1440
|
const retryCount = (item.retryCount || 0) + 2;
|
|
1435
|
-
if (retryCount >=
|
|
1441
|
+
if (retryCount >= 6) { // Reduced from 10 to 6
|
|
1436
1442
|
log({ event: 'result_push_give_up', taskId: item.taskId, to: item.task?.from, error: push.error, retryCount });
|
|
1437
1443
|
} else {
|
|
1438
1444
|
remaining.push({ ...item, retryCount, lastError: push.error, nextRetryAt: Date.now() + Math.min(60000, 5000 * Math.pow(2, Math.min(retryCount, 6))) });
|
|
@@ -1440,7 +1446,7 @@ async function cmdStart(port) {
|
|
|
1440
1446
|
}
|
|
1441
1447
|
} catch (e) {
|
|
1442
1448
|
const retryCount = (item.retryCount || 0) + 1;
|
|
1443
|
-
if (retryCount >=
|
|
1449
|
+
if (retryCount >= 6) { // Reduced from 10 to 6
|
|
1444
1450
|
log({ event: 'result_push_give_up', taskId: item.taskId, to: item.task?.from, error: e.message, retryCount });
|
|
1445
1451
|
} else {
|
|
1446
1452
|
remaining.push({ ...item, retryCount, lastError: e.message, nextRetryAt: Date.now() + Math.min(60000, 5000 * Math.pow(2, Math.min(retryCount, 6))) });
|
|
@@ -1682,6 +1688,11 @@ async function cmdTask(target, taskJson) {
|
|
|
1682
1688
|
|
|
1683
1689
|
// Parse task payload and extract risk level
|
|
1684
1690
|
const payload = typeof taskJson === 'string' ? JSON.parse(taskJson) : taskJson;
|
|
1691
|
+
if (!payload || typeof payload !== 'object') {
|
|
1692
|
+
console.error('Error: Task payload is required and must be a valid JSON object');
|
|
1693
|
+
console.error('Usage: atel task <DID> \'{"action":"general","payload":{"prompt":"..."}}\'');
|
|
1694
|
+
process.exit(1);
|
|
1695
|
+
}
|
|
1685
1696
|
const risk = payload._risk || 'low';
|
|
1686
1697
|
delete payload._risk;
|
|
1687
1698
|
const force = payload._force || false;
|