agentsvc 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 agentsvc.io
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,49 @@
1
- # Temporary Holding Version
1
+ # agentsvc (JavaScript)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Pay-per-call tools for AI agents from [agentsvc.io](https://agentsvc.io): 120+ web, data and crypto APIs (web scraping to Markdown, token safety checks, smart-money tracking, agent memory and inbox, PDF and OCR, company data, and more), paid per call in USDC via [x402](https://x402.org). No account, no subscription. Ready-made tools for the **Vercel AI SDK** and **LangChain.js**.
4
+
5
+ ```bash
6
+ npm i agentsvc
7
+ npm i @x402/fetch @x402/evm viem # only if your agent pays from its own wallet
8
+ ```
9
+
10
+ ## Pay
11
+
12
+ - **Credit token:** buy one at https://agentsvc.io/credits (from $0.10, +10% bonus), then `createAgentsvc({ creditToken: 'asvc_cr_...' })` or set `AGENTSVC_CREDIT_TOKEN`.
13
+ - **Wallet:** `createAgentsvc({ privateKey: '0x...', network: 'eip155:8453' })` with a few dollars of USDC on Base, Polygon (`eip155:137`) or Arbitrum (`eip155:42161`). Use a separate low-balance wallet.
14
+ - **Your own x402 fetch:** `createAgentsvc({ payFetch })`.
15
+ - Neither: `client.sample('web-scrape')` runs the free example of any service.
16
+
17
+ ```js
18
+ import { createAgentsvc } from 'agentsvc';
19
+
20
+ const svc = createAgentsvc({ creditToken: process.env.AGENTSVC_CREDIT_TOKEN });
21
+ const page = await svc.call('web-scrape', { url: 'https://example.com' });
22
+ const check = await svc.call('token-precheck', { tokens: ['0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'], chain: 'base' });
23
+ ```
24
+
25
+ ## Vercel AI SDK
26
+
27
+ ```js
28
+ import { generateText, isStepCount } from 'ai';
29
+ import { createAgentsvc } from 'agentsvc';
30
+ import { agentsvcTools } from 'agentsvc/ai-sdk';
31
+
32
+ const tools = await agentsvcTools(createAgentsvc({ creditToken: process.env.AGENTSVC_CREDIT_TOKEN }), ['web-scrape', 'news-search', 'token-smart-money']);
33
+ // Full guide: https://agentsvc.io/docs/ai-sdk
34
+ const { text } = await generateText({ model: 'anthropic/claude-haiku-5.5', tools, stopWhen: isStepCount(5), prompt: 'Who is buying BRETT on Base right now?' });
35
+ ```
36
+
37
+ ## LangChain.js
38
+
39
+ ```js
40
+ import { createAgentsvc } from 'agentsvc';
41
+ import { agentsvcLangChainTools } from 'agentsvc/langchain';
42
+
43
+ const tools = await agentsvcLangChainTools(createAgentsvc({ creditToken: process.env.AGENTSVC_CREDIT_TOKEN }), { category: 'web' });
44
+ // createReactAgent({ llm, tools }) or llm.bindTools(tools)
45
+ ```
46
+
47
+ Pick services by slug list, `{ category: 'finance' }` or a filter function. The full list with prices: https://agentsvc.io/api/v1/services. Failed calls are never charged; errors throw `AgentsvcError` with `status` and `body`.
48
+
49
+ MIT licensed. The service itself runs at agentsvc.io and is not open source.
package/ai-sdk.mjs ADDED
@@ -0,0 +1,16 @@
1
+ // Vercel AI SDK tools: const tools = await agentsvcTools(client, ['web-scrape', 'token-precheck'])
2
+ // then generateText({ model, tools, prompt, stopWhen: stepCountIs(5) }).
3
+ import { tool, jsonSchema } from 'ai';
4
+ import { selectServices, toolName, toolDescription, toolSchema } from './index.mjs';
5
+
6
+ export async function agentsvcTools(client, pick) {
7
+ const out = {};
8
+ for (const s of await selectServices(client, pick)) {
9
+ const def = { description: toolDescription(s), execute: input => client.call(s.slug, input) };
10
+ // AI SDK 5 heisst das Feld inputSchema, AI SDK 4 parameters
11
+ def.inputSchema = jsonSchema(toolSchema(s));
12
+ def.parameters = def.inputSchema;
13
+ out[toolName(s.slug)] = tool(def);
14
+ }
15
+ return out;
16
+ }
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export interface AgentsvcOptions { privateKey?: string; network?: string; payFetch?: typeof fetch; creditToken?: string; baseUrl?: string }
2
+ export interface Service { slug: string; name: string; description: string; category: string; price_usdc: number; input_schema: Record<string, unknown>; output_schema?: Record<string, unknown>; example_input?: Record<string, unknown>; is_active?: boolean; tags: string[] }
3
+ export interface AgentsvcClient {
4
+ call<T = unknown>(slug: string, input?: Record<string, unknown>): Promise<T>;
5
+ sample<T = unknown>(slug: string): Promise<T>;
6
+ services(): Promise<Service[]>;
7
+ baseUrl: string;
8
+ }
9
+ export class AgentsvcError extends Error { status?: number; body?: unknown }
10
+ export function createAgentsvc(opts?: AgentsvcOptions): AgentsvcClient;
11
+ export type ServicePick = string[] | { category: string } | ((s: Service) => boolean);
12
+ export function selectServices(client: AgentsvcClient, pick?: ServicePick): Promise<Service[]>;
13
+ export function toolName(slug: string): string;
14
+ export function toolDescription(s: Service): string;
15
+ export function toolSchema(s: Service): Record<string, unknown>;
package/index.mjs ADDED
@@ -0,0 +1,102 @@
1
+ // agentsvc: client for https://agentsvc.io. Every service is one HTTP endpoint, paid per call:
2
+ // - with x402 from a wallet (pass privateKey, or your own x402-enabled fetch as payFetch), or
3
+ // - with a prepaid credit token from https://agentsvc.io/credits (pass creditToken).
4
+ // Without either, only the free samples work (each service's example input).
5
+
6
+ const DEFAULT_BASE = 'https://agentsvc.io';
7
+
8
+ export class AgentsvcError extends Error {
9
+ constructor(message, { status, body } = {}) { super(message); this.name = 'AgentsvcError'; this.status = status; this.body = body; }
10
+ }
11
+
12
+ async function walletFetch(privateKey, network) {
13
+ let mods;
14
+ try {
15
+ mods = await Promise.all([import('@x402/fetch'), import('@x402/evm/exact/client'), import('viem/accounts')]);
16
+ } catch {
17
+ throw new AgentsvcError('Paying from a wallet needs the x402 packages: npm i @x402/fetch @x402/evm viem');
18
+ }
19
+ const [{ wrapFetchWithPayment, x402Client }, { registerExactEvmScheme }, { privateKeyToAccount }] = mods;
20
+ const pick = network ? (_v, accepts) => accepts.find(a => a.network === network) || accepts[0] : undefined;
21
+ const client = new x402Client(pick);
22
+ registerExactEvmScheme(client, { signer: privateKeyToAccount(privateKey) });
23
+ return wrapFetchWithPayment(fetch, client);
24
+ }
25
+
26
+ /**
27
+ * @param {object} [opts]
28
+ * @param {string} [opts.privateKey] EVM key of a wallet with a few dollars of USDC (Base, Polygon or Arbitrum). Use a separate low-balance wallet.
29
+ * @param {string} [opts.network] Preferred payment network, e.g. "eip155:8453" (Base, default), "eip155:137" (Polygon)
30
+ * @param {Function} [opts.payFetch] Your own fetch that handles x402 (instead of privateKey)
31
+ * @param {string} [opts.creditToken] Prepaid credit token (asvc_cr_...) from https://agentsvc.io/credits
32
+ * @param {string} [opts.baseUrl]
33
+ */
34
+ export function createAgentsvc(opts = {}) {
35
+ const base = (opts.baseUrl || DEFAULT_BASE).replace(/\/$/, '');
36
+ const credit = opts.creditToken || (typeof process !== 'undefined' ? process.env.AGENTSVC_CREDIT_TOKEN : undefined);
37
+ let fetcher = opts.payFetch || null;
38
+ let catalog = null;
39
+
40
+ async function getFetch() {
41
+ if (fetcher) return fetcher;
42
+ if (credit) return (fetcher = fetch);
43
+ if (opts.privateKey) return (fetcher = await walletFetch(opts.privateKey, opts.network));
44
+ return fetch;
45
+ }
46
+
47
+ async function services() {
48
+ if (!catalog) {
49
+ const r = await fetch(`${base}/api/v1/services`);
50
+ if (!r.ok) throw new AgentsvcError(`catalog HTTP ${r.status}`, { status: r.status });
51
+ const j = await r.json();
52
+ catalog = j.data || j.services || j;
53
+ }
54
+ return catalog;
55
+ }
56
+
57
+ /** Call one service. Returns its data; throws AgentsvcError on 402 (no payment), input errors and service errors (none of them are charged). */
58
+ async function call(slug, input = {}) {
59
+ const f = await getFetch();
60
+ const headers = { 'Content-Type': 'application/json', 'User-Agent': 'agentsvc-js/0.1.1' };
61
+ if (credit) headers.Authorization = `Bearer ${credit}`;
62
+ const paid = credit || opts.privateKey || opts.payFetch;
63
+ const url = paid ? `${base}/api/v1/proxy/${slug}` : `${base}/api/v1/try/${slug}`;
64
+ const r = await f(url, { method: 'POST', headers, body: JSON.stringify(input) });
65
+ const j = await r.json().catch(() => ({}));
66
+ if (r.status === 402) throw new AgentsvcError(j.hint || `Payment required for ${slug}: pass privateKey, payFetch or creditToken`, { status: 402, body: j });
67
+ if (!r.ok || j.success === false) throw new AgentsvcError(j.message || j.error || `HTTP ${r.status}`, { status: r.status, body: j });
68
+ return j.data ?? j;
69
+ }
70
+
71
+ /** Free sample of a service with its example input (no payment). */
72
+ async function sample(slug) {
73
+ const r = await fetch(`${base}/api/v1/try/${slug}`);
74
+ const j = await r.json().catch(() => ({}));
75
+ if (!r.ok) throw new AgentsvcError(j.message || `HTTP ${r.status}`, { status: r.status, body: j });
76
+ return j.data ?? j;
77
+ }
78
+
79
+ return { call, sample, services, baseUrl: base };
80
+ }
81
+
82
+ /** Pick catalog entries by slug list, category or a filter function. */
83
+ export async function selectServices(client, pick) {
84
+ const all = (await client.services()).filter(s => s.is_active !== false);
85
+ if (!pick) return all;
86
+ if (Array.isArray(pick)) {
87
+ const set = new Set(pick);
88
+ const found = all.filter(s => set.has(s.slug));
89
+ const missing = pick.filter(p => !found.some(s => s.slug === p));
90
+ if (missing.length) throw new AgentsvcError(`unknown services: ${missing.join(', ')}`);
91
+ return found;
92
+ }
93
+ if (typeof pick === 'function') return all.filter(pick);
94
+ if (pick.category) return all.filter(s => s.category === pick.category);
95
+ return all;
96
+ }
97
+
98
+ export const toolName = slug => slug.replace(/-/g, '_');
99
+ export const toolDescription = s => `${s.description} Costs $${s.price_usdc} per call.`;
100
+ export function toolSchema(s) {
101
+ return { ...(s.input_schema || {}), type: 'object' };
102
+ }
package/langchain.mjs ADDED
@@ -0,0 +1,13 @@
1
+ // LangChain.js tools: const tools = await agentsvcLangChainTools(client, ['web-scrape', 'news-search'])
2
+ // then createReactAgent({ llm, tools }) or llm.bindTools(tools).
3
+ import { DynamicStructuredTool } from '@langchain/core/tools';
4
+ import { selectServices, toolName, toolDescription, toolSchema } from './index.mjs';
5
+
6
+ export async function agentsvcLangChainTools(client, pick) {
7
+ return (await selectServices(client, pick)).map(s => new DynamicStructuredTool({
8
+ name: toolName(s.slug),
9
+ description: toolDescription(s),
10
+ schema: toolSchema(s),
11
+ func: async input => JSON.stringify(await client.call(s.slug, input)),
12
+ }));
13
+ }
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "agentsvc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Pay-per-call tools for AI agents: 120+ web, data and crypto APIs paid in USDC via x402, with ready-made tools for the Vercel AI SDK and LangChain.js",
5
+ "type": "module",
6
+ "main": "./index.mjs",
7
+ "exports": {
8
+ ".": "./index.mjs",
9
+ "./ai-sdk": "./ai-sdk.mjs",
10
+ "./langchain": "./langchain.mjs"
11
+ },
12
+ "files": ["index.mjs", "ai-sdk.mjs", "langchain.mjs", "index.d.ts", "README.md"],
13
+ "types": "./index.d.ts",
14
+ "keywords": ["x402", "ai-agents", "mcp", "vercel-ai-sdk", "langchain", "tools", "web-scraping", "crypto", "usdc", "pay-per-call"],
15
+ "homepage": "https://agentsvc.io",
16
+ "repository": { "type": "git", "url": "git+https://github.com/agentsvc/agentsvc.git", "directory": "packages/js" },
17
+ "bugs": "https://github.com/agentsvc/agentsvc/issues",
18
+ "license": "MIT",
19
+ "engines": { "node": ">=18" },
20
+ "peerDependencies": {
21
+ "@x402/fetch": ">=2.0.0",
22
+ "@x402/evm": ">=2.0.0",
23
+ "viem": ">=2.0.0",
24
+ "ai": ">=4.0.0",
25
+ "@langchain/core": ">=0.3.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "@x402/fetch": { "optional": true },
29
+ "@x402/evm": { "optional": true },
30
+ "viem": { "optional": true },
31
+ "ai": { "optional": true },
32
+ "@langchain/core": { "optional": true }
33
+ }
34
+ }