@priors/plugin-elizaos 0.1.0 → 0.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.
- package/README.md +7 -8
- package/elizaos.plugin.json +1 -1
- package/package.json +2 -2
- package/src/index.js +17 -9
- package/src/parse.js +33 -2
- package/src/priors.js +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Add it to the character's plugins (elizaOS 1.7 or later):
|
|
|
21
21
|
"secrets": {
|
|
22
22
|
"PRIORS_KEY_FILE": "/path/to/agent-wallet.key",
|
|
23
23
|
"PRIORS_AGENT_ID": "1234",
|
|
24
|
-
"PRIORS_PAY_HOSTS": "
|
|
24
|
+
"PRIORS_PAY_HOSTS": "api.priors.trade"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -35,6 +35,7 @@ Add it to the character's plugins (elizaOS 1.7 or later):
|
|
|
35
35
|
| `PRIORS_MAX_PRICE_USD` | most one x402 call may cost (default 1.00) |
|
|
36
36
|
| `PRIORS_STATE_DIR` | where the daily caps and sent payments are kept: a directory only this user can write to, with no group- or world-writable parent (otherwise nothing is signed) |
|
|
37
37
|
| `PRIORS_MAX_SPEND_DAY_USD`, `PRIORS_MAX_BORROW_DAY_USD` | optional daily caps |
|
|
38
|
+
| `PRIORS_AUTO_BORROW_USD` | optional, off by default (`@priors/mcp` 0.15.0): auto-borrow. A payment whose message names no borrow then borrows the gap on its own, up to this amount, for 14 days, only while the agent wallet's Autopay covers the loan. Needs `PRIORS_MAX_BORROW_DAY_USD` above 0, `PRIORS_PAY_HOSTS`, `PRIORS_AGENT_ID` and `PRIORS_STATE_DIR` |
|
|
38
39
|
|
|
39
40
|
Without a key, only `PRIORS_AGENT_RECORD` works.
|
|
40
41
|
|
|
@@ -44,13 +45,14 @@ Without a key, only `PRIORS_AGENT_RECORD` works.
|
|
|
44
45
|
|---|---|---|
|
|
45
46
|
| `PRIORS_AGENT_RECORD` | reads another agent's record on the hosted read-only Priors server: its line, repaid and late loans, defaults, score. The message names the agent, as `#1234` | no |
|
|
46
47
|
| `PRIORS_CREDIT_STATUS` | reads this agent's own line: available, drawn, open loans and due dates | no |
|
|
47
|
-
| `PRIORS_PAY_X402` | pays an x402 URL at most the price the message names; if the wallet is short, borrows the gap
|
|
48
|
+
| `PRIORS_PAY_X402` | pays an x402 URL at most the price the message names, with GET, or with POST when the message gives a JSON body (a chat completion); if the wallet is short, borrows the gap when the message names the most to borrow (`borrow up to 5`; a loan is at least the pool's minimum, 5 USDG today), or, with `PRIORS_AUTO_BORROW_USD` set, on its own within it. "don't borrow" never borrows | yes |
|
|
48
49
|
| `PRIORS_REPAY` | repays the loan the message names (`loan 50900`), principal and fee | yes |
|
|
49
50
|
|
|
50
51
|
Example messages:
|
|
51
52
|
|
|
52
|
-
- "Before we pay it, check agent #
|
|
53
|
-
- "Pay https://
|
|
53
|
+
- "Before we pay it, check agent #1234's record on Priors."
|
|
54
|
+
- "Pay https://api.priors.trade/v1/report/1234 at most 0.05, borrow up to 5 if the wallet is short."
|
|
55
|
+
- "Buy a chat completion from https://models.example/v1/chat/completions at most 0.02: {"model": "…", "messages": [{"role": "user", "content": "…"}]}" (the URL, the price and any borrow are read outside the JSON; `models.example` stands for an OpenAI-compatible model API you choose that charges over x402, its host in `PRIORS_PAY_HOSTS`)
|
|
54
56
|
- "Repay loan 50900 now."
|
|
55
57
|
|
|
56
58
|
## How it works
|
|
@@ -70,10 +72,7 @@ URLs are read from the user's message, never chosen by the model.
|
|
|
70
72
|
|
|
71
73
|
## Demo
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
A production run in elizaOS 1.7.2 on 2026-10-30 (agent #437, Robinhood Chain mainnet), its own output lines with waits
|
|
76
|
-
over 6 seconds shortened. The agent reads the seller's record (Blockpin, agent #9233), then pays its x402 check (0.10
|
|
75
|
+
A production run in elizaOS 1.7.2 on 2026-10-30 (agent #437, Robinhood Chain mainnet). The agent reads the seller's record, then pays its x402 check (0.10
|
|
77
76
|
USDG) from an empty wallet: PRIORS_PAY_X402 borrows 5 USDG, the pool's minimum loan (loan #50896). The agent's income
|
|
78
77
|
then arrives from another wallet, and PRIORS_REPAY closes the loan for 5.011666 USDG.
|
|
79
78
|
Transactions: [borrow](https://robinhoodchain.blockscout.com/tx/0x1a17ff6a4f4329d4a16fee0c7654f43104b037a0d9109f9c7ee4c503cbdd2d81),
|
package/elizaos.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "priors",
|
|
3
3
|
"name": "@priors/plugin-elizaos",
|
|
4
4
|
"description": "Priors credit for agents on Robinhood Chain: pay x402 APIs and borrow the gap in USDG from the agent's line, repay it, and read another agent's repayment record before paying it.",
|
|
5
|
-
"version": "0.1
|
|
5
|
+
"version": "0.2.1",
|
|
6
6
|
"kind": "plugin",
|
|
7
7
|
"requiredSecrets": [],
|
|
8
8
|
"configSchema": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@priors/plugin-elizaos",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Priors credit for elizaOS agents: pay x402 APIs and borrow the gap in USDG from the agent's Priors line on Robinhood Chain, repay it, and read another agent's repayment record before paying it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
23
|
-
"@priors/mcp": "0.
|
|
23
|
+
"@priors/mcp": "0.15.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@elizaos/core": "^1.7.0"
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// @priors/plugin-elizaos: Priors credit for elizaOS agents. Four actions over the two Priors MCP servers (priors.js):
|
|
2
2
|
// read another agent's repayment record, read the agent's own line, pay an x402 URL that borrows the gap when the
|
|
3
3
|
// wallet is short, and repay a loan. Every amount and URL comes from the user's own message (parse.js); a payment
|
|
4
|
-
// borrows only when the message names the most to borrow
|
|
5
|
-
//
|
|
4
|
+
// borrows only when the message names the most to borrow, or, with the agent's PRIORS_AUTO_BORROW_USD set, on its own
|
|
5
|
+
// within that setting (a message saying not to borrow never does). A JSON body in the message is sent with POST (a
|
|
6
|
+
// chat completion bought over x402). The caps, the host allowlist and the signing are @priors/mcp's own.
|
|
6
7
|
import { priorsOf } from "./priors.js";
|
|
7
|
-
import { urlOf, agentIdOf, loanIdOf, maxPriceOf,
|
|
8
|
+
import { urlOf, agentIdOf, loanIdOf, maxPriceOf, borrowOf, bodyOf } from "./parse.js";
|
|
8
9
|
|
|
9
10
|
const textOf = (message) => String((message && message.content && message.content.text) || "");
|
|
10
11
|
|
|
@@ -48,21 +49,28 @@ export const creditStatusAction = {
|
|
|
48
49
|
export const payX402Action = {
|
|
49
50
|
name: "PRIORS_PAY_X402",
|
|
50
51
|
similes: ["PAY_X402", "PAY_HTTP_402", "BUY_API_CALL"],
|
|
51
|
-
description: "Pay an HTTP 402 (x402) URL in USDG from this agent's wallet. If the wallet is short, it borrows the gap from the agent's Priors line,
|
|
52
|
+
description: "Pay an HTTP 402 (x402) URL in USDG from this agent's wallet, with GET, or with POST when the message gives a JSON body (a chat completion, for one). If the wallet is short, it borrows the gap from the agent's Priors line, when the message names the most to borrow, or, with the agent's PRIORS_AUTO_BORROW_USD set, on its own within that setting while Autopay covers the loan. The message must name the URL and the most to pay. Real money.",
|
|
52
53
|
validate: async (_runtime, message) => !!urlOf(textOf(message)) && /\bpay|buy|call|fetch/i.test(textOf(message)),
|
|
53
54
|
handler: async (runtime, message, _state, _options, callback) => {
|
|
54
55
|
const text = textOf(message);
|
|
55
|
-
const
|
|
56
|
+
const b = bodyOf(text);
|
|
57
|
+
const rest = b ? text.replace(b.raw, " ") : text;
|
|
58
|
+
const url = urlOf(rest), maxPrice = maxPriceOf(rest), borrow = borrowOf(rest);
|
|
59
|
+
if (!url) return answer(callback, "PRIORS_PAY_X402", false, "Nothing was paid. Name the https URL to pay outside the request body.", {});
|
|
56
60
|
if (maxPrice === null || maxPrice <= 0) {
|
|
57
61
|
return answer(callback, "PRIORS_PAY_X402", false, `Nothing was paid. Say the most to pay for ${url}, for example "at most 0.10", and if the wallet may borrow, the most to borrow, for example "borrow up to 1".`, { url });
|
|
58
62
|
}
|
|
59
|
-
|
|
63
|
+
// a borrow the message names, 0 included, is passed as said; none named leaves it to @priors/mcp's own setting
|
|
64
|
+
const args = { url, max_price_usd: maxPrice, ...(borrow !== null ? { max_borrow_usd: borrow } : {}), ...(b ? { method: "POST", body: b.body } : {}) };
|
|
60
65
|
const r = await priorsOf(runtime).wallet("pay_url", args);
|
|
61
|
-
return answer(callback, "PRIORS_PAY_X402", r.ok, r.text, { url, maxPrice, maxBorrow });
|
|
66
|
+
return answer(callback, "PRIORS_PAY_X402", r.ok, r.text, { url, maxPrice, maxBorrow: borrow ?? 0, ...(b ? { method: "POST" } : {}) });
|
|
62
67
|
},
|
|
63
68
|
examples: [[
|
|
64
|
-
{ name: "{{user1}}", content: { text: "Pay https://
|
|
65
|
-
{ name: "{{agentName}}", content: { text: "Paid 0.
|
|
69
|
+
{ name: "{{user1}}", content: { text: "Pay https://api.priors.trade/v1/report/1234 at most 0.05, borrow up to 5 if the wallet is short." } },
|
|
70
|
+
{ name: "{{agentName}}", content: { text: "Paid 0.03 USDG; the wallet was short, so it borrowed 5 USDG, the pool's minimum loan, from the Priors line (loan #50900, due 6 November).", actions: ["PRIORS_PAY_X402"] } },
|
|
71
|
+
], [
|
|
72
|
+
{ name: "{{user1}}", content: { text: "Buy one chat completion from https://models.example/v1/chat/completions at most 0.02: {\"model\": \"…\", \"messages\": [{\"role\": \"user\", \"content\": \"Summarise x402 in one line.\"}]}" } },
|
|
73
|
+
{ name: "{{agentName}}", content: { text: "Paid 0.02 USDG to models.example with POST; the model answered: \"x402 lets an API charge per call over HTTP 402.\"", actions: ["PRIORS_PAY_X402"] } },
|
|
66
74
|
]],
|
|
67
75
|
};
|
|
68
76
|
|
package/src/parse.js
CHANGED
|
@@ -38,6 +38,37 @@ export function maxPriceOf(text) {
|
|
|
38
38
|
|
|
39
39
|
/** The most to borrow: "borrow up to 1", "borrow at most $0.50", "borrow 1"; 0 when the message names none. */
|
|
40
40
|
export function maxBorrowOf(text) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
return borrowOf(text) ?? 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The borrow the message names: its amount, 0 for "don't borrow", "no borrowing", "without borrowing" or "never
|
|
45
|
+
* borrow", null when it names none (then @priors/mcp's own setting decides: never, or its auto-borrow). */
|
|
46
|
+
export function borrowOf(text) {
|
|
47
|
+
const t = String(text || "");
|
|
48
|
+
if (/\b(?:do not|don't|dont|never|no|without)\s+borrow/i.test(t)) return 0;
|
|
49
|
+
const m = t.match(BORROW);
|
|
50
|
+
return m ? num(m[1]) ?? 0 : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A JSON object the message gives as the request body (a chat completion's {"model", "messages"}): the first ``` fence
|
|
55
|
+
* holding one, else the first balanced {...} that parses. { body: the object as compact JSON, raw: the text it was read
|
|
56
|
+
* from }, or null. The caller reads the URL and the amounts from the rest of the message, so nothing inside the body
|
|
57
|
+
* (a prompt that says "up to 3") is ever taken for the price or a borrow.
|
|
58
|
+
*/
|
|
59
|
+
export function bodyOf(text) {
|
|
60
|
+
const t = String(text || "");
|
|
61
|
+
const obj = (s) => { try { const v = JSON.parse(s); return v && typeof v === "object" && !Array.isArray(v) ? JSON.stringify(v) : null; } catch { return null; } };
|
|
62
|
+
for (const m of t.matchAll(/```(?:json)?\s*([\s\S]*?)```/gi)) { const body = obj(m[1].trim()); if (body) return { body, raw: m[0] }; }
|
|
63
|
+
const start = t.indexOf("{");
|
|
64
|
+
if (start < 0) return null;
|
|
65
|
+
let depth = 0, inStr = false, esc = false;
|
|
66
|
+
for (let i = start; i < t.length; i++) {
|
|
67
|
+
const c = t[i];
|
|
68
|
+
if (inStr) { if (esc) esc = false; else if (c === "\\") esc = true; else if (c === "\"") inStr = false; continue; }
|
|
69
|
+
if (c === "\"") inStr = true;
|
|
70
|
+
else if (c === "{") depth++;
|
|
71
|
+
else if (c === "}" && --depth === 0) { const raw = t.slice(start, i + 1); const body = obj(raw); return body ? { body, raw } : null; }
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
43
74
|
}
|
package/src/priors.js
CHANGED
|
@@ -6,13 +6,13 @@ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
|
6
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
7
|
|
|
8
8
|
export const HOSTED_URL = "https://mcp.priors.trade/mcp";
|
|
9
|
-
export const CLIENT = { name: "elizaos-plugin-priors", version: "0.1
|
|
9
|
+
export const CLIENT = { name: "elizaos-plugin-priors", version: "0.2.1" };
|
|
10
10
|
|
|
11
11
|
/** The settings @priors/mcp reads, taken from the agent's settings (runtime.getSetting), else the process env. */
|
|
12
12
|
export const SETTINGS = Object.freeze([
|
|
13
13
|
"PRIORS_KEY_FILE", "PRIORS_KEY", "PRIORS_AGENT_ID", "PRIORS_PAY_HOSTS", "PRIORS_RPC", "PRIORS_STATE_DIR",
|
|
14
14
|
"PRIORS_MAX_PRICE_USD", "PRIORS_MAX_BORROW_USD", "PRIORS_MAX_SPEND_USD", "PRIORS_MAX_BORROW_TOTAL_USD",
|
|
15
|
-
"PRIORS_MAX_SPEND_DAY_USD", "PRIORS_MAX_BORROW_DAY_USD",
|
|
15
|
+
"PRIORS_MAX_SPEND_DAY_USD", "PRIORS_MAX_BORROW_DAY_USD", "PRIORS_AUTO_BORROW_USD",
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
18
|
/** The env @priors/mcp is built with: the process env, with every Priors setting the agent has replacing it. */
|