@seekdaseek/plugin-agentfeed 0.1.1 → 0.1.2

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.d.ts CHANGED
@@ -18,6 +18,8 @@ declare class AgentFeedService extends Service {
18
18
  private payerAddress;
19
19
  /** path -> { usd, checkedAt } of last approved quote */
20
20
  private approvedQuotes;
21
+ /** requirements that survived the spend policy on the most recent payment */
22
+ private lastSurvivingReqs;
21
23
  /** lifetime spend counter for this process (informational) */
22
24
  private totalSpentUsd;
23
25
  constructor(runtime: IAgentRuntime);
package/dist/index.js CHANGED
@@ -23,6 +23,8 @@ var AgentFeedService = class _AgentFeedService extends Service {
23
23
  payerAddress = "";
24
24
  /** path -> { usd, checkedAt } of last approved quote */
25
25
  approvedQuotes = /* @__PURE__ */ new Map();
26
+ /** requirements that survived the spend policy on the most recent payment */
27
+ lastSurvivingReqs = [];
26
28
  /** lifetime spend counter for this process (informational) */
27
29
  totalSpentUsd = 0;
28
30
  static async start(runtime) {
@@ -51,10 +53,14 @@ var AgentFeedService = class _AgentFeedService extends Service {
51
53
  this.payerAddress = keypair.address;
52
54
  const signer = toClientSvmSigner(keypair);
53
55
  const capBaseUnits = Math.round(this.maxSpendUsd * 10 ** USDC_DECIMALS);
54
- const maxSpendPolicy = (_v, reqs) => reqs.filter((r) => {
55
- const raw = Number(r?.maxAmountRequired ?? r?.amount ?? r?.maxAmount);
56
- return Number.isFinite(raw) && raw > 0 && raw <= capBaseUnits;
57
- });
56
+ const maxSpendPolicy = (_v, reqs) => {
57
+ const surviving = reqs.filter((r) => {
58
+ const raw = Number(r?.maxAmountRequired ?? r?.amount ?? r?.maxAmount);
59
+ return Number.isFinite(raw) && raw > 0 && raw <= capBaseUnits;
60
+ });
61
+ this.lastSurvivingReqs = surviving;
62
+ return surviving;
63
+ };
58
64
  this.payFetch = wrapFetchWithPaymentFromConfig(fetch, {
59
65
  schemes: [{ network: "solana:*", client: new ExactSvmScheme(signer) }],
60
66
  policies: [maxSpendPolicy]
@@ -132,8 +138,19 @@ var AgentFeedService = class _AgentFeedService extends Service {
132
138
  if (!res.ok) {
133
139
  return { ok: false, status: res.status, data, error: `AgentFeed HTTP ${res.status}` };
134
140
  }
135
- if (settlement) this.totalSpentUsd += quotedUsd;
136
- return { ok: true, status: res.status, data, paidUsd: settlement ? quotedUsd : 0, settlement };
141
+ let paidUsd = 0;
142
+ if (settlement) {
143
+ const s = settlement;
144
+ let raw = Number(s?.amount ?? s?.paidAmount);
145
+ if (!Number.isFinite(raw) || raw <= 0) {
146
+ const net = String(s?.network ?? "");
147
+ const req = this.lastSurvivingReqs.find((r) => String(r?.network ?? "") === net) ?? this.lastSurvivingReqs[0];
148
+ raw = Number(req?.maxAmountRequired ?? req?.amount ?? req?.maxAmount);
149
+ }
150
+ paidUsd = Number.isFinite(raw) && raw > 0 ? raw / 10 ** USDC_DECIMALS : quotedUsd;
151
+ this.totalSpentUsd += paidUsd;
152
+ }
153
+ return { ok: true, status: res.status, data, paidUsd, settlement };
137
154
  } catch (e) {
138
155
  return { ok: false, status: 0, data: null, error: e?.message || String(e) };
139
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seekdaseek/plugin-agentfeed",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "elizaOS plugin for AgentFeed — paid crypto market data (liquidations, positioning, funding, token risk) over x402 micropayments on Solana. $0.001–$0.01 per call in USDC, no API keys, no subscriptions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",