@priors/plugin-elizaos 0.3.3 → 0.4.0

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 CHANGED
@@ -47,8 +47,8 @@ Without a key, only `PRIORS_AGENT_RECORD` works.
47
47
  |---|---|---|
48
48
  | `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 |
49
49
  | `PRIORS_CREDIT_STATUS` | reads this agent's own line: available, drawn, open loans and due dates | no |
50
- | `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 |
51
- | `PRIORS_REPAY` | repays the loan the message names (`loan 50900`), principal and fee | yes |
50
+ | `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. Only a plain instruction pays (below) | yes |
51
+ | `PRIORS_REPAY` | repays the loan the message names (`loan 50900`), principal and fee. Only a plain instruction repays (below) | yes |
52
52
 
53
53
  Example messages:
54
54
 
@@ -64,16 +64,50 @@ and reads records from the hosted read-only server at `https://mcp.priors.trade/
64
64
  allowlist and the signing are `@priors/mcp`'s own: a payment above `max_price_usd` or to a host outside
65
65
  `PRIORS_PAY_HOSTS` is refused before anything is signed, and the server's totals (`PRIORS_MAX_SPEND_USD` 5 and
66
66
  `PRIORS_MAX_BORROW_TOTAL_USD` 25 by default while it runs) bound what one process can spend or borrow. Amounts and
67
- URLs are read from the message of a sender listed in `PRIORS_OWNER_ENTITY_IDS`, never chosen by the model: the URL is
68
- taken out before the amounts are read, so nothing in a seller's path or query (`/pay1/borrow5.json`, `#123`) is ever
69
- read as a price, a borrow or an id, and a bare "pay 5" is a price only when no cap phrase ("at most", "max", "up to",
70
- "no more than") is named and it is an amount, not a count ("pay 5 items"); a cap phrase's number is an amount too, not
71
- a count ("up to 50 items"). The JSON body, and anything else the message writes in braces or a ``` block (a
72
- template's `{model}`, an example), is taken out the same way wherever it stands, so nothing in a prompt is read as a
73
- price or a borrow; a ``` block that is never closed, or a body cut short (a `{` opened by a quote that never closes),
74
- runs to the end of the message, and a `}` inside a quoted string, single or double, does not close its braces. A
75
- message must write exactly one JSON object for the body: with two (an example before the body), one that does not
76
- parse (a body cut short too), or one joined to the URL with no space, nothing is paid.
67
+ URLs are read from the message of a sender listed in `PRIORS_OWNER_ENTITY_IDS`, never chosen by the model, and only
68
+ from a message that is one plain instruction (below): the URL is taken out before the amounts are read, so nothing in
69
+ a seller's path or query (`/pay1/borrow5.json`, `#123`) is ever read as a price, a borrow or an id, and the JSON body
70
+ is taken out too, so nothing in a prompt is read as a price or a borrow. A message must write exactly one JSON object
71
+ for the body: with two (an example before the body), one that does not parse (a body cut short), or one joined to the
72
+ URL with no space, nothing is paid.
73
+
74
+ ## What the money actions accept
75
+
76
+ `PRIORS_PAY_X402` and `PRIORS_REPAY` act only on a message from an entity in `PRIORS_OWNER_ENTITY_IDS` that is one
77
+ plain instruction, read whole. Any other message is refused before anything is sent: the answer starts "Nothing was
78
+ paid:" (or "Nothing was repaid:") and says what was not clear. Nothing in a message is masked or guessed, so some
79
+ messages 0.3.3 paid are refused; writing the instruction plainly, as in the examples above, is always enough. The
80
+ words are English, as in the examples.
81
+
82
+ A payment message:
83
+
84
+ - is plain text outside its JSON body: no backtick (inline code or a ``` block that is not the body), no `~~~`, no
85
+ line indented by four spaces or a tab, no line starting with `>` (a quote), no `<` opening an HTML tag, comment or
86
+ `<https://…>` link, no Markdown link (`[text](url)`), no invisible character (zero-width, bidi) or control character
87
+ but line breaks and tabs, and no braces outside its URL (a template's `{model}` refuses);
88
+ - names exactly one URL outside the body, and it is https; anything inside the URL, braces included, is the URL's;
89
+ - says to pay in its own words: pay, buy, call or fetch;
90
+ - names the most to pay exactly once: "at most 0.10", "max 0.10", "maximum 0.10", "up to 0.10" or "no more than
91
+ 0.10", the number after `$` or followed by USDG, the end, a line break, punctuation or a joining word
92
+ ("for", "per", "if", "and", ...); or, with none of those, "pay 0.10" ("pay $0.10 for", "pay 0.10 to"). A count is no
93
+ amount and is not read ("up to 20 items"). Two amounts for the price refuse;
94
+ - mentions borrowing at most once: an amount in USDG, its number (after an optional `$`) followed by USDG, the end,
95
+ a line break, punctuation or a joining word ("borrow up to 5", "borrow at most $5", "borrow 5 USDG
96
+ if short", "borrow no more than 5"), or "don't borrow", "do not borrow", "never borrow", "no borrowing" or
97
+ "without borrowing" with no number after it in its clause, which borrows nothing. Anything else refuses: "borrow 10
98
+ items", "borrow 5 ETH", "borrow if needed", an aside ("borrow 0.50 (up to 5)"). With no borrow named,
99
+ `@priors/mcp`'s own setting decides (never, or `PRIORS_AUTO_BORROW_USD`);
100
+ - holds no other negation: "not", "no", "never", "without", "none", "nothing", "nor", "neither", "cannot", a word
101
+ ending in n't, or "dont", "wont" and the like written without it ("don't pay …", "never ever borrow up to 5", "do not
102
+ under any circumstances borrow 5" refuse);
103
+ - names no loan, lending or repayment: one instruction per message;
104
+ - does not say "USD" or "dollars": they are not plain USDG, so "at most 0.10 USD" or "borrow 5 dollars" refuses (`$`
105
+ and a bare amount are USDG);
106
+ - may give one JSON object as the request body, sent with POST: a balanced `{...}` standing apart from the URL, or the
107
+ only content of one ``` block (```json too). Nothing inside it is read.
108
+
109
+ A repayment message is plain text as above, with no braces and no URL; says "repay" or "pay back"; holds no negation;
110
+ names no borrow and no price; and names exactly one loan, as "loan 50900" or "loan #50900", and no other number.
77
111
 
78
112
  ## Disclosure
79
113
 
@@ -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.3.3",
5
+ "version": "0.4.0",
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.3.3",
3
+ "version": "0.4.0",
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.19.1"
23
+ "@priors/mcp": "0.21.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@elizaos/core": "^1.7.0"
package/src/index.js CHANGED
@@ -5,9 +5,11 @@
5
5
  // within that setting (a message saying not to borrow never does). A JSON body in the message is sent with POST (a
6
6
  // chat completion bought over x402). The caps, the host allowlist and the signing are @priors/mcp's own. The two money
7
7
  // actions answer only the operator's elizaOS entities (PRIORS_OWNER_ENTITY_IDS): in a room, a message is from whoever
8
- // spoke in it, not from the agent's operator (GHSA-p29w).
8
+ // spoke in it, not from the agent's operator (GHSA-p29w). And they act only on a plain instruction, read whole
9
+ // (payInstructionOf, repayInstructionOf): any other message is refused with what was not clear, nothing masked or
10
+ // guessed.
9
11
  import { priorsOf } from "./priors.js";
10
- import { urlOf, agentIdOf, loanIdOf, maxPriceOf, borrowOf, bodyOf } from "./parse.js";
12
+ import { urlOf, agentIdOf, payInstructionOf, repayInstructionOf } from "./parse.js";
11
13
 
12
14
  const textOf = (message) => String((message && message.content && message.content.text) || "");
13
15
 
@@ -33,6 +35,10 @@ function notOperator(runtime) {
33
35
  : "Nothing was paid or repaid: this agent moves money only for its operator, and none is set. Set PRIORS_OWNER_ENTITY_IDS to the operator's elizaOS entity ids (comma-separated), or to * to let anyone in its rooms make it pay.";
34
36
  }
35
37
 
38
+ // what a refusal asks for instead
39
+ const PAY_PLAINLY = "Write one plain instruction, for example \"Pay https://seller.example/report at most 0.10, borrow up to 5\" (or \"don't borrow\"), with nothing quoted, in code or in markup; a JSON request body may follow it.";
40
+ const REPAY_PLAINLY = "Write one plain instruction, for example \"Repay loan 50900\", with nothing quoted, in code or in markup.";
41
+
36
42
  /** Answer through the callback and as the action's result. */
37
43
  async function answer(callback, action, ok, text, data = {}) {
38
44
  if (typeof callback === "function") await callback({ text, actions: [action] });
@@ -74,23 +80,20 @@ export const payX402Action = {
74
80
  name: "PRIORS_PAY_X402",
75
81
  similes: ["PAY_X402", "PAY_HTTP_402", "BUY_API_CALL"],
76
82
  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, and come from the agent's operator (PRIORS_OWNER_ENTITY_IDS). Real money.",
77
- validate: async (runtime, message) => fromOperator(runtime, message) && !!urlOf(textOf(message)) && /\bpay|buy|call|fetch/i.test(textOf(message)),
83
+ // offered for any operator message with an https URL and a pay word, so that one it cannot read whole is answered
84
+ // with what was not clear
85
+ validate: async (runtime, message) => fromOperator(runtime, message) && /https:\/\/\S/i.test(textOf(message)) && /\bpay|buy|call|fetch/i.test(textOf(message)),
78
86
  handler: async (runtime, message, _state, _options, callback) => {
79
87
  if (!fromOperator(runtime, message)) return answer(callback, "PRIORS_PAY_X402", false, notOperator(runtime), {});
80
- const text = textOf(message);
81
- // the URL and the amounts are read with the body and every other object of the message taken out, wherever they
82
- // stand (parse.js); a message whose body cannot be told apart pays nothing (GHSA-p87w, GHSA-8pvh)
83
- const b = bodyOf(text);
84
- if (b && b.error) return answer(callback, "PRIORS_PAY_X402", false, `Nothing was paid: ${b.error}.`, {});
85
- const url = urlOf(text), maxPrice = maxPriceOf(text), borrow = borrowOf(text);
86
- if (!url) return answer(callback, "PRIORS_PAY_X402", false, "Nothing was paid. Name the https URL to pay outside the request body.", {});
87
- if (maxPrice === null || maxPrice <= 0) {
88
- 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 });
89
- }
88
+ // one plain instruction, read whole, or nothing is paid (parse.js payInstructionOf; the README's "What the money
89
+ // actions accept")
90
+ const p = payInstructionOf(textOf(message));
91
+ if (p.unclear) return answer(callback, "PRIORS_PAY_X402", false, `Nothing was paid: ${p.unclear}. ${PAY_PLAINLY}`, p.url ? { url: p.url } : {});
92
+ const { url, maxPrice, borrow, body } = p;
90
93
  // a borrow the message names, 0 included, is passed as said; none named leaves it to @priors/mcp's own setting
91
- const args = { url, max_price_usd: maxPrice, ...(borrow !== null ? { max_borrow_usd: borrow } : {}), ...(b ? { method: "POST", body: b.body } : {}) };
94
+ const args = { url, max_price_usd: maxPrice, ...(borrow !== null ? { max_borrow_usd: borrow } : {}), ...(body ? { method: "POST", body } : {}) };
92
95
  const r = await priorsOf(runtime).wallet("pay_url", args);
93
- return answer(callback, "PRIORS_PAY_X402", r.ok, r.text, { url, maxPrice, maxBorrow: borrow ?? 0, ...(b ? { method: "POST" } : {}) });
96
+ return answer(callback, "PRIORS_PAY_X402", r.ok, r.text, { url, maxPrice, maxBorrow: borrow ?? 0, ...(body ? { method: "POST" } : {}) });
94
97
  },
95
98
  examples: [[
96
99
  { 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." } },
@@ -105,10 +108,12 @@ export const repayAction = {
105
108
  name: "PRIORS_REPAY",
106
109
  similes: ["REPAY_LOAN", "PAY_BACK_LOAN"],
107
110
  description: "Repay one of this agent's Priors loans in full (principal and fee) from its wallet. Needs the loan id in the message, as loan 50900, from the agent's operator (PRIORS_OWNER_ENTITY_IDS). Real money.",
108
- validate: async (runtime, message) => fromOperator(runtime, message) && loanIdOf(textOf(message)) !== null && /repay|pay (it )?back/i.test(textOf(message)),
111
+ validate: async (runtime, message) => fromOperator(runtime, message) && /\bloan\s*#?\s*\d/i.test(textOf(message)) && /repay|pay (it )?back/i.test(textOf(message)),
109
112
  handler: async (runtime, message, _state, _options, callback) => {
110
113
  if (!fromOperator(runtime, message)) return answer(callback, "PRIORS_REPAY", false, notOperator(runtime), {});
111
- const loan = loanIdOf(textOf(message));
114
+ const p = repayInstructionOf(textOf(message));
115
+ if (p.unclear) return answer(callback, "PRIORS_REPAY", false, `Nothing was repaid: ${p.unclear}. ${REPAY_PLAINLY}`, {});
116
+ const loan = p.loanId;
112
117
  const r = await priorsOf(runtime).wallet("repay", { loan_id: loan });
113
118
  return answer(callback, "PRIORS_REPAY", r.ok, r.text, { loanId: loan });
114
119
  },
package/src/parse.js CHANGED
@@ -11,7 +11,7 @@ const inSpans = (spans, i) => spans.some(([s, e]) => i >= s && i < e);
11
11
 
12
12
  /** Where the {...} that opens at `start` closes (the index after its "}"), strings read as JSON spells them, and a
13
13
  * single-quoted one too where a string can open (after {, [, "," or ":"), so a } inside 'a } b' does not close the braces
14
- * while an apostrophe in words ({it's}) is no string; -1 if never. `memo` keeps what one scan learns of every
14
+ * (GHSA-f65r) while an apostrophe in words ({it's}) is no string; -1 if never. `memo` keeps what one scan learns of every
15
15
  * { it passes outside a string (a scan from there would read the same), so a run of braces that never close is scanned
16
16
  * once, not once per brace. */
17
17
  function closeOf(t, start, memo = new Map()) {
@@ -36,7 +36,7 @@ const objectOf = (s) => { try { const v = JSON.parse(s); return v && typeof v ==
36
36
  /**
37
37
  * The message's objects: each ``` block, and each balanced {...} that opens outside a URL and outside a ``` block. A
38
38
  * ``` block that never closes runs to the end of the message, as Markdown reads it, and so does a { that never closes
39
- * when a quote opens it (a JSON body cut short: its words are the body's); any other { that never closes is
39
+ * when a quote opens it (a JSON body cut short: its words are the body's, GHSA-f65r); any other { that never closes is
40
40
  * skipped (a lone brace hides nothing). Each is { start, end, json, body }: `json` when it is written as JSON (a block
41
41
  * holding { or [, a {...} opening with a double quote or closing at once), `body` the JSON object it holds as compact
42
42
  * JSON, or null. None of their text is the message's own words: a request body, an example of one, a template's
@@ -155,7 +155,7 @@ export function maxBorrowOf(text) {
155
155
  * borrow", null when it names none (then @priors/mcp's own setting decides: never, or its auto-borrow). */
156
156
  export function borrowOf(text) {
157
157
  const t = proseOf(text);
158
- if (/\b(?:do not|don't|dont|never|no|without)\s+borrow/i.test(t)) return 0;
158
+ if (/\b(?:do\s+not|don['’]t|dont|never|no|without)\s+borrow/i.test(t)) return 0;
159
159
  const m = t.match(BORROW);
160
160
  return m ? num(m[1]) ?? 0 : null;
161
161
  }
@@ -184,3 +184,105 @@ export function bodyOf(text) {
184
184
  if (written.length > 1) return { error: `the message holds ${written.length} JSON objects (in \`\`\` blocks or braces): give the request body as the only one` };
185
185
  return { body: written[0].body, raw: t.slice(written[0].start, written[0].end) };
186
186
  }
187
+
188
+ // ---- The plain-instruction rule -------------------------------------------------------------------------------------------
189
+ // The readers above take out the shapes they know (URLs, braces, ``` blocks) and read the rest; each spelling they did
190
+ // not know was read as the operator's words (RT-7, RT-14). The money actions now act only on a message that is one plain
191
+ // instruction, read whole, and refuse any other, saying what was not clear: nothing in such a message is masked or
192
+ // guessed. The readers give the values once the rule has found exactly one thing for each to read. The README's
193
+ // "What the money actions accept" states the same rule.
194
+
195
+ // markup a plain message never holds (outside its request body): what a reader of the message may not see as the
196
+ // operator's own words
197
+ const MARKUP = [
198
+ [/(?![\n\r\t])[\p{Cc}\p{Cf}]/u, "an invisible or control character"],
199
+ [/`/, "code (a backtick)"],
200
+ [/~~~/, "a ~~~ block"],
201
+ [/^(?: {4}| {0,3}\t)[ \t]*\S/m, "an indented line (code)"],
202
+ [/^[ \t]*>/m, "a quoted line (a line starting with >)"],
203
+ [/<[a-z!/?]/i, "HTML (a tag or a <!-- comment -->)"],
204
+ [/\]\s*[([]|^[ \t]*\[[^\]\r\n]*\]:/m, "a Markdown link"],
205
+ ];
206
+ const markupOf = (t) => (MARKUP.find(([re]) => re.test(t)) || [])[1] || null;
207
+ // a negation: any but the plain no-borrow phrase and the cap phrase "no more than" refuses ("never ever
208
+ // borrow up to 5" was a borrow of 5)
209
+ const NEGATION = /\b(?:not|no|never|none|nothing|nor|neither|without|cannot|dont|doesnt|didnt|wont|cant|isnt|arent|shouldnt|wouldnt|couldnt|mustnt)\b|\b[a-z]+n['’]t\b/i;
210
+ const NO_BORROW = /\b(?:(?:do\s+not|don['’]t|dont|never)\s+borrow|no\s+borrow(?:ing)?|without\s+borrowing)\b/i;
211
+ // a borrow amount: the borrow phrase's number in USDG (after an optional "$", followed by USDG, the end, a line break,
212
+ // punctuation or a joining word; USD and dollars are refused before it is read), never a count ("borrow up to 10 items")
213
+ // or another unit. The value is then borrowOf's, whose no-borrow spellings are NO_BORROW's.
214
+ const BORROW_AMOUNT = new RegExp(`\\bborrow(?:ing)?\\s+(?:(?:up to|at most|no more than|max(?:imum)?)\\s*)?(?:\\$\\s*)?\\d+(?:[.,]\\d+)?(?!\\d|[.,]\\d)${CAP_AFTER}`, "iy");
215
+ const PAY_VERB = /\b(?:pay|buy|call|fetch)\b/i;
216
+ const sticky = (re, t, at) => { re.lastIndex = at; return re.exec(t); };
217
+ // the words of a clause from `at`, at most five, to quote back what was not clear
218
+ const CLAUSE = /^(?:[^.,;:!?\r\n]|[.,](?=\d))*/;
219
+ const firstWords = (t, at) => t.slice(at).match(CLAUSE)[0].match(/^\S+(?:[ \t]+\S+){0,4}/)[0];
220
+
221
+ /**
222
+ * What PRIORS_PAY_X402 pays, if the message is one plain instruction: { url, maxPrice, borrow (null when none is
223
+ * named), body (null when none) }; otherwise { unclear: what was not clear, url? }. The message, its one JSON request
224
+ * body taken out (bodyOf), holds no markup (MARKUP), no braces outside its URL, exactly one URL (https), a pay verb, no
225
+ * loan or repayment, no "USD" or "dollars", no negation but "don't borrow" (and its plain spellings) or "no more than",
226
+ * at most one mention of borrowing (an amount in USDG, or "don't borrow"), and the most to pay exactly once.
227
+ */
228
+ export function payInstructionOf(text) {
229
+ const t = String(text || "");
230
+ const b = bodyOf(t);
231
+ if (b && b.error) return { unclear: b.error };
232
+ const outside = without(t, b ? objectsOf(t).filter((o) => o.json).map((o) => [o.start, o.end]) : []);
233
+ const markup = markupOf(outside);
234
+ if (markup) return { unclear: `it holds ${markup}` };
235
+ const urls = urlSpans(outside), words = without(outside, urls);
236
+ if (/[{}]/.test(words)) return { unclear: "it holds braces that are not the request body" };
237
+ if (urls.length !== 1) return { unclear: urls.length ? `it names ${urls.length} URLs: name only the one to pay` : "it names no https URL outside the request body" };
238
+ const url = urlOf(t);
239
+ if (!url) return { unclear: "the URL to pay must be https" };
240
+ if (!PAY_VERB.test(words)) return { unclear: "it does not say to pay (pay, buy, call or fetch)", url };
241
+ if (/\b(?:repay\w*|loans?|lend\w*)\b|\bpay\s+(?:it\s+)?back\b/i.test(words)) return { unclear: "it names a loan or a repayment too: one instruction per message", url };
242
+ // USD and dollars are not plain USDG: an instruction naming them is refused, never read as USDG ("$" and a bare
243
+ // amount are USDG, as "USDG" itself)
244
+ const usd = words.match(/\b(?:usd|dollars?)\b/i);
245
+ if (usd) return { unclear: `it names "${usd[0]}": amounts are in USDG; write "at most 0.10" or "borrow up to 5 USDG"`, url };
246
+ const mentions = [...words.matchAll(/\bborrow\w*/gi)];
247
+ if (mentions.length > 1) return { unclear: "it mentions borrowing more than once", url };
248
+ let rest = words;
249
+ if (mentions.length) {
250
+ const at = mentions[0].index;
251
+ // the no-borrow phrase (the one mention is its "borrow"), with no number after it in its clause: "never borrow 5"
252
+ // is not clear
253
+ const no = words.match(NO_BORROW);
254
+ const plainNo = no && !/\d/.test(words.slice(no.index + no[0].length).match(CLAUSE)[0]) ? no : null;
255
+ const amount = plainNo ? null : sticky(BORROW_AMOUNT, words, at);
256
+ if (!plainNo && !amount) return { unclear: `"${firstWords(words, at)}" is not a borrow in USDG: write "borrow up to 5", or "don't borrow"`, url };
257
+ const m = plainNo || amount;
258
+ rest = without(words, [[m.index, m.index + m[0].length]]);
259
+ }
260
+ const neg = rest.replace(/\bno more than\b/gi, "at most").match(NEGATION);
261
+ if (neg) return { unclear: `it holds a negation ("${neg[0]}") other than "don't borrow": say plainly what to pay and whether to borrow`, url };
262
+ const prices = [...rest.matchAll(new RegExp(CAP.source, "gi")), ...rest.matchAll(new RegExp(PAY.source, "gi"))];
263
+ if (prices.length > 1) return { unclear: `it names the most to pay ${prices.length} times: name it once`, url };
264
+ const maxPrice = maxPriceOf(t);
265
+ if (!prices.length || maxPrice === null || maxPrice <= 0) return { unclear: `it names no most to pay for ${url}: say it, for example "at most 0.10"`, url };
266
+ return { url, maxPrice, borrow: mentions.length ? borrowOf(t) : null, body: b ? b.body : null };
267
+ }
268
+
269
+ /**
270
+ * What PRIORS_REPAY repays, if the message is one plain instruction: { loanId }, otherwise { unclear }. The message
271
+ * holds no markup (MARKUP), no braces and no URL, says to repay ("repay", "pay back"), holds no negation, names no borrow
272
+ * or price, and names exactly one loan ("loan 50900", "loan #50900") and no other number.
273
+ */
274
+ export function repayInstructionOf(text) {
275
+ const t = String(text || "");
276
+ const markup = markupOf(t);
277
+ if (markup) return { unclear: `it holds ${markup}` };
278
+ if (/[{}]/.test(t)) return { unclear: "it holds braces" };
279
+ if (urlSpans(t).length) return { unclear: "it names a URL: a repayment names only its loan" };
280
+ if (!/\brepay\b|\bpay\s+(?:it\s+)?back\b/i.test(t)) return { unclear: "it does not say to repay" };
281
+ const neg = t.match(NEGATION);
282
+ if (neg) return { unclear: `it holds a negation ("${neg[0]}"): say plainly which loan to repay` };
283
+ if (/\bborrow\w*/i.test(t) || CAP.test(t)) return { unclear: "it names a borrow or a price too: one instruction per message" };
284
+ const loans = [...t.matchAll(/\bloan\s*#?\s*\d{1,12}\b/gi)];
285
+ if (loans.length !== 1) return { unclear: loans.length ? `it names ${loans.length} loans: name only the one to repay` : "it names no loan, as \"loan 50900\"" };
286
+ if (/\d/.test(without(t, [[loans[0].index, loans[0].index + loans[0][0].length]]))) return { unclear: "it holds a number other than the loan's" };
287
+ return { loanId: loanIdOf(t) };
288
+ }
package/src/priors.js CHANGED
@@ -6,7 +6,7 @@ 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.3.3" };
9
+ export const CLIENT = { name: "elizaos-plugin-priors", version: "0.4.0" };
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([