@botsrated/ai-sdk 0.1.0 → 0.1.2
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 +24 -7
- package/dist/index.d.ts +23 -1623
- package/dist/index.js +10 -3
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -3,32 +3,49 @@
|
|
|
3
3
|
[AI SDK](https://ai-sdk.dev) tools for [BotsRated](https://botsrated.com) (beta). Use them as a
|
|
4
4
|
pre-payment check before an agent pays an x402 seller.
|
|
5
5
|
|
|
6
|
-
**Status:
|
|
7
|
-
|
|
6
|
+
**Status: published on npm as [`@botsrated/ai-sdk`](https://www.npmjs.com/package/@botsrated/ai-sdk) (0.1.2).** It depends on
|
|
7
|
+
[`@botsrated/x402-preflight`](https://www.npmjs.com/package/@botsrated/x402-preflight) `^0.1.2`. Docs: https://botsrated.com/docs/ai-sdk
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @botsrated/ai-sdk ai zod
|
|
11
|
+
```
|
|
8
12
|
|
|
9
13
|
```ts
|
|
10
|
-
import { generateText,
|
|
14
|
+
import { generateText, stepCountIs } from "ai";
|
|
11
15
|
import { botsratedTools } from "@botsrated/ai-sdk";
|
|
12
16
|
|
|
13
17
|
const { text } = await generateText({
|
|
14
18
|
model: "openai/gpt-5-mini",
|
|
15
19
|
prompt: "Before paying https://blockrun.ai/api/v1/chat/completions (payTo 0xe903...1aBf), check it.",
|
|
16
20
|
tools: botsratedTools(), // { botsratedPreflight } – free
|
|
17
|
-
stopWhen: isStepCount(3)
|
|
21
|
+
stopWhen: stepCountIs(3), // AI SDK 7 also exports isStepCount(3)
|
|
18
22
|
});
|
|
19
23
|
```
|
|
20
24
|
|
|
25
|
+
`botsratedTools()` returns the AI SDK's `ToolSet` type, so it type-checks as `tools:` (or spread into one) under
|
|
26
|
+
strict TypeScript on AI SDK 5, 6 and 7 (0.1.1 did not on AI SDK 7; fixed in 0.1.2). The single tools are also
|
|
27
|
+
exported as `botsratedPreflight(client)` and `botsratedCheck(client)`. `stepCountIs` works on AI SDK 5, 6 and 7. `isStepCount` is the AI SDK 7 name (AI SDK 7 needs Node 22+).
|
|
28
|
+
|
|
21
29
|
Opt-in paid check, capped by a budget:
|
|
22
30
|
|
|
23
31
|
```ts
|
|
24
|
-
import { x402Client
|
|
32
|
+
import { x402Client } from "@x402/core/client";
|
|
33
|
+
import { registerExactEvmScheme } from "@x402/evm/exact/client";
|
|
25
34
|
import { BotsRatedClient, botsratedTools } from "@botsrated/ai-sdk";
|
|
26
35
|
|
|
27
|
-
const
|
|
36
|
+
const x402 = new x402Client();
|
|
37
|
+
registerExactEvmScheme(x402, { signer }); // your signer, e.g. a viem account
|
|
38
|
+
const client = new BotsRatedClient({ paid: { budgetUsd: 0.02, x402Client: x402 } });
|
|
28
39
|
const tools = botsratedTools(client); // { botsratedPreflight, botsratedCheck ($0.001 each after 100 free/day, stops at $0.02) }
|
|
29
40
|
```
|
|
30
41
|
|
|
42
|
+
The client validates BotsRated's 402 and signs only a copy rebuilt from allowlisted fields: a one-shot
|
|
43
|
+
EIP-3009 USDC payment on Base to BotsRated's payTo at the published price. A quote asking for Permit2
|
|
44
|
+
(`extra.assetTransferMethod`), carrying payment extensions such as `erc20ApprovalGasSponsoring`, or a
|
|
45
|
+
`maxTimeoutSeconds` above 600 is refused before anything is signed.
|
|
46
|
+
|
|
31
47
|
To guard every x402 payment, not only those the model calls a tool for, register
|
|
32
48
|
`createPrePaymentGuard().beforePaymentCreation` from `@botsrated/x402-preflight` on your `x402Client`.
|
|
33
49
|
|
|
34
|
-
Tests: `npm test
|
|
50
|
+
Tests: `npm test` (includes a `generateText` run with `MockLanguageModelV3`) and `npm run typecheck`
|
|
51
|
+
(compiles the tools-registry usage example under strict TypeScript).
|