@moneytools-dev/elizaos-plugin-moneytools 0.0.0-stage → 0.1.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/LICENSE +9 -0
- package/README.md +30 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +123 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MoneyTools
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @moneytools-dev/elizaos-plugin-moneytools (ElizaOS)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Gives an ElizaOS agent pay-per-use speech-to-text and x402 spend checks from MoneyTools, paid with x402 USDC on Base. No API key or account.
|
|
4
|
+
|
|
5
|
+
| Action | Cost | Trigger |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `TRANSCRIBE_AUDIO` | 0.002 USDC / started minute | a message with an audio/video URL ("transcribe https://…/ep12.mp3") |
|
|
8
|
+
| `GET_TRANSCRIPTION` | free | a message with a `job_…` id (add "srt"/"vtt" for subtitles) |
|
|
9
|
+
| `SETTLE_SPEND_CHECK` | 0.002 USDC | "can I pay $0.25 to api.example.com?" |
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
elizaos plugins add @moneytools-dev/elizaos-plugin-moneytools # or: bun add @moneytools-dev/elizaos-plugin-moneytools
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Character / `.env`:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
MONEYTOOLS_EVM_PRIVATE_KEY=0x… # Base wallet with a little USDC (falls back to EVM_PRIVATE_KEY)
|
|
21
|
+
MONEYTOOLS_MAX_USD_PER_REQUEST=0.5 # optional hard cap per signed payment (default 1.00)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import moneytoolsPlugin from "@moneytools-dev/elizaos-plugin-moneytools";
|
|
26
|
+
export const character = { name: "Scribe", plugins: [moneytoolsPlugin] /* … */ };
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The key is used only to sign x402 payments locally and is never sent anywhere. Payments above the cap are refused before signing.
|
|
30
|
+
|
|
31
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Action, Plugin } from "@elizaos/core";
|
|
2
|
+
export declare const transcribeAudioAction: Action;
|
|
3
|
+
export declare const getTranscriptionAction: Action;
|
|
4
|
+
export declare const spendCheckAction: Action;
|
|
5
|
+
export declare const moneytoolsPlugin: Plugin;
|
|
6
|
+
export default moneytoolsPlugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
2
|
+
import { TranscriptsGateway, SettleClient } from "@moneytools-dev/transcripts";
|
|
3
|
+
const URL_RE = /https?:\/\/[^\s<>"')]+/i;
|
|
4
|
+
const JOB_RE = /\bjob_[A-Za-z0-9]+\b/;
|
|
5
|
+
function setup(runtime) {
|
|
6
|
+
const key = (runtime.getSetting("MONEYTOOLS_EVM_PRIVATE_KEY") || runtime.getSetting("EVM_PRIVATE_KEY"));
|
|
7
|
+
if (!key)
|
|
8
|
+
return null;
|
|
9
|
+
const account = privateKeyToAccount((key.startsWith("0x") ? key : `0x${key}`));
|
|
10
|
+
const max = Number(runtime.getSetting("MONEYTOOLS_MAX_USD_PER_REQUEST") || 1);
|
|
11
|
+
return {
|
|
12
|
+
account,
|
|
13
|
+
gw: new TranscriptsGateway({ account, maxUsdPerRequest: max }),
|
|
14
|
+
settle: new SettleClient({ account, maxUsdPerRequest: Math.min(max, 0.05) }),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const hasKey = async (runtime) => !!(runtime.getSetting("MONEYTOOLS_EVM_PRIVATE_KEY") || runtime.getSetting("EVM_PRIVATE_KEY"));
|
|
18
|
+
const text = (m) => String(m.content?.text ?? "");
|
|
19
|
+
async function reply(callback, t, data, ok = true) {
|
|
20
|
+
if (callback)
|
|
21
|
+
await callback({ text: t, actions: [] });
|
|
22
|
+
return { success: ok, text: t, data, error: ok ? undefined : t };
|
|
23
|
+
}
|
|
24
|
+
export const transcribeAudioAction = {
|
|
25
|
+
name: "TRANSCRIBE_AUDIO",
|
|
26
|
+
similes: ["TRANSCRIBE", "SPEECH_TO_TEXT", "TRANSCRIBE_URL", "GET_TRANSCRIPT"],
|
|
27
|
+
description: "Transcribe a public audio/video URL with MoneyTools Transcripts (0.002 USDC per started minute, paid automatically via x402 on Base). Returns the text, or a job id if it takes longer.",
|
|
28
|
+
validate: async (runtime, message) => (await hasKey(runtime)) && URL_RE.test(text(message)),
|
|
29
|
+
handler: async (runtime, message, _state, options, callback) => {
|
|
30
|
+
const s = setup(runtime);
|
|
31
|
+
if (!s)
|
|
32
|
+
return reply(callback, "MoneyTools needs MONEYTOOLS_EVM_PRIVATE_KEY (or EVM_PRIVATE_KEY) to pay.", undefined, false);
|
|
33
|
+
const url = options?.url ?? text(message).match(URL_RE)?.[0];
|
|
34
|
+
if (!url)
|
|
35
|
+
return reply(callback, "Send me an audio or video URL to transcribe.", undefined, false);
|
|
36
|
+
try {
|
|
37
|
+
const job = await s.gw.transcribeUrl(url, { language: options?.language });
|
|
38
|
+
let cur = job;
|
|
39
|
+
const end = Date.now() + Number(options?.maxWaitSeconds ?? 120) * 1000;
|
|
40
|
+
while (!["completed", "failed"].includes(cur.status)) {
|
|
41
|
+
cur = await s.gw.getFileTranscription(job.id);
|
|
42
|
+
if (["completed", "failed"].includes(cur.status) || Date.now() >= end)
|
|
43
|
+
break;
|
|
44
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
45
|
+
}
|
|
46
|
+
const paid = job.payment?.amountUsd;
|
|
47
|
+
if (cur.status === "completed")
|
|
48
|
+
return reply(callback, `Transcript (${Math.round(cur.durationSeconds ?? 0)} s, paid ${paid} USDC):\n${cur.result?.text ?? ""}`, { jobId: job.id, paidUsd: paid, result: cur.result });
|
|
49
|
+
if (cur.status === "failed")
|
|
50
|
+
return reply(callback, `Transcription failed: ${cur.error ?? "unknown error"}`, { jobId: job.id }, false);
|
|
51
|
+
return reply(callback, `Transcription is running (job ${job.id}, paid ${paid} USDC). Ask me for ${job.id} later.`, { jobId: job.id, paidUsd: paid, status: cur.status });
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return reply(callback, `Could not transcribe: ${e?.message ?? e}`, undefined, false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
examples: [[
|
|
58
|
+
{ name: "{{user}}", content: { text: "Transcribe https://example.com/podcast-ep12.mp3" } },
|
|
59
|
+
{ name: "{{agent}}", content: { text: "Transcript (1830 s, paid 0.062 USDC): …", actions: ["TRANSCRIBE_AUDIO"] } },
|
|
60
|
+
]],
|
|
61
|
+
};
|
|
62
|
+
export const getTranscriptionAction = {
|
|
63
|
+
name: "GET_TRANSCRIPTION",
|
|
64
|
+
similes: ["CHECK_TRANSCRIPTION", "TRANSCRIPTION_STATUS"],
|
|
65
|
+
description: "Get the status or result of a MoneyTools transcription job by its job_… id (free). Can return SRT/VTT subtitles.",
|
|
66
|
+
validate: async (runtime, message) => (await hasKey(runtime)) && JOB_RE.test(text(message)),
|
|
67
|
+
handler: async (runtime, message, _state, options, callback) => {
|
|
68
|
+
const s = setup(runtime);
|
|
69
|
+
if (!s)
|
|
70
|
+
return reply(callback, "MoneyTools needs MONEYTOOLS_EVM_PRIVATE_KEY.", undefined, false);
|
|
71
|
+
const id = options?.jobId ?? text(message).match(JOB_RE)?.[0];
|
|
72
|
+
const fmt = options?.format ?? (/\bsrt\b/i.test(text(message)) ? "srt" : /\bvtt\b/i.test(text(message)) ? "vtt" : "json");
|
|
73
|
+
try {
|
|
74
|
+
if (fmt !== "json") {
|
|
75
|
+
const c = await s.gw.getFileTranscriptionText(id, fmt);
|
|
76
|
+
return reply(callback, c, { jobId: id, format: fmt });
|
|
77
|
+
}
|
|
78
|
+
const j = await s.gw.getFileTranscription(id);
|
|
79
|
+
return reply(callback, j.status === "completed" ? j.result?.text ?? "" : `Job ${id} is ${j.status}.`, { jobId: id, status: j.status, result: j.result });
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return reply(callback, `Could not read ${id}: ${e?.message ?? e}`, undefined, false);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
examples: [[
|
|
86
|
+
{ name: "{{user}}", content: { text: "Is job_3f9c2a done? send srt" } },
|
|
87
|
+
{ name: "{{agent}}", content: { text: "1\n00:00:00,000 --> 00:00:04,200\nHello everyone…", actions: ["GET_TRANSCRIPTION"] } },
|
|
88
|
+
]],
|
|
89
|
+
};
|
|
90
|
+
export const spendCheckAction = {
|
|
91
|
+
name: "SETTLE_SPEND_CHECK",
|
|
92
|
+
similes: ["CHECK_SPEND", "CAN_I_PAY", "SPEND_CAP_CHECK"],
|
|
93
|
+
description: "Before paying an x402 402, check the amount and host against this wallet's MoneyTools Settle spend caps (0.002 USDC per check). Pass options {amountUsd, host, payTo?}.",
|
|
94
|
+
validate: async (runtime) => hasKey(runtime),
|
|
95
|
+
handler: async (runtime, message, _state, options, callback) => {
|
|
96
|
+
const s = setup(runtime);
|
|
97
|
+
if (!s)
|
|
98
|
+
return reply(callback, "MoneyTools needs MONEYTOOLS_EVM_PRIVATE_KEY.", undefined, false);
|
|
99
|
+
const t = text(message);
|
|
100
|
+
const amountUsd = options?.amountUsd ?? t.match(/\$?\s?(\d+(?:\.\d+)?)\s*(?:usd|usdc|\$)?/i)?.[1];
|
|
101
|
+
const host = options?.host ?? (t.match(URL_RE)?.[0] ? new URL(t.match(URL_RE)[0]).host : t.match(/\b([a-z0-9-]+\.)+[a-z]{2,}\b/i)?.[0]);
|
|
102
|
+
if (!amountUsd || !host)
|
|
103
|
+
return reply(callback, "Tell me the amount and the host, e.g. 'check $0.25 to api.example.com'.", undefined, false);
|
|
104
|
+
try {
|
|
105
|
+
const d = await s.settle.spendCheck({ payer: s.account.address, amountUsd: String(amountUsd), host, payTo: options?.payTo });
|
|
106
|
+
return reply(callback, `Spend check: ${d.decision}${d.reasons?.length ? ` (${d.reasons.join(", ")})` : ""}`, d);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
return reply(callback, `Spend check failed: ${e?.message ?? e}`, undefined, false);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
examples: [[
|
|
113
|
+
{ name: "{{user}}", content: { text: "Can I pay $0.25 to api.example.com?" } },
|
|
114
|
+
{ name: "{{agent}}", content: { text: "Spend check: allow", actions: ["SETTLE_SPEND_CHECK"] } },
|
|
115
|
+
]],
|
|
116
|
+
};
|
|
117
|
+
export const moneytoolsPlugin = {
|
|
118
|
+
name: "moneytools",
|
|
119
|
+
description: "Pay-per-use speech-to-text (Transcripts) and x402 spend controls (Settle) from MoneyTools, paid with x402 USDC on Base.",
|
|
120
|
+
config: { MONEYTOOLS_EVM_PRIVATE_KEY: undefined, MONEYTOOLS_MAX_USD_PER_REQUEST: "1" },
|
|
121
|
+
actions: [transcribeAudioAction, getTranscriptionAction, spendCheckAction],
|
|
122
|
+
};
|
|
123
|
+
export default moneytoolsPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneytools-dev/elizaos-plugin-moneytools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ElizaOS plugin: pay-per-file speech-to-text (MoneyTools Transcripts, 0.002 USDC/min) and x402 spend controls (Settle), paid with x402 USDC on Base. No API keys.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"elizaos",
|
|
22
|
+
"eliza",
|
|
23
|
+
"plugin",
|
|
24
|
+
"x402",
|
|
25
|
+
"speech-to-text",
|
|
26
|
+
"transcription",
|
|
27
|
+
"base",
|
|
28
|
+
"usdc"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/joe1993119/plugin-moneytools"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p .",
|
|
36
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
37
|
+
"prepublishOnly": "npm test"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@elizaos/core": "^1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@moneytools-dev/transcripts": "^0.1.0",
|
|
44
|
+
"viem": "^2.30.0"
|
|
45
|
+
},
|
|
46
|
+
"agentConfig": {
|
|
47
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
48
|
+
"pluginParameters": {
|
|
49
|
+
"MONEYTOOLS_EVM_PRIVATE_KEY": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "EVM private key of a Base wallet holding a little USDC (falls back to EVM_PRIVATE_KEY). Used only to sign x402 payments locally.",
|
|
52
|
+
"required": false,
|
|
53
|
+
"sensitive": true
|
|
54
|
+
},
|
|
55
|
+
"MONEYTOOLS_MAX_USD_PER_REQUEST": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "Max USD per signed payment (default 1.00).",
|
|
58
|
+
"required": false,
|
|
59
|
+
"sensitive": false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": "^22.20.5",
|
|
65
|
+
"typescript": "^5.9.3"
|
|
66
|
+
}
|
|
67
|
+
}
|