@lawrenceliang-btc/atel-sdk 1.2.12 → 1.2.13

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.
@@ -1,6 +1,23 @@
1
- export function getDirectExecutableActions(eventType, recommendedActions) {
1
+ export function getDirectExecutableActions(eventType, recommendedActions, payload = {}, policy = {}) {
2
2
  if (!Array.isArray(recommendedActions) || recommendedActions.length === 0) return [];
3
3
 
4
+ if (eventType === 'order_created') {
5
+ const amount = Number(payload?.priceAmount || 0);
6
+ const autoPolicy = policy?.autoPolicy || {};
7
+ const acceptMaxAmount = Number(autoPolicy.acceptMaxAmount || 0);
8
+ const shouldAutoAcceptFree = policy?.taskMode === 'auto' && policy?.autoAcceptPlatform === true && amount <= 0;
9
+ const shouldAutoAcceptByPolicy = autoPolicy.acceptOrders === true && (acceptMaxAmount <= 0 || amount <= acceptMaxAmount);
10
+ if (shouldAutoAcceptFree || shouldAutoAcceptByPolicy) {
11
+ return recommendedActions.filter((action) =>
12
+ action?.type === 'cli' &&
13
+ action?.action === 'accept' &&
14
+ Array.isArray(action.command) &&
15
+ action.command[0] === 'atel'
16
+ );
17
+ }
18
+ return [];
19
+ }
20
+
4
21
  if (eventType === 'order_accepted') {
5
22
  return recommendedActions.filter((action) =>
6
23
  action?.type === 'cli' &&
@@ -0,0 +1,77 @@
1
+ const TERMINAL_ORDER_STATUSES = new Set(['cancelled', 'settled', 'rejected', 'expired']);
2
+
3
+ function normalizeOrderCancelContext(orderInfo = {}) {
4
+ const orderId = orderInfo.orderId || orderInfo.OrderID || orderInfo.id || orderInfo.ID || '';
5
+ const orderStatus = String(orderInfo.status || orderInfo.Status || '').trim().toLowerCase();
6
+ const requesterDid = orderInfo.requesterDid || orderInfo.RequesterDID || orderInfo.requester_did || '';
7
+ const executorDid = orderInfo.executorDid || orderInfo.ExecutorDID || orderInfo.executor_did || '';
8
+
9
+ return {
10
+ orderId,
11
+ orderStatus,
12
+ requesterDid,
13
+ executorDid,
14
+ };
15
+ }
16
+
17
+ function parseOrderCancelArgs(restArgs = []) {
18
+ const args = Array.isArray(restArgs) ? restArgs : [String(restArgs || '')];
19
+ const reasonParts = [];
20
+ let dryRun = false;
21
+
22
+ for (const arg of args) {
23
+ if (arg === '--dry-run') {
24
+ dryRun = true;
25
+ continue;
26
+ }
27
+ if (arg) reasonParts.push(arg);
28
+ }
29
+
30
+ return {
31
+ dryRun,
32
+ reason: reasonParts.join(' ').trim(),
33
+ };
34
+ }
35
+
36
+ function preflightOrderCancel(orderInfo, currentDid) {
37
+ const ctx = normalizeOrderCancelContext(orderInfo);
38
+ const isExecutor = ctx.executorDid && currentDid ? ctx.executorDid === currentDid : false;
39
+ const isRequester = ctx.requesterDid && currentDid ? ctx.requesterDid === currentDid : false;
40
+
41
+ if (!ctx.orderId) {
42
+ return { ok: false, code: 'missing_order_id', error: 'Order info is missing an order ID.', ...ctx, currentDid, isRequester, isExecutor, terminal: false };
43
+ }
44
+
45
+ if (!ctx.orderStatus) {
46
+ return { ok: false, code: 'missing_status', error: `Unable to determine order status for ${ctx.orderId}.`, ...ctx, currentDid, isRequester, isExecutor, terminal: false };
47
+ }
48
+
49
+ if (TERMINAL_ORDER_STATUSES.has(ctx.orderStatus)) {
50
+ return { ok: false, code: 'terminal_status', error: `Order ${ctx.orderId} is already ${ctx.orderStatus}.`, ...ctx, currentDid, isRequester, isExecutor, terminal: true };
51
+ }
52
+
53
+ if (!currentDid) {
54
+ return { ok: false, code: 'missing_identity', error: 'Current DID is not initialized.', ...ctx, currentDid: '', isRequester, isExecutor, terminal: false };
55
+ }
56
+
57
+ if (!ctx.requesterDid) {
58
+ return { ok: false, code: 'missing_requester', error: `Order ${ctx.orderId} is missing requester DID; cannot verify cancel permission.`, ...ctx, currentDid, isRequester: false, isExecutor, terminal: false };
59
+ }
60
+
61
+ if (!isRequester) {
62
+ return {
63
+ ok: false,
64
+ code: 'not_requester',
65
+ error: `Only the requester can cancel order ${ctx.orderId}. Current DID ${currentDid} does not match requester DID ${ctx.requesterDid}.`,
66
+ ...ctx,
67
+ currentDid,
68
+ isRequester: false,
69
+ isExecutor,
70
+ terminal: false,
71
+ };
72
+ }
73
+
74
+ return { ok: true, ...ctx, currentDid, isRequester: true, isExecutor, terminal: false };
75
+ }
76
+
77
+ export { TERMINAL_ORDER_STATUSES, normalizeOrderCancelContext, parseOrderCancelArgs, preflightOrderCancel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawrenceliang-btc/atel-sdk",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "ATEL Protocol SDK - Agent Trust & Exchange Layer",
5
5
  "repository": {
6
6
  "type": "git",
@@ -72,4 +72,4 @@
72
72
  "vitest": "^3.2.4"
73
73
  },
74
74
  "license": "MIT"
75
- }
75
+ }
@@ -99,7 +99,7 @@ mkdir -p "$WORKSPACE" && cd "$WORKSPACE"
99
99
  # 安装 SDK
100
100
  if ! command -v atel &> /dev/null; then
101
101
  echo "📦 Installing ATEL SDK..."
102
- npm install -g @lawrenceliang-btc/atel-sdk || { echo "❌ SDK install failed"; exit 1; }
102
+ npm install -g @lawrenceliang-btc/atel-sdk@latest || { echo "❌ SDK install failed"; exit 1; }
103
103
  fi
104
104
  echo "✅ SDK: $(command -v atel)"
105
105
 
@@ -226,7 +226,7 @@ echo "========================================="
226
226
  处理 paid order 时,必须遵守:
227
227
 
228
228
  1. 不要默认所有订单都在 Base
229
- 2. 先用 `atel order-info <orderId>` `atel milestone-status <orderId>` 看 `chain`
229
+ 2. 先用 `atel order-info <orderId>` `chain`,必要时再用 `GET /trade/v1/order/<orderId>/timeline` 复核历史事件
230
230
  3. 后续所有跟链有关的判断都跟 `order.chain`
231
231
  4. 如果订单是 `bsc`,就不要再按 `base` 钱包、`base` gas、`base` 浏览器去理解
232
232
 
@@ -312,7 +312,7 @@ atel trade-task <capability> "任务描述" --budget 5
312
312
  ```bash
313
313
  cd ~/atel-workspace
314
314
  atel order-info <orderId>
315
- atel milestone-status <orderId>
315
+ atel order-info <orderId>
316
316
  atel milestone-feedback <orderId> --approve
317
317
  ```
318
318
 
@@ -15,7 +15,7 @@ cd "$WORKSPACE"
15
15
  # 2. 安装 SDK
16
16
  if ! command -v atel &> /dev/null; then
17
17
  echo "📦 Installing ATEL SDK..."
18
- npm install -g @lawrenceliang-btc/atel-sdk || { echo "❌ SDK install failed"; exit 1; }
18
+ npm install -g @lawrenceliang-btc/atel-sdk@latest || { echo "❌ SDK install failed"; exit 1; }
19
19
  fi
20
20
  echo "✅ SDK: $(command -v atel)"
21
21
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  **First-time setup:**
8
8
  ```bash
9
- npm install -g @lawrenceliang-btc/atel-sdk
9
+ npm install -g @lawrenceliang-btc/atel-sdk@latest
10
10
  atel init my-agent
11
11
  atel register "My Agent" "general,research"
12
12
  atel start 3100