@lawrenceliang-btc/atel-sdk 1.0.5 → 1.0.7
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 +23 -22
- package/package.json +1 -1
package/bin/atel.mjs
CHANGED
|
@@ -2238,9 +2238,11 @@ async function cmdStart(port) {
|
|
|
2238
2238
|
}
|
|
2239
2239
|
|
|
2240
2240
|
// 4. Agent command hook: forward notification to agent's AI
|
|
2241
|
-
//
|
|
2241
|
+
// Skip order_created — accepting orders requires human confirmation
|
|
2242
|
+
// Only auto-trigger for milestone-related events
|
|
2242
2243
|
const agentCmd = detectedAgentCmd;
|
|
2243
|
-
|
|
2244
|
+
const autoTriggerEvents = ['order_accepted', 'milestone_plan_confirmed', 'milestone_submitted', 'milestone_verified', 'milestone_rejected'];
|
|
2245
|
+
if (agentCmd && prompt && autoTriggerEvents.includes(event)) {
|
|
2244
2246
|
// Add working directory context so agent runs atel commands in the right place
|
|
2245
2247
|
const cwd = process.cwd();
|
|
2246
2248
|
const cwdNote = `\n\n重要:所有 atel 命令必须在目录 ${cwd} 下执行(cd ${cwd} && atel ...)。`;
|
|
@@ -3162,15 +3164,14 @@ async function cmdStart(port) {
|
|
|
3162
3164
|
});
|
|
3163
3165
|
if (!resp.ok) return;
|
|
3164
3166
|
const data = await resp.json();
|
|
3165
|
-
// Relay returns {messages: [{id, sender, message, createdAt}]}
|
|
3166
|
-
// Each message.message contains {method, path, body}
|
|
3167
3167
|
const rawMessages = data.messages || data.requests || [];
|
|
3168
|
-
|
|
3168
|
+
if (rawMessages.length === 0) return;
|
|
3169
|
+
|
|
3170
|
+
const processedIds = []; // track successfully processed message IDs for ACK
|
|
3171
|
+
|
|
3172
|
+
for (const m of rawMessages) {
|
|
3169
3173
|
const inner = m.message || m;
|
|
3170
|
-
|
|
3171
|
-
});
|
|
3172
|
-
for (const req of requests) {
|
|
3173
|
-
// Forward to local endpoint
|
|
3174
|
+
const req = typeof inner === 'string' ? JSON.parse(inner) : inner;
|
|
3174
3175
|
try {
|
|
3175
3176
|
const method = req.method || 'POST';
|
|
3176
3177
|
const fetchOpts = {
|
|
@@ -3180,22 +3181,22 @@ async function cmdStart(port) {
|
|
|
3180
3181
|
};
|
|
3181
3182
|
if (method !== 'GET' && method !== 'HEAD') fetchOpts.body = JSON.stringify(req.body);
|
|
3182
3183
|
const localResp = await fetch(`http://127.0.0.1:${p}${req.path}`, fetchOpts);
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
await fetch(`${relayUrl}/relay/v1/respond`, {
|
|
3186
|
-
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
3187
|
-
body: JSON.stringify({ requestId: req.requestId, status: localResp.status, body }),
|
|
3188
|
-
signal: AbortSignal.timeout(5000),
|
|
3189
|
-
});
|
|
3184
|
+
await localResp.json();
|
|
3185
|
+
if (m.id) processedIds.push(m.id); // mark for ACK
|
|
3190
3186
|
} catch (e) {
|
|
3191
|
-
//
|
|
3192
|
-
|
|
3193
|
-
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
3194
|
-
body: JSON.stringify({ requestId: req.requestId, status: 500, body: { error: e.message } }),
|
|
3195
|
-
signal: AbortSignal.timeout(5000),
|
|
3196
|
-
}).catch(() => {});
|
|
3187
|
+
// Still ACK even on local processing error (to prevent infinite retry)
|
|
3188
|
+
if (m.id) processedIds.push(m.id);
|
|
3197
3189
|
}
|
|
3198
3190
|
}
|
|
3191
|
+
|
|
3192
|
+
// ACK processed messages so relay doesn't re-deliver them
|
|
3193
|
+
if (processedIds.length > 0) {
|
|
3194
|
+
await fetch(`${relayUrl}/relay/v1/ack`, {
|
|
3195
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
3196
|
+
body: JSON.stringify({ did: id.did, ids: processedIds }),
|
|
3197
|
+
signal: AbortSignal.timeout(5000),
|
|
3198
|
+
}).catch(() => {});
|
|
3199
|
+
}
|
|
3199
3200
|
} catch {}
|
|
3200
3201
|
};
|
|
3201
3202
|
|