在 Vercel AI SDK 里,付款之前先检查
Agent 准备付钱之前,先问 OceanAlt:收款方是不是制裁或高风险地址,付款页面是不是仿冒的。每次检查返回三种结果之一:allow(没有发现阻断性问题)、review(先交给人确认)、decline(不要付)。检查跑不了时一律返回 review,不会变成 allow。包里不保存密钥,也不经手资金。
安装
npm install @oceanalt/vercel-ai ai zod用法一:给模型用的检查工具(建议性)
checkPayee 查收款方(调用 POST /api/decide),checkPaymentEndpoint 查付款网址(调用 GET /api/endpoint)。模型自己决定调不调、听不听,所以这是建议性的。
import { generateText } from "ai";
import { oceanaltTools } from "@oceanalt/vercel-ai";
const result = await generateText({
model,
tools: { ...oceanaltTools(), ...yourTools },
prompt: "Pay 2 USDC to 0x... for the weather API",
});用法二:拦在付款工具前面的守卫(强制)
guardPaymentTool 包住你自己的付款工具:原来的 execute 运行之前先检查。decline 就不执行;review 只有在你的 onReview 返回 true(有人同意)时才执行;检查失败按 review 处理。
import { generateText, tool } from "ai";
import { z } from "zod";
import { guardPaymentTool } from "@oceanalt/vercel-ai";
const transfer = tool({
description: "Send USDC on Base",
inputSchema: z.object({ recipient: z.string(), amount: z.number() }),
execute: async ({ recipient, amount }) => sendUsdc(recipient, amount),
});
// Runs POST /api/decide before the original execute. decline -> not executed.
// review -> not executed unless onReview returns true (after a human agreed).
const guardedTransfer = guardPaymentTool(transfer, {
getPayment: (input) => ({ to: input.recipient, amountUsdc: input.amount, network: "base" }),
onReview: async (result, input) => askAHuman(result, input),
});
await generateText({ model, tools: { transfer: guardedTransfer }, prompt });返回什么
decision、verdict、reason_code、retry、advice、signal_keys、evidence,以及给模型的一句 instruction。结果是基于公开数据的筛查结论,不是安全保证。

