@sardis/ai-sdk 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/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2026-01-27
9
+
10
+ ### Added
11
+
12
+ - Initial release of `@sardis/ai-sdk`
13
+ - **Tool Functions**
14
+ - `createSardisTools()` - Full tool set (7 tools)
15
+ - `createMinimalSardisTools()` - Pay + balance only
16
+ - `createReadOnlySardisTools()` - Analytics only (no payments)
17
+ - **Tools**
18
+ - `sardis_pay` - Execute payments
19
+ - `sardis_create_hold` - Create pre-authorizations
20
+ - `sardis_capture_hold` - Capture holds
21
+ - `sardis_void_hold` - Cancel holds
22
+ - `sardis_check_policy` - Policy verification
23
+ - `sardis_get_balance` - Wallet balance
24
+ - `sardis_get_spending` - Spending analytics
25
+ - **SardisProvider Class**
26
+ - High-level provider for Vercel AI SDK integration
27
+ - Built-in system prompt with payment guidelines
28
+ - Transaction logging and callbacks
29
+ - Direct payment methods (without AI)
30
+ - **Policy Enforcement**
31
+ - Local pre-checks before API calls
32
+ - Maximum payment amount limits
33
+ - Blocked category filtering
34
+ - Allowed merchant whitelist mode
35
+ - **TypeScript Support**
36
+ - Full type definitions
37
+ - Zod schemas for validation
38
+ - Exported types for all parameters and results
39
+
40
+ ### Dependencies
41
+
42
+ - Requires `ai` >= 3.0.0 (Vercel AI SDK)
43
+ - Uses `@sardis/sdk` for API communication
44
+ - Uses `zod` for schema validation
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sardis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # @sardis/ai-sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@sardis/ai-sdk.svg)](https://www.npmjs.com/package/@sardis/ai-sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ **Sardis payment tools for Vercel AI SDK** - Enable AI agents to make payments with policy guardrails.
7
+
8
+ ## Features
9
+
10
+ - 🔧 **Drop-in tools** for Vercel AI SDK (`generateText`, `streamText`)
11
+ - 💰 **Payments** - Execute stablecoin payments on-chain
12
+ - 🔒 **Holds** - Pre-authorize funds for variable amounts
13
+ - 📋 **Policy checks** - Verify payments before execution
14
+ - 📊 **Spending analytics** - Track budgets and limits
15
+ - 🛡️ **Built-in guardrails** - Prevent unauthorized spending
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @sardis/ai-sdk ai
21
+ # or
22
+ pnpm add @sardis/ai-sdk ai
23
+ # or
24
+ yarn add @sardis/ai-sdk ai
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### Basic Usage
30
+
31
+ ```typescript
32
+ import { generateText } from 'ai'
33
+ import { openai } from '@ai-sdk/openai'
34
+ import { createSardisTools } from '@sardis/ai-sdk'
35
+
36
+ const tools = createSardisTools({
37
+ apiKey: process.env.SARDIS_API_KEY!,
38
+ walletId: 'wallet_abc123',
39
+ })
40
+
41
+ const { text, toolResults } = await generateText({
42
+ model: openai('gpt-4o'),
43
+ tools,
44
+ prompt: 'Pay $50 to merchant_xyz for API credits',
45
+ })
46
+
47
+ console.log(text)
48
+ // "I've successfully paid $50 to merchant_xyz. Transaction ID: tx_abc123"
49
+ ```
50
+
51
+ ### With SardisProvider (Recommended)
52
+
53
+ ```typescript
54
+ import { generateText } from 'ai'
55
+ import { openai } from '@ai-sdk/openai'
56
+ import { SardisProvider } from '@sardis/ai-sdk'
57
+
58
+ const sardis = new SardisProvider({
59
+ apiKey: process.env.SARDIS_API_KEY!,
60
+ walletId: 'wallet_abc123',
61
+ enableLogging: true,
62
+ onTransaction: async (event) => {
63
+ // Log all transactions to your database
64
+ await db.transactions.insert(event)
65
+ },
66
+ })
67
+
68
+ const { text } = await generateText({
69
+ model: openai('gpt-4o'),
70
+ tools: sardis.tools,
71
+ system: sardis.systemPrompt, // Includes payment guidelines
72
+ prompt: 'Check my balance and pay $25 for API credits',
73
+ })
74
+ ```
75
+
76
+ ### Direct API Access
77
+
78
+ ```typescript
79
+ import { SardisProvider } from '@sardis/ai-sdk'
80
+
81
+ const sardis = new SardisProvider({
82
+ apiKey: process.env.SARDIS_API_KEY!,
83
+ walletId: 'wallet_abc123',
84
+ })
85
+
86
+ // Check balance
87
+ const balance = await sardis.getBalance()
88
+ console.log(`Available: $${balance.available}`)
89
+
90
+ // Execute payment
91
+ const result = await sardis.pay({
92
+ to: 'merchant_openai',
93
+ amount: 50,
94
+ memo: 'API credits',
95
+ })
96
+
97
+ if (result.success) {
98
+ console.log(`Paid! TX: ${result.txHash}`)
99
+ }
100
+ ```
101
+
102
+ ## Available Tools
103
+
104
+ | Tool | Description |
105
+ |------|-------------|
106
+ | `sardis_pay` | Execute a payment from the wallet |
107
+ | `sardis_create_hold` | Create a hold (pre-authorization) |
108
+ | `sardis_capture_hold` | Capture a previously created hold |
109
+ | `sardis_void_hold` | Void/cancel a hold |
110
+ | `sardis_check_policy` | Check if payment is allowed by policy |
111
+ | `sardis_get_balance` | Get wallet balance |
112
+ | `sardis_get_spending` | Get spending summary |
113
+
114
+ ## Configuration Options
115
+
116
+ ```typescript
117
+ createSardisTools({
118
+ // Required
119
+ apiKey: string,
120
+ walletId: string,
121
+
122
+ // Optional
123
+ agentId?: string, // Agent identifier
124
+ baseUrl?: string, // Custom API URL
125
+ simulationMode?: boolean, // Test without real transactions
126
+ maxPaymentAmount?: number, // Max single payment limit
127
+ blockedCategories?: string[], // Block merchant categories
128
+ allowedMerchants?: string[], // Whitelist mode
129
+ })
130
+ ```
131
+
132
+ ## Tool Sets
133
+
134
+ ```typescript
135
+ import {
136
+ createSardisTools, // Full tool set (7 tools)
137
+ createMinimalSardisTools, // Just pay + balance
138
+ createReadOnlySardisTools, // No payments, analytics only
139
+ } from '@sardis/ai-sdk'
140
+ ```
141
+
142
+ ## Policy Enforcement
143
+
144
+ Sardis automatically enforces spending policies:
145
+
146
+ ```typescript
147
+ const tools = createSardisTools({
148
+ apiKey: '...',
149
+ walletId: '...',
150
+ maxPaymentAmount: 100, // Block payments over $100
151
+ blockedCategories: ['gambling', 'adult'],
152
+ allowedMerchants: ['openai', 'anthropic', 'aws'], // Whitelist
153
+ })
154
+
155
+ // This will fail with policy violation
156
+ const result = await generateText({
157
+ model: openai('gpt-4o'),
158
+ tools,
159
+ prompt: 'Pay $500 to some_casino',
160
+ })
161
+ // Result: "Payment blocked: Amount $500 exceeds maximum allowed payment of $100"
162
+ ```
163
+
164
+ ## Holds (Pre-authorization)
165
+
166
+ Use holds when the final amount isn't known:
167
+
168
+ ```typescript
169
+ const { text } = await generateText({
170
+ model: openai('gpt-4o'),
171
+ tools: sardis.tools,
172
+ prompt: `
173
+ I need to book a hotel room for 2 nights at approximately $150/night.
174
+ Create a hold for the estimated total, then when I confirm the
175
+ exact price of $287.50, capture that amount.
176
+ `,
177
+ })
178
+ ```
179
+
180
+ ## Streaming
181
+
182
+ Works with `streamText` too:
183
+
184
+ ```typescript
185
+ import { streamText } from 'ai'
186
+
187
+ const result = streamText({
188
+ model: openai('gpt-4o'),
189
+ tools: sardis.tools,
190
+ prompt: 'Pay $25 to merchant_abc',
191
+ })
192
+
193
+ for await (const chunk of result.textStream) {
194
+ process.stdout.write(chunk)
195
+ }
196
+ ```
197
+
198
+ ## Framework Support
199
+
200
+ Works with any model provider supported by Vercel AI SDK:
201
+
202
+ ```typescript
203
+ import { openai } from '@ai-sdk/openai'
204
+ import { anthropic } from '@ai-sdk/anthropic'
205
+ import { google } from '@ai-sdk/google'
206
+
207
+ // Works with all providers
208
+ generateText({ model: openai('gpt-4o'), tools: sardis.tools, ... })
209
+ generateText({ model: anthropic('claude-3-5-sonnet-20241022'), tools: sardis.tools, ... })
210
+ generateText({ model: google('gemini-1.5-pro'), tools: sardis.tools, ... })
211
+ ```
212
+
213
+ ## TypeScript
214
+
215
+ Full TypeScript support with exported types:
216
+
217
+ ```typescript
218
+ import type {
219
+ SardisToolsConfig,
220
+ PaymentResult,
221
+ HoldResult,
222
+ PolicyCheckResult,
223
+ BalanceResult,
224
+ TransactionEvent,
225
+ } from '@sardis/ai-sdk'
226
+ ```
227
+
228
+ ## Error Handling
229
+
230
+ ```typescript
231
+ const result = await sardis.pay({
232
+ to: 'merchant',
233
+ amount: 1000,
234
+ })
235
+
236
+ if (!result.success) {
237
+ console.error(`Payment failed: ${result.error}`)
238
+ // "Payment failed: Amount exceeds daily spending limit"
239
+ }
240
+ ```
241
+
242
+ ## Related Packages
243
+
244
+ - [`@sardis/sdk`](https://www.npmjs.com/package/@sardis/sdk) - Full TypeScript SDK
245
+ - [`@sardis/mcp-server`](https://www.npmjs.com/package/@sardis/mcp-server) - MCP Server for Claude
246
+ - [`@sardis/ramp`](https://www.npmjs.com/package/@sardis/ramp) - Fiat on/off ramps
247
+
248
+ ## Links
249
+
250
+ - [Documentation](https://sardis.sh/docs)
251
+ - [API Reference](https://sardis.sh/docs/api)
252
+ - [GitHub](https://github.com/sardis-project/sardis)
253
+ - [Discord](https://discord.gg/sardis)
254
+
255
+ ## License
256
+
257
+ MIT © [Sardis](https://sardis.sh)