@moneytools-dev/ai-sdk 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/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ import { tool } from "ai";
2
+ import { z } from "zod";
3
+ import { TranscriptsGateway, SettleClient } from "@moneytools-dev/transcripts";
4
+ /**
5
+ * MoneyTools tools for the Vercel AI SDK (`generateText({ tools: moneytoolsTools({ account }) })`).
6
+ * Transcripts: 0.002 USDC per started audio minute. Settle: 0.002–0.003 USDC per call. Paid via x402 on Base.
7
+ */
8
+ export function moneytoolsTools(o) {
9
+ const gw = new TranscriptsGateway({ account: o.account, maxUsdPerRequest: o.maxUsdPerRequest, gatewayUrl: o.transcriptsUrl, fetch: o.fetch });
10
+ const settle = new SettleClient({ account: o.account, maxUsdPerRequest: Math.min(o.maxUsdPerRequest ?? 0.05, 0.05), baseUrl: o.settleUrl, fetch: o.fetch });
11
+ const payer = o.account.address;
12
+ const wrap = async (f) => { try {
13
+ return await f();
14
+ }
15
+ catch (e) {
16
+ return { error: e?.message ?? String(e), status: e?.status };
17
+ } };
18
+ return {
19
+ transcribeAudio: tool({
20
+ description: "Transcribe speech in a public audio/video URL (mp3, wav, m4a, ogg, webm, flac, mp4; up to 3 h). Costs 0.002 USDC per started minute, paid automatically via x402. Returns text, language and timestamped segments, or a jobId to check later with getTranscription.",
21
+ inputSchema: z.object({
22
+ url: z.string().url().describe("https URL of the audio or video file"),
23
+ language: z.string().optional().describe("ISO-639-1 code, e.g. 'en'; omit to auto-detect"),
24
+ summary: z.boolean().optional().describe("Also return a short summary"),
25
+ }),
26
+ execute: async ({ url, language, summary }) => wrap(async () => {
27
+ const job = await gw.transcribeUrl(url, { language, summary });
28
+ let cur = job;
29
+ const end = Date.now() + (o.maxWaitSeconds ?? 120) * 1000;
30
+ while (!["completed", "failed"].includes(cur.status)) {
31
+ cur = await gw.getFileTranscription(job.id);
32
+ if (["completed", "failed"].includes(cur.status) || Date.now() >= end)
33
+ break;
34
+ await new Promise((r) => setTimeout(r, 3000));
35
+ }
36
+ return { jobId: job.id, status: cur.status, durationSeconds: cur.durationSeconds ?? job.durationSeconds, paidUsd: job.payment?.amountUsd, text: cur.result?.text, language: cur.result?.language, segments: cur.result?.segments?.slice(0, 200), error: cur.error ?? undefined };
37
+ }),
38
+ }),
39
+ getTranscription: tool({
40
+ description: "Get the status/result of a MoneyTools transcription job (free). format: json (default), srt, vtt or txt.",
41
+ inputSchema: z.object({ jobId: z.string(), format: z.enum(["json", "srt", "vtt", "txt"]).optional() }),
42
+ execute: async ({ jobId, format }) => wrap(async () => (format && format !== "json" ? { jobId, format, content: await gw.getFileTranscriptionText(jobId, format) } : gw.getFileTranscription(jobId))),
43
+ }),
44
+ spendCheck: tool({
45
+ description: "Before paying an x402 402, check the payment against this wallet's spend caps (per call / per day / allowed hosts). Costs 0.002 USDC. Returns decision allow|deny with reasons.",
46
+ inputSchema: z.object({ amountUsd: z.string().describe("e.g. '0.25'"), host: z.string().describe("host asking for payment"), payTo: z.string().optional() }),
47
+ execute: async (a) => wrap(() => settle.spendCheck({ payer, ...a })),
48
+ }),
49
+ setSpendCap: tool({
50
+ description: "Set spend caps for this wallet (per call, per UTC day, allowed hosts). Costs 0.002 USDC.",
51
+ inputSchema: z.object({ perCallUsd: z.string().optional(), perDayUsd: z.string().optional(), allowHosts: z.array(z.string()).optional() }),
52
+ execute: async (a) => wrap(() => settle.spendCapSet({ payer, ...a })),
53
+ }),
54
+ verifyPayment: tool({
55
+ description: "Verify an x402 USDC payment on Base by tx hash or authorization nonce (who paid whom, how much, settled or not). Costs 0.003 USDC.",
56
+ inputSchema: z.object({ tx: z.string().optional(), nonce: z.string().optional() }),
57
+ execute: async (a) => (a.tx || a.nonce ? wrap(() => settle.verify(a)) : { error: "provide tx or nonce" }),
58
+ }),
59
+ };
60
+ }
61
+ export default moneytoolsTools;
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@moneytools-dev/ai-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Vercel AI SDK tools for MoneyTools: pay-per-file speech-to-text (Transcripts) and x402 spend controls (Settle). 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
+ "ai-sdk",
22
+ "vercel-ai",
23
+ "tools",
24
+ "x402",
25
+ "speech-to-text",
26
+ "transcription",
27
+ "agents",
28
+ "base",
29
+ "usdc"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsc -p .",
33
+ "test": "npm run build && node --test test/*.test.mjs",
34
+ "prepublishOnly": "npm test"
35
+ },
36
+ "peerDependencies": {
37
+ "ai": ">=5",
38
+ "zod": ">=3.25"
39
+ },
40
+ "dependencies": {
41
+ "@moneytools-dev/transcripts": "^0.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^26.6.6",
45
+ "ai": "^7.0.166",
46
+ "typescript": "^5.9.3",
47
+ "viem": "^2.57.17",
48
+ "zod": "^4.6.7"
49
+ }
50
+ }