@priors/plugin-elizaos 0.3.2 → 0.3.3

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
@@ -70,8 +70,10 @@ read as a price, a borrow or an id, and a bare "pay 5" is a price only when no c
70
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
71
  a count ("up to 50 items"). The JSON body, and anything else the message writes in braces or a ``` block (a
72
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 message must write exactly one JSON object for the body: with two (an example before the body),
74
- one that does not parse, or one joined to the URL with no space, nothing is paid.
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.
75
77
 
76
78
  ## Disclosure
77
79
 
@@ -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.2",
5
+ "version": "0.3.3",
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.2",
3
+ "version": "0.3.3",
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",
package/src/parse.js CHANGED
@@ -9,19 +9,22 @@ const URL_RE = /https?:\/\/\S+/gi;
9
9
  const urlSpans = (t) => [...t.matchAll(URL_RE)].map((m) => [m.index, m.index + m[0].length]);
10
10
  const inSpans = (spans, i) => spans.some(([s, e]) => i >= s && i < e);
11
11
 
12
- /** Where the {...} that opens at `start` closes (the index after its "}"), strings read as JSON spells them; -1 if never.
13
- * `memo` keeps what one scan learns of every { it passes outside a string (a scan from there would read the same), so a
14
- * run of braces that never close is scanned once, not once per brace. */
12
+ /** Where the {...} that opens at `start` closes (the index after its "}"), strings read as JSON spells them, and a
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
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
+ * once, not once per brace. */
15
17
  function closeOf(t, start, memo = new Map()) {
16
18
  if (memo.has(start)) return memo.get(start);
17
19
  const open = [];
18
- let inStr = false, esc = false;
20
+ let quote = null, esc = false, prev = "";
19
21
  for (let i = start; i < t.length; i++) {
20
22
  const c = t[i];
21
- if (inStr) { if (esc) esc = false; else if (c === "\\") esc = true; else if (c === "\"") inStr = false; continue; }
22
- if (c === "\"") inStr = true;
23
+ if (quote) { if (esc) esc = false; else if (c === "\\") esc = true; else if (c === quote) { quote = null; prev = c; } continue; }
24
+ if (c === "\"" || (c === "'" && prev !== "" && "{[,:".includes(prev))) quote = c;
23
25
  else if (c === "{") open.push(i);
24
26
  else if (c === "}" && open.length) { memo.set(open.pop(), i + 1); if (!open.length) return i + 1; }
27
+ if (c.trim()) prev = c;
25
28
  }
26
29
  for (const j of open) memo.set(j, -1);
27
30
  return -1;
@@ -31,11 +34,13 @@ function closeOf(t, start, memo = new Map()) {
31
34
  const objectOf = (s) => { try { const v = JSON.parse(s); return v && typeof v === "object" && !Array.isArray(v) ? JSON.stringify(v) : null; } catch { return null; } };
32
35
 
33
36
  /**
34
- * The message's objects: each ``` block, and each balanced {...} that opens outside a URL and outside a ``` block (one
35
- * that never closes is skipped). Each is { start, end, json, body }: `json` when it is written as JSON (a block holding
36
- * { or [, a {...} opening with a quote or closing at once), `body` the JSON object it holds as compact JSON, or null.
37
- * None of their text is the message's own words: a request body, an example of one, a template's {model}. A brace
38
- * inside a URL is the URL's (GHSA-p87w): it was taken for the body, and taking it out cut the URL in two.
37
+ * The message's objects: each ``` block, and each balanced {...} that opens outside a URL and outside a ``` block. A
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
40
+ * skipped (a lone brace hides nothing). Each is { start, end, json, body }: `json` when it is written as JSON (a block
41
+ * holding { or [, a {...} opening with a double quote or closing at once), `body` the JSON object it holds as compact
42
+ * JSON, or null. None of their text is the message's own words: a request body, an example of one, a template's
43
+ * {model}. A brace inside a URL is the URL's (GHSA-p87w): it was taken for the body, and taking it out cut the URL in two.
39
44
  */
40
45
  function objectsOf(text) {
41
46
  const t = String(text || ""), urls = urlSpans(t), out = [], memo = new Map();
@@ -50,13 +55,11 @@ function objectsOf(text) {
50
55
  i = objEnd + after[0].length;
51
56
  continue;
52
57
  }
53
- const close = t.indexOf("```", i + 3);
54
- if (close >= 0) {
55
- const inner = t.slice(i + 3, close).replace(/^json\b/i, "").trim();
56
- out.push({ start: i, end: close + 3, json: /^[{[]/.test(inner), body: objectOf(inner) });
57
- i = close + 3;
58
- continue;
59
- }
58
+ const close = t.indexOf("```", i + 3), end = close >= 0 ? close + 3 : t.length;
59
+ const inner = t.slice(i + 3, close >= 0 ? close : t.length).replace(/^json\b/i, "").trim();
60
+ out.push({ start: i, end, json: /^[{[]/.test(inner), body: objectOf(inner) });
61
+ i = end;
62
+ continue;
60
63
  }
61
64
  if (t[i] === "{" && !inSpans(urls, i)) {
62
65
  const end = closeOf(t, i, memo);
@@ -66,6 +69,10 @@ function objectsOf(text) {
66
69
  i = end;
67
70
  continue;
68
71
  }
72
+ const opened = /\{\s*(["'])/y;
73
+ opened.lastIndex = i;
74
+ const q = opened.exec(t);
75
+ if (q) { out.push({ start: i, end: t.length, json: q[1] === "\"", body: null }); break; }
69
76
  }
70
77
  i++;
71
78
  }
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.2" };
9
+ export const CLIENT = { name: "elizaos-plugin-priors", version: "0.3.3" };
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([