agent402-function-tools 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +95 -2
- package/index.d.ts +40 -0
- package/index.js +192 -0
- package/package.json +68 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cardhavok LLC (doing business as Havok Holdings LLC)
|
|
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
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agent402-function-tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Agent402](https://agent402.tools) tools as **FunctionTool instances**, for use with LlamaIndex TS. Agent402 is the open-source, self-hostable x402 + MCP server with 500+ pay-per-call web tools (browser, web search, PDF, images, live data, payment helpers, wallet-keyed memory).
|
|
4
|
+
|
|
5
|
+
Works with LlamaIndex TS (`llamaindex`). Agent402 is not affiliated with or endorsed by LlamaIndex.
|
|
6
|
+
|
|
7
|
+
Formerly `agent402-llamaindex`: the same API under a new name. Change the dependency and the import specifier; nothing else changes.
|
|
8
|
+
|
|
9
|
+
> **Agent402 is the applied layer of [Agentic Finance](https://agent402.tools/agentic-finance)** - agents that pay and get paid on their own over the two open wires, [x402](https://agent402.tools/what-is-x402) and [MPP](https://agent402.tools/what-is-mpp) (Machine Payments Protocol). Every paid endpoint answers both on the same 402; wallet-only tools take any payment-wrapped fetch (`@x402/fetch`, or a stock `mppx` fetch).
|
|
10
|
+
|
|
11
|
+
- **Zero new infra.** Get back a ready-to-pass `FunctionTool[]` array for any LlamaIndex agent.
|
|
12
|
+
- **Free tier by default.** No wallet needed - compute-payable tools settle with a built-in proof-of-work.
|
|
13
|
+
- **Wallet-only tools optional.** Pass an `@x402/fetch`-wrapped fetch to use the full catalog.
|
|
14
|
+
- **Raw JSON Schema.** No Zod or manual schema authoring needed.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install llamaindex @llamaindex/workflow @llamaindex/openai agent402-function-tools @x402/fetch @x402/core @x402/evm viem
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`llamaindex` is what this adapter builds its tools with; `@llamaindex/workflow`
|
|
23
|
+
(the agent) and `@llamaindex/openai` (an LLM) are what the example below runs on,
|
|
24
|
+
and the `@x402/*` and `viem` packages pay wallet-only tools from your wallet.
|
|
25
|
+
|
|
26
|
+
## Use with an agent workflow
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { agent } from "@llamaindex/workflow";
|
|
30
|
+
import { openai } from "@llamaindex/openai";
|
|
31
|
+
import { agent402Tools } from "agent402-function-tools";
|
|
32
|
+
import { wrapFetchWithPayment } from "@x402/fetch";
|
|
33
|
+
import { x402Client } from "@x402/core/client";
|
|
34
|
+
import { registerExactEvmScheme } from "@x402/evm/exact/client";
|
|
35
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
36
|
+
|
|
37
|
+
const payClient = new x402Client();
|
|
38
|
+
registerExactEvmScheme(payClient, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
|
|
39
|
+
const payFetch = wrapFetchWithPayment(fetch, payClient);
|
|
40
|
+
|
|
41
|
+
// Web search, then a cited answer: both wallet-only, paid per call through payFetch.
|
|
42
|
+
const { tools } = await agent402Tools({ slugs: ["search", "answer"], freeOnly: false, fetch: payFetch });
|
|
43
|
+
|
|
44
|
+
const myAgent = agent({ tools, llm: openai({ model: "gpt-6-luna" }) });
|
|
45
|
+
const res = await myAgent.run("Search the web for x402 payment protocol adoption, then answer with citations: what is the x402 payment protocol?");
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**No wallet yet?** The pure-CPU tools (hash, uuid, base64, markdown, JSON and more) run free with proof-of-work and no wallet. Leave out `fetch`; the default (`freeOnly: true`) keeps only those tools:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const { tools } = await agent402Tools({ slugs: ["hash", "uuid", "json-to-csv"] });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## More wallet-only tools
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const { tools } = await agent402Tools({
|
|
58
|
+
slugs: ["extract", "render", "screenshot"],
|
|
59
|
+
freeOnly: false,
|
|
60
|
+
fetch: payFetch, // the @x402/fetch-wrapped fetch from above
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Spending caps
|
|
65
|
+
|
|
66
|
+
agent402-client 0.10.0 and later hold one ceiling by default: `maxPerCallUsd`
|
|
67
|
+
of $5, above every catalog price (`0` or `"off"` turns it off). The rolling
|
|
68
|
+
caps are opt-in. Pass agent402-client's caps through (since 0.2.0); a paid
|
|
69
|
+
call over one is refused before anything is signed, with a
|
|
70
|
+
`SpendingLimitError`:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const { tools, execute } = await agent402Tools({
|
|
74
|
+
slugs: ["search", "answer"], freeOnly: false, fetch: payFetch,
|
|
75
|
+
x402Client: client, // the @x402/core client payFetch wraps: caps hold at signing
|
|
76
|
+
maxPerCallUsd: 0.05, // per call
|
|
77
|
+
dailyLimitUsd: 5, // rolling 24 hours
|
|
78
|
+
maxPerHostUsd: 1, // rolling 24 hours, per seller host
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`agent402Execute` takes the same options.
|
|
83
|
+
|
|
84
|
+
## Self-hosted Agent402
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const { tools } = await agent402Tools({ baseUrl: "https://agent402.example.com" });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Trust & `baseUrl`
|
|
91
|
+
|
|
92
|
+
The catalog server you point `baseUrl` at controls the **name, description, and JSON Schema** of every generated tool - and tool descriptions are passed to your LLM. Only point `baseUrl` at an Agent402 instance you operate or trust. The default (`https://agent402.tools`) is the maintained, open-source hosted instance.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Type declarations for agent402-function-tools. The runtime is index.js (plain ES modules on
|
|
2
|
+
// agent402-client); these declarations describe its public API.
|
|
3
|
+
import type { Agent402, FetchLike } from "agent402-client";
|
|
4
|
+
|
|
5
|
+
export interface Agent402ToolOptions {
|
|
6
|
+
/** Default "https://agent402.tools". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Only these slugs (recommended: every tool is a definition the model reads). */
|
|
9
|
+
slugs?: string[];
|
|
10
|
+
/** Only the tools that run free with proof of work (default true). */
|
|
11
|
+
freeOnly?: boolean;
|
|
12
|
+
/** An x402- or MPP-wrapped fetch that pays wallet-only tools. */
|
|
13
|
+
fetch?: FetchLike;
|
|
14
|
+
/** Spending caps passed to agent402-client: one paid call (default 5; 0 or "off" turns it off). */
|
|
15
|
+
maxPerCallUsd?: number | string | null;
|
|
16
|
+
/** Rolling 24-hour total for paid calls (opt-in). */
|
|
17
|
+
dailyLimitUsd?: number | null;
|
|
18
|
+
/** Rolling 24-hour total per seller host (opt-in). */
|
|
19
|
+
maxPerHostUsd?: number | null;
|
|
20
|
+
/** The @x402/core x402Client the fetch wraps, so the caps hold on the payment that is signed. */
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
x402Client?: any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ExecuteOptions = Omit<Agent402ToolOptions, "slugs" | "freeOnly">;
|
|
26
|
+
|
|
27
|
+
/** Runs a tool by its tool name (or slug) and resolves to its JSON answer. */
|
|
28
|
+
export type Agent402Execute = (name: string, args?: Record<string, unknown>) => Promise<unknown>;
|
|
29
|
+
|
|
30
|
+
/** A LlamaIndex.TS function tool, typed loosely (llamaindex is a peer). */
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
export type LlamaIndexTool = any;
|
|
33
|
+
|
|
34
|
+
/** Agent402 tools as LlamaIndex.TS function tools, the client, and an executor (needs llamaindex). */
|
|
35
|
+
export function agent402Tools(opts?: Agent402ToolOptions): Promise<{ client: Agent402; tools: LlamaIndexTool[]; execute: Agent402Execute }>;
|
|
36
|
+
|
|
37
|
+
/** An executor for a tool list built another way. */
|
|
38
|
+
export function agent402Execute(opts?: ExecuteOptions): Agent402Execute;
|
|
39
|
+
|
|
40
|
+
export default agent402Tools;
|
package/index.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// agent402-function-tools (formerly agent402-llamaindex): Agent402 tools as
|
|
2
|
+
// FunctionTool instances for use with LlamaIndex TS.
|
|
3
|
+
//
|
|
4
|
+
// Turn the Agent402 catalog (500+ pay-per-call web tools) into LlamaIndex
|
|
5
|
+
// `FunctionTool` instances any agent can invoke, with payment handled for you
|
|
6
|
+
// under the hood by agent402-client (proof-of-work for the free tier,
|
|
7
|
+
// x402+USDC for wallet-only tools when you pass a payFetch).
|
|
8
|
+
//
|
|
9
|
+
// import { agent } from "@llamaindex/workflow";
|
|
10
|
+
// import { openai } from "@llamaindex/openai";
|
|
11
|
+
// import { agent402Tools } from "agent402-function-tools";
|
|
12
|
+
//
|
|
13
|
+
// const { tools } = await agent402Tools({ slugs: ["hash","uuid"] });
|
|
14
|
+
// const a = agent({ llm: openai({ model: "gpt-4o-mini" }), tools });
|
|
15
|
+
// const res = await a.run("Hash 'hello world' with SHA-256");
|
|
16
|
+
//
|
|
17
|
+
// The returned tools are FunctionTool instances, usable by any LlamaIndex
|
|
18
|
+
// agent that accepts them.
|
|
19
|
+
|
|
20
|
+
import { Agent402 } from "agent402-client";
|
|
21
|
+
|
|
22
|
+
const DEFAULT_BASE = "https://agent402.tools";
|
|
23
|
+
// Keep in lockstep with package.json: the User-Agent product token that names
|
|
24
|
+
// this package on every call it sends.
|
|
25
|
+
const USER_AGENT = "agent402-function-tools/0.3.0";
|
|
26
|
+
|
|
27
|
+
// Discovery reads (catalog, find, route, manifest, a proof-of-work challenge)
|
|
28
|
+
// settle nothing, so a 503 the server sheds under load is safe to repeat. It
|
|
29
|
+
// is retried only when it names its own delay (a Retry-After header or a
|
|
30
|
+
// retryAfterSeconds body field), at most DISCOVERY_ATTEMPTS tries in all,
|
|
31
|
+
// each wait capped at DISCOVERY_MAX_WAIT_MS. A paid call never goes through
|
|
32
|
+
// here: a repeat of one could settle twice.
|
|
33
|
+
const DISCOVERY_ATTEMPTS = 3;
|
|
34
|
+
const DISCOVERY_MAX_WAIT_MS = 5000;
|
|
35
|
+
|
|
36
|
+
async function shedRetryWaitMs(r) {
|
|
37
|
+
if (!r || r.status !== 503) return null;
|
|
38
|
+
const header = r.headers && typeof r.headers.get === "function" ? r.headers.get("retry-after") : null;
|
|
39
|
+
let seconds = header != null && String(header).trim() !== "" ? Number(header) : NaN;
|
|
40
|
+
if (!Number.isFinite(seconds)) {
|
|
41
|
+
try {
|
|
42
|
+
const body = await (typeof r.clone === "function" ? r.clone() : r).json();
|
|
43
|
+
seconds = Number(body && body.retryAfterSeconds);
|
|
44
|
+
} catch { seconds = NaN; }
|
|
45
|
+
}
|
|
46
|
+
if (!Number.isFinite(seconds) || seconds < 0) return null;
|
|
47
|
+
return Math.min(seconds * 1000, DISCOVERY_MAX_WAIT_MS);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Resolves with the 2xx response, or throws `${label}: HTTP <status>` (plus
|
|
51
|
+
// "after N attempts" when it retried, and the server's `error` text) with
|
|
52
|
+
// `.status`, `.body` and `.attempts` set.
|
|
53
|
+
// `init` may be a function, so each attempt gets its own timeout signal.
|
|
54
|
+
async function discoveryFetch(fetchImpl, label, url, init) {
|
|
55
|
+
let r;
|
|
56
|
+
let attempts = 0;
|
|
57
|
+
for (;;) {
|
|
58
|
+
attempts++;
|
|
59
|
+
const i = (typeof init === "function" ? init() : init) || {};
|
|
60
|
+
r = await fetchImpl(url, { ...i, headers: { "User-Agent": USER_AGENT, ...(i.headers || {}) } });
|
|
61
|
+
if (r.ok) return r;
|
|
62
|
+
if (attempts >= DISCOVERY_ATTEMPTS) break;
|
|
63
|
+
const wait = await shedRetryWaitMs(r);
|
|
64
|
+
if (wait == null) break;
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
66
|
+
}
|
|
67
|
+
const err = await responseError(`${label}: HTTP ${r.status}${attempts > 1 ? ` after ${attempts} attempts` : ""}`, r);
|
|
68
|
+
err.attempts = attempts;
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The server's own answer to a failed request, on the thrown error: its
|
|
73
|
+
// `error` text joins the message, and `.status` and `.body` (the parsed JSON,
|
|
74
|
+
// else the text, at most ERROR_BODY_MAX characters) are set, so a caller sees
|
|
75
|
+
// why the call failed (a refusal, a limit, a missing parameter).
|
|
76
|
+
const ERROR_BODY_MAX = 4000;
|
|
77
|
+
async function responseError(message, r) {
|
|
78
|
+
let text = "";
|
|
79
|
+
try { text = typeof r?.text === "function" ? String(await r.text()) : ""; } catch { text = ""; }
|
|
80
|
+
text = text.slice(0, ERROR_BODY_MAX);
|
|
81
|
+
let body = null;
|
|
82
|
+
try { body = text ? JSON.parse(text) : null; } catch { body = null; }
|
|
83
|
+
const said = body && typeof body === "object" && typeof body.error === "string" ? body.error.slice(0, 500) : (!body ? text.trim().slice(0, 300) : "");
|
|
84
|
+
const err = new Error(said ? `${message}: ${said}` : message);
|
|
85
|
+
err.status = r?.status;
|
|
86
|
+
err.body = body ?? (text || null);
|
|
87
|
+
return err;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const sanitizeName = (s) => String(s).replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Fetch the Agent402 catalog and return:
|
|
94
|
+
* - `tools`: FunctionTool[] ready to pass to a LlamaIndex agent
|
|
95
|
+
* - `execute`: async (name, args) => result, pays under the hood
|
|
96
|
+
* - `client`: the underlying Agent402 client (use for find()/clearCache())
|
|
97
|
+
*/
|
|
98
|
+
export async function agent402Tools({ baseUrl = DEFAULT_BASE, slugs, freeOnly = true, fetch: payFetch, maxPerCallUsd, dailyLimitUsd, maxPerHostUsd, x402Client } = {}) {
|
|
99
|
+
const llama = await loadLlamaIndex();
|
|
100
|
+
const client = new Agent402({ userAgent: USER_AGENT, baseUrl, fetch: payFetch, ...capOptions({ maxPerCallUsd, dailyLimitUsd, maxPerHostUsd, x402Client }) });
|
|
101
|
+
// Bounded discovery fetch: caller picks baseUrl, so cap the wait. Node ≥18
|
|
102
|
+
// exposes AbortSignal.timeout() (declared in package.json engines).
|
|
103
|
+
const r = await discoveryFetch(globalThis.fetch, `Could not load ${baseUrl}/openapi.json`, `${baseUrl}/openapi.json`, () => ({ signal: AbortSignal.timeout(15000) }));
|
|
104
|
+
const spec = await r.json();
|
|
105
|
+
|
|
106
|
+
const wanted = slugs ? new Set(slugs) : null;
|
|
107
|
+
const meta = [];
|
|
108
|
+
|
|
109
|
+
for (const [, methods] of Object.entries(spec.paths || {})) {
|
|
110
|
+
for (const [method, op] of Object.entries(methods)) {
|
|
111
|
+
const slug = op.operationId?.replace(/Get$/, "");
|
|
112
|
+
if (!slug) continue;
|
|
113
|
+
if (wanted && !wanted.has(slug)) continue;
|
|
114
|
+
|
|
115
|
+
const schema = method.toLowerCase() === "get"
|
|
116
|
+
? {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: Object.fromEntries((op.parameters || []).map((p) => [p.name, { type: p.schema?.type || "string", description: p.description }])),
|
|
119
|
+
required: (op.parameters || []).filter((p) => p.required).map((p) => p.name),
|
|
120
|
+
}
|
|
121
|
+
: op.requestBody?.content?.["application/json"]?.schema || { type: "object", properties: {} };
|
|
122
|
+
if (schema && !schema.type) schema.type = "object";
|
|
123
|
+
|
|
124
|
+
meta.push({ name: sanitizeName(slug), slug, schema, description: shortDesc(op.summary, op.description) });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (freeOnly) {
|
|
129
|
+
const pr = await discoveryFetch(globalThis.fetch, `Could not load ${baseUrl}/api/pricing`, `${baseUrl}/api/pricing`, () => ({ signal: AbortSignal.timeout(15000) }));
|
|
130
|
+
const pricing = await pr.json();
|
|
131
|
+
const free = new Set((pricing.endpoints || []).filter((e) => e.computePayable).map((e) => e.slug));
|
|
132
|
+
for (let i = meta.length - 1; i >= 0; i--) if (!free.has(meta[i].slug)) meta.splice(i, 1);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// LlamaIndex's FunctionTool.from() accepts a raw JSON Schema in `parameters`.
|
|
136
|
+
// Use the modern `tool()` helper when available (newer llamaindex), falling
|
|
137
|
+
// back to FunctionTool.from() for older versions.
|
|
138
|
+
const make = typeof llama.tool === "function"
|
|
139
|
+
? (fn, metadata) => llama.tool(fn, metadata)
|
|
140
|
+
: (fn, metadata) => llama.FunctionTool.from(fn, metadata);
|
|
141
|
+
|
|
142
|
+
const tools = meta.map((m) => make(
|
|
143
|
+
async (input) => client.call(m.slug, input ?? {}),
|
|
144
|
+
{ name: m.name, description: m.description, parameters: m.schema },
|
|
145
|
+
));
|
|
146
|
+
|
|
147
|
+
return { client, tools, execute: makeExecute(client, meta) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function loadLlamaIndex() {
|
|
151
|
+
try {
|
|
152
|
+
return await import("llamaindex");
|
|
153
|
+
} catch {
|
|
154
|
+
throw new Error("agent402-function-tools requires the 'llamaindex' package. Install it with: npm install llamaindex");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function makeExecute(client, meta) {
|
|
159
|
+
const nameToSlug = new Map(meta.map((m) => [m.name, m.slug]));
|
|
160
|
+
return async function execute(name, args) {
|
|
161
|
+
const slug = nameToSlug.get(name) || name;
|
|
162
|
+
return client.call(slug, args ?? {});
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Standalone executor for users who built their tool list a different way.
|
|
168
|
+
* Returns an `execute(name, args)` that calls Agent402 with PoW or x402 payment.
|
|
169
|
+
*/
|
|
170
|
+
export function agent402Execute({ baseUrl = DEFAULT_BASE, fetch: payFetch, maxPerCallUsd, dailyLimitUsd, maxPerHostUsd, x402Client } = {}) {
|
|
171
|
+
const client = new Agent402({ userAgent: USER_AGENT, baseUrl, fetch: payFetch, ...capOptions({ maxPerCallUsd, dailyLimitUsd, maxPerHostUsd, x402Client }) });
|
|
172
|
+
return async function execute(name, args) {
|
|
173
|
+
return client.call(name, args ?? {});
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function shortDesc(summary, description) {
|
|
178
|
+
const d = (description || summary || "").split("\n\n")[0].trim();
|
|
179
|
+
return d.length > 280 ? d.slice(0, 277) + "..." : d;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export default agent402Tools;
|
|
183
|
+
|
|
184
|
+
/** The opt-in spending caps a caller passed, as agent402-client options.
|
|
185
|
+
* None are set by default: a caller who sets none is never refused a
|
|
186
|
+
* purchase. */
|
|
187
|
+
function capOptions({ maxPerCallUsd, dailyLimitUsd, maxPerHostUsd, x402Client } = {}) {
|
|
188
|
+
const out = {};
|
|
189
|
+
for (const [k, v] of Object.entries({ maxPerCallUsd, dailyLimitUsd, maxPerHostUsd })) if (v != null) out[k] = v;
|
|
190
|
+
if (x402Client) out.x402Client = x402Client;
|
|
191
|
+
return out;
|
|
192
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent402-function-tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Agent402 tools as FunctionTool instances, for use with LlamaIndex TS (Agentic Finance over x402 or MPP): turn tools from Agent402's catalog of 500+ pay-per-call tools and skill packs into function tools, one per catalog tool, with payment handled by agent402-client. Free via proof-of-work for the pure-CPU tools, or pay per call in USDC on 13 chains or USDG on Robinhood Chain. Formerly agent402-llamaindex.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node test.js"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"llamaindex",
|
|
27
|
+
"function-tool",
|
|
28
|
+
"tools",
|
|
29
|
+
"agents",
|
|
30
|
+
"react-agent",
|
|
31
|
+
"x402",
|
|
32
|
+
"ai-agents",
|
|
33
|
+
"agent-tools",
|
|
34
|
+
"llm-tools",
|
|
35
|
+
"usdc",
|
|
36
|
+
"base",
|
|
37
|
+
"proof-of-work",
|
|
38
|
+
"http-402",
|
|
39
|
+
"micropayments",
|
|
40
|
+
"agent402",
|
|
41
|
+
"tool-discovery",
|
|
42
|
+
"smart-order-router",
|
|
43
|
+
"mcp",
|
|
44
|
+
"agentic-commerce",
|
|
45
|
+
"agentic-finance",
|
|
46
|
+
"aifi",
|
|
47
|
+
"mpp",
|
|
48
|
+
"machine-payments-protocol",
|
|
49
|
+
"agentic-payments"
|
|
50
|
+
],
|
|
51
|
+
"author": "Cardhavok LLC (doing business as Havok Holdings LLC) <mike@agent402.tools> (https://github.com/MikeyPetrillo/Agent402)",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/MikeyPetrillo/Agent402.git",
|
|
56
|
+
"directory": "adapters/llamaindex"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://agent402.tools",
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"agent402-client": ">=0.8.21 <1.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"llamaindex": ">=0.12.0 <1"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"llamaindex": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|