dashclaw 4.1.2 → 4.2.1

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.
Files changed (3) hide show
  1. package/README.md +14 -1
  2. package/dashclaw.js +54 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1112,6 +1112,18 @@ if (action.status === 'pending_approval') {
1112
1112
  // Agent executes the x402 call, then records the result
1113
1113
  const x402Result = { summary: 'Found 14 papers', data: { count: 14 }, url: 'https://...' };
1114
1114
  await claw.recordPurchaseResult(action.id, x402Result);
1115
+
1116
+ // Or self-report a SETTLED payment in ONE call — when you pay OUTSIDE a
1117
+ // governance hook (e.g. a native-shell agentcash wrapper) and just need the
1118
+ // spend on Spend → x402. The server resolves/auto-registers the provider from
1119
+ // `provider`, so you don't register one first.
1120
+ const settled = await claw.recordX402Purchase({
1121
+ agent_id: 'research-agent',
1122
+ provider: 'stableenrich.dev', // name/origin
1123
+ spend: 0.007, // settled USD
1124
+ transaction_hash: '0xabc…',
1125
+ request_id: 'req_123',
1126
+ });
1115
1127
  ```
1116
1128
 
1117
1129
  - `claw.listProviders(filters?)` -- GET /api/x402/providers
@@ -1123,8 +1135,9 @@ await claw.recordPurchaseResult(action.id, x402Result);
1123
1135
  - `claw.recordPurchase(data)` -- POST /api/x402/purchases (guard-gated; returns `{ action, purchase, decision }`)
1124
1136
  - `claw.listPurchases(filters?)` -- GET /api/x402/purchases
1125
1137
  - `claw.recordPurchaseResult(actionId, result)` -- POST /api/artifacts (attaches the x402 result snapshot to the purchase action via `source_action_id`)
1138
+ - `claw.recordX402Purchase({ agent_id, provider, spend, transaction_hash?, request_id?, ... })` -- one call: govern + record the purchase, mark it succeeded, and attach the receipt. Use for the **pay-outside-a-hook** self-report pattern. Python parity: `record_x402_purchase(...)`.
1126
1139
 
1127
- > **Note:** `recordPurchaseResult` is Node-only. It is a convenience wrapper over `POST /api/artifacts` — Python callers post directly to that endpoint with `artifact_type: 'x402_purchase_result'` and `source_action_id` set to the `act_` id from `record_purchase`.
1140
+ > **Note:** `recordPurchaseResult` is Node-only. It is a convenience wrapper over `POST /api/artifacts` — Python callers post directly to that endpoint with `artifact_type: 'x402_purchase_result'` and `source_action_id` set to the `act_` id from `record_purchase`. (`recordX402Purchase` / `record_x402_purchase` exist in both SDKs and handle the receipt internally.)
1128
1141
 
1129
1142
  > **Operator surface (no SDK wrapper):** The platform also exposes `GET /api/finops/spend?lens=fleet|claude-code` — a read-only operator rollup that aggregates agent LLM cost + x402 purchases (Fleet lens) or Code Sessions cost (Claude-Code lens). It is a presentation layer backed by repository functions (`getFleetSpend` / `getClaudeCodeSpend`), **not** an SDK method, so it does not appear in the method count. Query it directly over HTTP.
1130
1143
 
package/dashclaw.js CHANGED
@@ -1480,6 +1480,60 @@ class DashClaw {
1480
1480
  source_action_id: actionId,
1481
1481
  });
1482
1482
  }
1483
+ /**
1484
+ * Convenience: record a SETTLED x402 payment end-to-end in one call — govern +
1485
+ * record the purchase, mark it succeeded, and (when given) attach the on-chain
1486
+ * receipt. Use this when your agent pays OUTSIDE an OpenClaw governance hook
1487
+ * (e.g. a Codex/native-shell agentcash wrapper) and must self-report so the
1488
+ * spend lands on Spend → x402. The server resolves/auto-registers the provider
1489
+ * from `provider`, so you do NOT register one first. Only call this for a
1490
+ * settled payment — a free quote or a failed call has nothing to record.
1491
+ *
1492
+ * @param {Object} p
1493
+ * @param {string} p.agent_id
1494
+ * @param {string} p.provider - provider name/origin, e.g. "stableenrich.dev"
1495
+ * @param {number} p.spend - settled USD amount (> 0)
1496
+ * @param {string} [p.declared_goal]
1497
+ * @param {string} [p.purchase_reason]
1498
+ * @param {string} [p.context_gap]
1499
+ * @param {string} [p.expected_value]
1500
+ * @param {string} [p.transaction_hash] - on-chain tx hash (receipt evidence)
1501
+ * @param {string} [p.request_id]
1502
+ * @param {string} [p.currency='USDC']
1503
+ * @param {string} [p.payment_method='x402']
1504
+ * @returns {Promise<{ action, purchase, decision, outcome }>}
1505
+ */
1506
+ async recordX402Purchase({
1507
+ agent_id, provider, spend,
1508
+ declared_goal, purchase_reason, context_gap, expected_value,
1509
+ transaction_hash, request_id, currency = 'USDC', payment_method = 'x402',
1510
+ } = {}) {
1511
+ const origin = provider;
1512
+ const res = await this.recordPurchase({
1513
+ agent_id,
1514
+ provider: origin,
1515
+ declared_goal: declared_goal || `x402 capability call to ${origin}`,
1516
+ purchase_reason: purchase_reason || `Paid x402 capability call to ${origin}`,
1517
+ context_gap: context_gap || `Capability gated behind payment at ${origin}`,
1518
+ expected_value: expected_value || `Paid result from ${origin}`,
1519
+ spend_amount: spend,
1520
+ cost_estimate: spend,
1521
+ currency,
1522
+ payment_method,
1523
+ });
1524
+ const actionId = res?.action?.action_id ?? res?.action?.id;
1525
+ let outcome = null;
1526
+ if (actionId) {
1527
+ outcome = await this.reportActionSuccess(actionId, `x402 settled: $${spend} ${currency} at ${origin}`);
1528
+ if (transaction_hash || request_id) {
1529
+ await this.recordPurchaseResult(actionId, {
1530
+ summary: `x402 settled: $${spend} ${currency} at ${origin}`,
1531
+ data: { origin, transactionHash: transaction_hash, requestId: request_id },
1532
+ });
1533
+ }
1534
+ }
1535
+ return { action: res?.action, purchase: res?.purchase, decision: res?.decision, outcome };
1536
+ }
1483
1537
  }
1484
1538
 
1485
1539
  export { DashClaw, ApprovalDeniedError, GuardBlockedError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dashclaw",
3
- "version": "4.1.2",
3
+ "version": "4.2.1",
4
4
  "description": "Minimal governance runtime for AI agents. Intercept, govern, and verify agent actions.",
5
5
  "type": "module",
6
6
  "publishConfig": {