@ausca/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/README.md +73 -0
- package/dist/index.cjs +107 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +82 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @ausca/ai-sdk
|
|
2
|
+
|
|
3
|
+
Vercel AI SDK tools that consume paid HTTP APIs by answering `402 Payment
|
|
4
|
+
Required` with an [x402](https://www.x402.org) v2 payment, instead of carrying
|
|
5
|
+
an API key. The model authors the request; the wallet and a hard per-call USD
|
|
6
|
+
cap stay with your code.
|
|
7
|
+
|
|
8
|
+
Works against any x402 v2 resource. [Ausca](https://ausca.com) is the default
|
|
9
|
+
example because its services are keyless and receipt-backed, which is the shape
|
|
10
|
+
this tool exists for.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @ausca/ai-sdk ai viem zod
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Use
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { generateText } from "ai";
|
|
22
|
+
import { x402Tool } from "@ausca/ai-sdk";
|
|
23
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
|
|
26
|
+
const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as `0x${string}`);
|
|
27
|
+
|
|
28
|
+
const result = await generateText({
|
|
29
|
+
model: yourModel,
|
|
30
|
+
prompt: "Extract the text from the uploaded scan.",
|
|
31
|
+
tools: {
|
|
32
|
+
// Document OCR on Ausca: copy the exact offer binding from
|
|
33
|
+
// https://ausca.com/catalog.json (offer document.ocr).
|
|
34
|
+
extract_document_text: x402Tool({
|
|
35
|
+
description:
|
|
36
|
+
"Extracts normalized text from a scanned document for $0.30. Input is the immutable artifact commitment of the uploaded document.",
|
|
37
|
+
inputSchema: z.object({
|
|
38
|
+
artifact_ref: z.string(),
|
|
39
|
+
content_digest: z.string(),
|
|
40
|
+
media_type: z.string(),
|
|
41
|
+
}),
|
|
42
|
+
url: "https://ausca.com/v1/extract-text",
|
|
43
|
+
account,
|
|
44
|
+
maxPaymentUsd: 0.5,
|
|
45
|
+
buildBody: (input) => ({
|
|
46
|
+
offer_id: "document.ocr",
|
|
47
|
+
input: { artifact: input },
|
|
48
|
+
idempotency_key: `ocr-${input.content_digest.slice(7, 27)}`,
|
|
49
|
+
}),
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The tool result carries the resource result and, when the call was paid, the
|
|
56
|
+
decoded settlement proof from the `PAYMENT-RESPONSE` header.
|
|
57
|
+
|
|
58
|
+
## Spend authority
|
|
59
|
+
|
|
60
|
+
`maxPaymentUsd` is enforced by the x402 client's spend controls before
|
|
61
|
+
anything is signed. A resource quoting above the cap makes the tool throw; no
|
|
62
|
+
payment is created. The account object never reaches the model.
|
|
63
|
+
|
|
64
|
+
## Any x402 resource
|
|
65
|
+
|
|
66
|
+
Nothing here is vendor-specific: point `url` at any endpoint that answers an
|
|
67
|
+
x402 v2 challenge and the tool pays it under the same cap. `network` defaults
|
|
68
|
+
to Base mainnet (`eip155:8453`) and accepts any CAIP-2 network your account
|
|
69
|
+
can pay on.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
x402Tool: () => x402Tool
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_ai = require("ai");
|
|
27
|
+
|
|
28
|
+
// ../payable/src/index.ts
|
|
29
|
+
var import_fetch = require("@x402/fetch");
|
|
30
|
+
var import_evm = require("@x402/evm");
|
|
31
|
+
function createPayableFetch(options) {
|
|
32
|
+
if (!Number.isFinite(options.maxPaymentUsd) || options.maxPaymentUsd <= 0) {
|
|
33
|
+
throw new Error("maxPaymentUsd must be a positive number");
|
|
34
|
+
}
|
|
35
|
+
return (0, import_fetch.wrapFetchWithPaymentFromConfig)(options.fetch ?? globalThis.fetch, {
|
|
36
|
+
schemes: [
|
|
37
|
+
{
|
|
38
|
+
network: options.network ?? "eip155:8453",
|
|
39
|
+
client: new import_evm.ExactEvmScheme(options.account)
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
spendControls: { maxAmountPerPayment: `$${options.maxPaymentUsd}` }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function paymentReceipt(response) {
|
|
46
|
+
const header = response.headers.get("PAYMENT-RESPONSE");
|
|
47
|
+
if (!header) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const decoded = (0, import_fetch.decodePaymentResponseHeader)(header);
|
|
51
|
+
return {
|
|
52
|
+
success: decoded.success === true,
|
|
53
|
+
network: typeof decoded.network === "string" ? decoded.network : void 0,
|
|
54
|
+
transaction: typeof decoded.transaction === "string" ? decoded.transaction : void 0,
|
|
55
|
+
payer: typeof decoded.payer === "string" ? decoded.payer : void 0
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function payableCall(options, body) {
|
|
59
|
+
const method = options.method ?? "POST";
|
|
60
|
+
const payableFetch = createPayableFetch(options);
|
|
61
|
+
const response = await payableFetch(options.url, {
|
|
62
|
+
method,
|
|
63
|
+
headers: { "content-type": "application/json", ...options.headers },
|
|
64
|
+
body: method === "GET" ? void 0 : JSON.stringify(body ?? {})
|
|
65
|
+
});
|
|
66
|
+
const text = await response.text();
|
|
67
|
+
let result = text;
|
|
68
|
+
try {
|
|
69
|
+
result = JSON.parse(text);
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`payable resource ${options.url} answered ${response.status}: ${text.slice(0, 512)}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return { result, payment: paymentReceipt(response), status: response.status };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/index.ts
|
|
81
|
+
function x402Tool(options) {
|
|
82
|
+
return (0, import_ai.tool)({
|
|
83
|
+
description: options.description,
|
|
84
|
+
inputSchema: options.inputSchema,
|
|
85
|
+
execute: async (input) => {
|
|
86
|
+
const outcome = await payableCall(
|
|
87
|
+
{
|
|
88
|
+
url: options.url,
|
|
89
|
+
method: options.method,
|
|
90
|
+
account: options.account,
|
|
91
|
+
network: options.network,
|
|
92
|
+
maxPaymentUsd: options.maxPaymentUsd,
|
|
93
|
+
headers: options.headers
|
|
94
|
+
},
|
|
95
|
+
options.buildBody ? options.buildBody(input) : input
|
|
96
|
+
);
|
|
97
|
+
if (outcome.payment && options.onPayment) {
|
|
98
|
+
options.onPayment(outcome.payment);
|
|
99
|
+
}
|
|
100
|
+
return { result: outcome.result, payment: outcome.payment };
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
x402Tool
|
|
107
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
3
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
|
+
import { LocalAccount } from 'viem';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PaymentReceipt } from '@ausca-internal/payable';
|
|
7
|
+
export { PaymentReceipt } from '@ausca-internal/payable';
|
|
8
|
+
|
|
9
|
+
interface X402ToolOptions<Schema extends z.ZodTypeAny> {
|
|
10
|
+
/** What the tool does and what it costs, in the model's language. */
|
|
11
|
+
readonly description: string;
|
|
12
|
+
/** Zod schema of the tool input the model authors. */
|
|
13
|
+
readonly inputSchema: Schema;
|
|
14
|
+
/** The payable resource URL. Any x402 v2 resource works. */
|
|
15
|
+
readonly url: string;
|
|
16
|
+
/** HTTP method of the payable resource. */
|
|
17
|
+
readonly method?: "GET" | "POST";
|
|
18
|
+
/** The signing account that pays. Never exposed to the model. */
|
|
19
|
+
readonly account: LocalAccount;
|
|
20
|
+
/** CAIP-2 network to pay on. Defaults to Base mainnet ("eip155:8453"). */
|
|
21
|
+
readonly network?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Hard per-call USD cap enforced before signing. The model can author the
|
|
24
|
+
* request, never the spend authority.
|
|
25
|
+
*/
|
|
26
|
+
readonly maxPaymentUsd: number;
|
|
27
|
+
/** Extra request headers. */
|
|
28
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
29
|
+
/** Maps the model-authored input to the request body. Defaults to identity. */
|
|
30
|
+
readonly buildBody?: (input: z.infer<Schema>) => unknown;
|
|
31
|
+
/** Called with the settlement proof after each paid call. */
|
|
32
|
+
readonly onPayment?: (payment: PaymentReceipt) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a Vercel AI SDK tool over one x402 payable resource. The tool result
|
|
36
|
+
* carries the resource result and, when the call was paid, the decoded
|
|
37
|
+
* settlement proof.
|
|
38
|
+
*/
|
|
39
|
+
declare function x402Tool<Schema extends z.ZodTypeAny>(options: X402ToolOptions<Schema>): ({
|
|
40
|
+
title?: string;
|
|
41
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
42
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
43
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
44
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
45
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
46
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
47
|
+
onInputDelta?: ((options: {
|
|
48
|
+
inputTextDelta: string;
|
|
49
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
50
|
+
onInputAvailable?: ((options: {
|
|
51
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
52
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
53
|
+
toModelOutput?: ((options: {
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
56
|
+
output: NoInfer<{
|
|
57
|
+
result: unknown;
|
|
58
|
+
payment: PaymentReceipt | null;
|
|
59
|
+
}>;
|
|
60
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
61
|
+
} & {
|
|
62
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
63
|
+
result: unknown;
|
|
64
|
+
payment: PaymentReceipt | null;
|
|
65
|
+
}> | undefined;
|
|
66
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
67
|
+
result: unknown;
|
|
68
|
+
payment: PaymentReceipt | null;
|
|
69
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
70
|
+
} & {
|
|
71
|
+
description?: string | ((options: {
|
|
72
|
+
context: NoInfer<_ai_sdk_provider_utils.Context>;
|
|
73
|
+
experimental_sandbox?: ai.Experimental_SandboxSession;
|
|
74
|
+
}) => string) | undefined;
|
|
75
|
+
strict?: boolean;
|
|
76
|
+
inputExamples?: {
|
|
77
|
+
input: NoInfer<z.TypeOf<Schema>>;
|
|
78
|
+
}[] | undefined;
|
|
79
|
+
id?: never;
|
|
80
|
+
isProviderExecuted?: never;
|
|
81
|
+
args?: never;
|
|
82
|
+
supportsDeferredResults?: never;
|
|
83
|
+
} & {
|
|
84
|
+
type?: undefined | "function";
|
|
85
|
+
} & {
|
|
86
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
87
|
+
result: unknown;
|
|
88
|
+
payment: PaymentReceipt | null;
|
|
89
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
90
|
+
}) | ({
|
|
91
|
+
title?: string;
|
|
92
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
93
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
94
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
95
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
96
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
97
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
98
|
+
onInputDelta?: ((options: {
|
|
99
|
+
inputTextDelta: string;
|
|
100
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
101
|
+
onInputAvailable?: ((options: {
|
|
102
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
103
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
104
|
+
toModelOutput?: ((options: {
|
|
105
|
+
toolCallId: string;
|
|
106
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
107
|
+
output: NoInfer<{
|
|
108
|
+
result: unknown;
|
|
109
|
+
payment: PaymentReceipt | null;
|
|
110
|
+
}>;
|
|
111
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
112
|
+
} & {
|
|
113
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
114
|
+
result: unknown;
|
|
115
|
+
payment: PaymentReceipt | null;
|
|
116
|
+
}> | undefined;
|
|
117
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
118
|
+
result: unknown;
|
|
119
|
+
payment: PaymentReceipt | null;
|
|
120
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
121
|
+
} & {
|
|
122
|
+
description?: string | ((options: {
|
|
123
|
+
context: NoInfer<_ai_sdk_provider_utils.Context>;
|
|
124
|
+
experimental_sandbox?: ai.Experimental_SandboxSession;
|
|
125
|
+
}) => string) | undefined;
|
|
126
|
+
strict?: boolean;
|
|
127
|
+
inputExamples?: {
|
|
128
|
+
input: NoInfer<z.TypeOf<Schema>>;
|
|
129
|
+
}[] | undefined;
|
|
130
|
+
id?: never;
|
|
131
|
+
isProviderExecuted?: never;
|
|
132
|
+
args?: never;
|
|
133
|
+
supportsDeferredResults?: never;
|
|
134
|
+
} & {
|
|
135
|
+
type: "dynamic";
|
|
136
|
+
} & {
|
|
137
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
138
|
+
result: unknown;
|
|
139
|
+
payment: PaymentReceipt | null;
|
|
140
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
141
|
+
}) | ({
|
|
142
|
+
title?: string;
|
|
143
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
144
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
145
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
146
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
147
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
148
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
149
|
+
onInputDelta?: ((options: {
|
|
150
|
+
inputTextDelta: string;
|
|
151
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
152
|
+
onInputAvailable?: ((options: {
|
|
153
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
154
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
155
|
+
toModelOutput?: ((options: {
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
158
|
+
output: NoInfer<{
|
|
159
|
+
result: unknown;
|
|
160
|
+
payment: PaymentReceipt | null;
|
|
161
|
+
}>;
|
|
162
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
163
|
+
} & {
|
|
164
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
165
|
+
result: unknown;
|
|
166
|
+
payment: PaymentReceipt | null;
|
|
167
|
+
}> | undefined;
|
|
168
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
169
|
+
result: unknown;
|
|
170
|
+
payment: PaymentReceipt | null;
|
|
171
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
172
|
+
} & {
|
|
173
|
+
type: "provider";
|
|
174
|
+
id: `${string}.${string}`;
|
|
175
|
+
args: Record<string, unknown>;
|
|
176
|
+
description?: never;
|
|
177
|
+
strict?: never;
|
|
178
|
+
inputExamples?: never;
|
|
179
|
+
} & {
|
|
180
|
+
isProviderExecuted: false;
|
|
181
|
+
supportsDeferredResults?: never;
|
|
182
|
+
} & {
|
|
183
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
184
|
+
result: unknown;
|
|
185
|
+
payment: PaymentReceipt | null;
|
|
186
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
187
|
+
}) | ({
|
|
188
|
+
title?: string;
|
|
189
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
190
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
191
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
192
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
193
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
194
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
195
|
+
onInputDelta?: ((options: {
|
|
196
|
+
inputTextDelta: string;
|
|
197
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
198
|
+
onInputAvailable?: ((options: {
|
|
199
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
200
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
201
|
+
toModelOutput?: ((options: {
|
|
202
|
+
toolCallId: string;
|
|
203
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
204
|
+
output: NoInfer<{
|
|
205
|
+
result: unknown;
|
|
206
|
+
payment: PaymentReceipt | null;
|
|
207
|
+
}>;
|
|
208
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
209
|
+
} & {
|
|
210
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
211
|
+
result: unknown;
|
|
212
|
+
payment: PaymentReceipt | null;
|
|
213
|
+
}> | undefined;
|
|
214
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
215
|
+
result: unknown;
|
|
216
|
+
payment: PaymentReceipt | null;
|
|
217
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
218
|
+
} & {
|
|
219
|
+
type: "provider";
|
|
220
|
+
id: `${string}.${string}`;
|
|
221
|
+
args: Record<string, unknown>;
|
|
222
|
+
description?: never;
|
|
223
|
+
strict?: never;
|
|
224
|
+
inputExamples?: never;
|
|
225
|
+
} & {
|
|
226
|
+
isProviderExecuted: true;
|
|
227
|
+
supportsDeferredResults?: boolean;
|
|
228
|
+
} & {
|
|
229
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
230
|
+
result: unknown;
|
|
231
|
+
payment: PaymentReceipt | null;
|
|
232
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
export { type X402ToolOptions, x402Tool };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
3
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
|
+
import { LocalAccount } from 'viem';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PaymentReceipt } from '@ausca-internal/payable';
|
|
7
|
+
export { PaymentReceipt } from '@ausca-internal/payable';
|
|
8
|
+
|
|
9
|
+
interface X402ToolOptions<Schema extends z.ZodTypeAny> {
|
|
10
|
+
/** What the tool does and what it costs, in the model's language. */
|
|
11
|
+
readonly description: string;
|
|
12
|
+
/** Zod schema of the tool input the model authors. */
|
|
13
|
+
readonly inputSchema: Schema;
|
|
14
|
+
/** The payable resource URL. Any x402 v2 resource works. */
|
|
15
|
+
readonly url: string;
|
|
16
|
+
/** HTTP method of the payable resource. */
|
|
17
|
+
readonly method?: "GET" | "POST";
|
|
18
|
+
/** The signing account that pays. Never exposed to the model. */
|
|
19
|
+
readonly account: LocalAccount;
|
|
20
|
+
/** CAIP-2 network to pay on. Defaults to Base mainnet ("eip155:8453"). */
|
|
21
|
+
readonly network?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Hard per-call USD cap enforced before signing. The model can author the
|
|
24
|
+
* request, never the spend authority.
|
|
25
|
+
*/
|
|
26
|
+
readonly maxPaymentUsd: number;
|
|
27
|
+
/** Extra request headers. */
|
|
28
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
29
|
+
/** Maps the model-authored input to the request body. Defaults to identity. */
|
|
30
|
+
readonly buildBody?: (input: z.infer<Schema>) => unknown;
|
|
31
|
+
/** Called with the settlement proof after each paid call. */
|
|
32
|
+
readonly onPayment?: (payment: PaymentReceipt) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a Vercel AI SDK tool over one x402 payable resource. The tool result
|
|
36
|
+
* carries the resource result and, when the call was paid, the decoded
|
|
37
|
+
* settlement proof.
|
|
38
|
+
*/
|
|
39
|
+
declare function x402Tool<Schema extends z.ZodTypeAny>(options: X402ToolOptions<Schema>): ({
|
|
40
|
+
title?: string;
|
|
41
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
42
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
43
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
44
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
45
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
46
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
47
|
+
onInputDelta?: ((options: {
|
|
48
|
+
inputTextDelta: string;
|
|
49
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
50
|
+
onInputAvailable?: ((options: {
|
|
51
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
52
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
53
|
+
toModelOutput?: ((options: {
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
56
|
+
output: NoInfer<{
|
|
57
|
+
result: unknown;
|
|
58
|
+
payment: PaymentReceipt | null;
|
|
59
|
+
}>;
|
|
60
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
61
|
+
} & {
|
|
62
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
63
|
+
result: unknown;
|
|
64
|
+
payment: PaymentReceipt | null;
|
|
65
|
+
}> | undefined;
|
|
66
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
67
|
+
result: unknown;
|
|
68
|
+
payment: PaymentReceipt | null;
|
|
69
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
70
|
+
} & {
|
|
71
|
+
description?: string | ((options: {
|
|
72
|
+
context: NoInfer<_ai_sdk_provider_utils.Context>;
|
|
73
|
+
experimental_sandbox?: ai.Experimental_SandboxSession;
|
|
74
|
+
}) => string) | undefined;
|
|
75
|
+
strict?: boolean;
|
|
76
|
+
inputExamples?: {
|
|
77
|
+
input: NoInfer<z.TypeOf<Schema>>;
|
|
78
|
+
}[] | undefined;
|
|
79
|
+
id?: never;
|
|
80
|
+
isProviderExecuted?: never;
|
|
81
|
+
args?: never;
|
|
82
|
+
supportsDeferredResults?: never;
|
|
83
|
+
} & {
|
|
84
|
+
type?: undefined | "function";
|
|
85
|
+
} & {
|
|
86
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
87
|
+
result: unknown;
|
|
88
|
+
payment: PaymentReceipt | null;
|
|
89
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
90
|
+
}) | ({
|
|
91
|
+
title?: string;
|
|
92
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
93
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
94
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
95
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
96
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
97
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
98
|
+
onInputDelta?: ((options: {
|
|
99
|
+
inputTextDelta: string;
|
|
100
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
101
|
+
onInputAvailable?: ((options: {
|
|
102
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
103
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
104
|
+
toModelOutput?: ((options: {
|
|
105
|
+
toolCallId: string;
|
|
106
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
107
|
+
output: NoInfer<{
|
|
108
|
+
result: unknown;
|
|
109
|
+
payment: PaymentReceipt | null;
|
|
110
|
+
}>;
|
|
111
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
112
|
+
} & {
|
|
113
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
114
|
+
result: unknown;
|
|
115
|
+
payment: PaymentReceipt | null;
|
|
116
|
+
}> | undefined;
|
|
117
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
118
|
+
result: unknown;
|
|
119
|
+
payment: PaymentReceipt | null;
|
|
120
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
121
|
+
} & {
|
|
122
|
+
description?: string | ((options: {
|
|
123
|
+
context: NoInfer<_ai_sdk_provider_utils.Context>;
|
|
124
|
+
experimental_sandbox?: ai.Experimental_SandboxSession;
|
|
125
|
+
}) => string) | undefined;
|
|
126
|
+
strict?: boolean;
|
|
127
|
+
inputExamples?: {
|
|
128
|
+
input: NoInfer<z.TypeOf<Schema>>;
|
|
129
|
+
}[] | undefined;
|
|
130
|
+
id?: never;
|
|
131
|
+
isProviderExecuted?: never;
|
|
132
|
+
args?: never;
|
|
133
|
+
supportsDeferredResults?: never;
|
|
134
|
+
} & {
|
|
135
|
+
type: "dynamic";
|
|
136
|
+
} & {
|
|
137
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
138
|
+
result: unknown;
|
|
139
|
+
payment: PaymentReceipt | null;
|
|
140
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
141
|
+
}) | ({
|
|
142
|
+
title?: string;
|
|
143
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
144
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
145
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
146
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
147
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
148
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
149
|
+
onInputDelta?: ((options: {
|
|
150
|
+
inputTextDelta: string;
|
|
151
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
152
|
+
onInputAvailable?: ((options: {
|
|
153
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
154
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
155
|
+
toModelOutput?: ((options: {
|
|
156
|
+
toolCallId: string;
|
|
157
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
158
|
+
output: NoInfer<{
|
|
159
|
+
result: unknown;
|
|
160
|
+
payment: PaymentReceipt | null;
|
|
161
|
+
}>;
|
|
162
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
163
|
+
} & {
|
|
164
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
165
|
+
result: unknown;
|
|
166
|
+
payment: PaymentReceipt | null;
|
|
167
|
+
}> | undefined;
|
|
168
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
169
|
+
result: unknown;
|
|
170
|
+
payment: PaymentReceipt | null;
|
|
171
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
172
|
+
} & {
|
|
173
|
+
type: "provider";
|
|
174
|
+
id: `${string}.${string}`;
|
|
175
|
+
args: Record<string, unknown>;
|
|
176
|
+
description?: never;
|
|
177
|
+
strict?: never;
|
|
178
|
+
inputExamples?: never;
|
|
179
|
+
} & {
|
|
180
|
+
isProviderExecuted: false;
|
|
181
|
+
supportsDeferredResults?: never;
|
|
182
|
+
} & {
|
|
183
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
184
|
+
result: unknown;
|
|
185
|
+
payment: PaymentReceipt | null;
|
|
186
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
187
|
+
}) | ({
|
|
188
|
+
title?: string;
|
|
189
|
+
providerOptions?: _ai_sdk_provider_utils.ProviderOptions;
|
|
190
|
+
metadata?: _ai_sdk_provider.JSONObject;
|
|
191
|
+
inputSchema: ai.FlexibleSchema<z.TypeOf<Schema>>;
|
|
192
|
+
contextSchema?: ai.FlexibleSchema<_ai_sdk_provider_utils.Context> | undefined;
|
|
193
|
+
needsApproval?: boolean | _ai_sdk_provider_utils.ToolNeedsApprovalFunction<[z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>, NoInfer<_ai_sdk_provider_utils.Context>> | undefined;
|
|
194
|
+
onInputStart?: ((options: ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
195
|
+
onInputDelta?: ((options: {
|
|
196
|
+
inputTextDelta: string;
|
|
197
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
198
|
+
onInputAvailable?: ((options: {
|
|
199
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
200
|
+
} & ai.ToolExecutionOptions<NoInfer<_ai_sdk_provider_utils.Context>>) => void | PromiseLike<void>) | undefined;
|
|
201
|
+
toModelOutput?: ((options: {
|
|
202
|
+
toolCallId: string;
|
|
203
|
+
input: [z.TypeOf<Schema>] extends [never] ? unknown : z.TypeOf<Schema>;
|
|
204
|
+
output: NoInfer<{
|
|
205
|
+
result: unknown;
|
|
206
|
+
payment: PaymentReceipt | null;
|
|
207
|
+
}>;
|
|
208
|
+
}) => _ai_sdk_provider_utils.ToolResultOutput | PromiseLike<_ai_sdk_provider_utils.ToolResultOutput>) | undefined;
|
|
209
|
+
} & {
|
|
210
|
+
outputSchema?: ai.FlexibleSchema<{
|
|
211
|
+
result: unknown;
|
|
212
|
+
payment: PaymentReceipt | null;
|
|
213
|
+
}> | undefined;
|
|
214
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
215
|
+
result: unknown;
|
|
216
|
+
payment: PaymentReceipt | null;
|
|
217
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
218
|
+
} & {
|
|
219
|
+
type: "provider";
|
|
220
|
+
id: `${string}.${string}`;
|
|
221
|
+
args: Record<string, unknown>;
|
|
222
|
+
description?: never;
|
|
223
|
+
strict?: never;
|
|
224
|
+
inputExamples?: never;
|
|
225
|
+
} & {
|
|
226
|
+
isProviderExecuted: true;
|
|
227
|
+
supportsDeferredResults?: boolean;
|
|
228
|
+
} & {
|
|
229
|
+
execute: ai.ToolExecuteFunction<z.TypeOf<Schema>, {
|
|
230
|
+
result: unknown;
|
|
231
|
+
payment: PaymentReceipt | null;
|
|
232
|
+
}, NoInfer<_ai_sdk_provider_utils.Context>>;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
export { type X402ToolOptions, x402Tool };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
// ../payable/src/index.ts
|
|
5
|
+
import { decodePaymentResponseHeader, wrapFetchWithPaymentFromConfig } from "@x402/fetch";
|
|
6
|
+
import { ExactEvmScheme } from "@x402/evm";
|
|
7
|
+
function createPayableFetch(options) {
|
|
8
|
+
if (!Number.isFinite(options.maxPaymentUsd) || options.maxPaymentUsd <= 0) {
|
|
9
|
+
throw new Error("maxPaymentUsd must be a positive number");
|
|
10
|
+
}
|
|
11
|
+
return wrapFetchWithPaymentFromConfig(options.fetch ?? globalThis.fetch, {
|
|
12
|
+
schemes: [
|
|
13
|
+
{
|
|
14
|
+
network: options.network ?? "eip155:8453",
|
|
15
|
+
client: new ExactEvmScheme(options.account)
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
spendControls: { maxAmountPerPayment: `$${options.maxPaymentUsd}` }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function paymentReceipt(response) {
|
|
22
|
+
const header = response.headers.get("PAYMENT-RESPONSE");
|
|
23
|
+
if (!header) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const decoded = decodePaymentResponseHeader(header);
|
|
27
|
+
return {
|
|
28
|
+
success: decoded.success === true,
|
|
29
|
+
network: typeof decoded.network === "string" ? decoded.network : void 0,
|
|
30
|
+
transaction: typeof decoded.transaction === "string" ? decoded.transaction : void 0,
|
|
31
|
+
payer: typeof decoded.payer === "string" ? decoded.payer : void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function payableCall(options, body) {
|
|
35
|
+
const method = options.method ?? "POST";
|
|
36
|
+
const payableFetch = createPayableFetch(options);
|
|
37
|
+
const response = await payableFetch(options.url, {
|
|
38
|
+
method,
|
|
39
|
+
headers: { "content-type": "application/json", ...options.headers },
|
|
40
|
+
body: method === "GET" ? void 0 : JSON.stringify(body ?? {})
|
|
41
|
+
});
|
|
42
|
+
const text = await response.text();
|
|
43
|
+
let result = text;
|
|
44
|
+
try {
|
|
45
|
+
result = JSON.parse(text);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`payable resource ${options.url} answered ${response.status}: ${text.slice(0, 512)}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return { result, payment: paymentReceipt(response), status: response.status };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/index.ts
|
|
57
|
+
function x402Tool(options) {
|
|
58
|
+
return tool({
|
|
59
|
+
description: options.description,
|
|
60
|
+
inputSchema: options.inputSchema,
|
|
61
|
+
execute: async (input) => {
|
|
62
|
+
const outcome = await payableCall(
|
|
63
|
+
{
|
|
64
|
+
url: options.url,
|
|
65
|
+
method: options.method,
|
|
66
|
+
account: options.account,
|
|
67
|
+
network: options.network,
|
|
68
|
+
maxPaymentUsd: options.maxPaymentUsd,
|
|
69
|
+
headers: options.headers
|
|
70
|
+
},
|
|
71
|
+
options.buildBody ? options.buildBody(input) : input
|
|
72
|
+
);
|
|
73
|
+
if (outcome.payment && options.onPayment) {
|
|
74
|
+
options.onPayment(outcome.payment);
|
|
75
|
+
}
|
|
76
|
+
return { result: outcome.result, payment: outcome.payment };
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
x402Tool
|
|
82
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ausca/ai-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vercel AI SDK tools that pay for HTTP 402 APIs over x402 instead of carrying API keys. Works with any x402 v2 resource; Ausca is the default example.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://ausca.com",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": ["ai-sdk", "vercel", "x402", "payments", "agents", "tools", "ausca"],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": ["dist", "README.md"],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
22
|
+
"test": "vitest run"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@x402/evm": "^2.24.0",
|
|
26
|
+
"@x402/fetch": "^2.24.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"ai": ">=5",
|
|
30
|
+
"viem": ">=2",
|
|
31
|
+
"zod": ">=3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@ausca-internal/payable": "*",
|
|
35
|
+
"ai": "^7.0.0",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"typescript": "^5.9.0",
|
|
38
|
+
"viem": "^2.44.0",
|
|
39
|
+
"vitest": "^4.0.0",
|
|
40
|
+
"zod": "^3.25.0"
|
|
41
|
+
},
|
|
42
|
+
"tsup": {
|
|
43
|
+
"noExternal": ["@ausca-internal/payable"]
|
|
44
|
+
}
|
|
45
|
+
}
|