OceanAltOceanAlt

集成指南

在 Vercel AI SDK 裡,付款之前先檢查

Agent 準備付錢之前,先問 OceanAlt:收款方是不是制裁或高風險地址,付款頁面是不是仿冒的。每次檢查返回三種結果之一:allow(沒有發現阻斷性問題)、review(先交給人確認)、decline(不要付)。檢查跑不了時一律返回 review,不會變成 allow。包裡不保存密鑰,也不經手資金。

安裝

npm install @oceanalt/vercel-ai ai zod

免費接口不需要 API key。測試過的版本:ai 7、6、5。

用法一:給模型用的檢查工具(建議性)

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。結果是基於公開數據的篩查結論,不是安全保證。

npm: @oceanalt/vercel-ai · 接口文檔 · 全部接入方式

與 Vercel 沒有隸屬關係。