@xyz17711/proxy-pool 0.0.0-stage → 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 +86 -2
- package/dist/index.d.ts +37 -0
- package/dist/index.js +11 -0
- package/dist/langchain.d.ts +25 -0
- package/dist/langchain.js +19 -0
- package/package.json +40 -4
- package/src/index.ts +39 -0
- package/src/langchain.ts +28 -0
- package/test/index.test.mjs +24 -0
- package/test/langchain.test.mjs +16 -0
- package/tsconfig.json +16 -0
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xyz17711/proxy-pool
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/17711-services/clients/actions/workflows/publish-node.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@xyz17711/proxy-pool)
|
|
5
|
+
[](https://github.com/17711-services/clients/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Typed TypeScript client for **proxy-pool**, part of the
|
|
8
|
+
[17711.xyz](https://api.17711.xyz) microservice fleet -- pay-per-call APIs settled in USDC via
|
|
9
|
+
[x402](https://x402.org), listed on [x402scan](https://www.x402scan.com/server/f1c7b972-3405-4b75-8b4f-d1bfbd6305ff).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @xyz17711/proxy-pool
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Methods
|
|
18
|
+
|
|
19
|
+
| Method | Description |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `getBestProxy` | Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402) |
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Client } from "@xyz17711/proxy-pool";
|
|
27
|
+
|
|
28
|
+
const client = new Client("https://api.17711.xyz/registry/proxy-pool");
|
|
29
|
+
// see the Methods table above for every available call and its request/response type
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Paying past the free quota
|
|
33
|
+
|
|
34
|
+
Every gated tool allows a small number of free calls per day; beyond that it returns a 402
|
|
35
|
+
challenge. Without a wallet configured, this client throws `PaymentRequiredError` with the price,
|
|
36
|
+
network, and payee address attached:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { Client, PaymentRequiredError } from "@xyz17711/proxy-pool";
|
|
40
|
+
|
|
41
|
+
const client = new Client("https://api.17711.xyz/registry/proxy-pool");
|
|
42
|
+
try {
|
|
43
|
+
await client.getBestProxy(/* ... */);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (e instanceof PaymentRequiredError) {
|
|
46
|
+
console.log(`needs ${e.priceUsdc} USDC on ${e.network}, payable to ${e.payTo}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To pay automatically, configure a wallet on the client -- the private key should come from your
|
|
52
|
+
own environment/secrets manager, never a literal string in source code:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { Client } from "@xyz17711/proxy-pool";
|
|
56
|
+
|
|
57
|
+
const client = new Client("https://api.17711.xyz/registry/proxy-pool", {
|
|
58
|
+
x402PrivateKey: process.env.X402_PRIVATE_KEY,
|
|
59
|
+
x402ExpectedNetwork: "eip155:8453", // Base mainnet; use eip155:84532 for Base Sepolia testnet
|
|
60
|
+
x402MaxPaymentUsdc: 0.01, // refuse any single call above this
|
|
61
|
+
x402MaxTotalSpendUsdc: 1.0, // refuse once this WALLET's lifetime spend would exceed it
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Never commit a private key.** Both spend caps are required together with the key -- a wallet
|
|
66
|
+
with real funds and no explicit caps refuses to construct at all (`WalletConfigError`), on
|
|
67
|
+
purpose. The cumulative cap is tracked per wallet address, shared by every `Client` you construct
|
|
68
|
+
with that same key in this process.
|
|
69
|
+
|
|
70
|
+
## LangChain.js
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { Client } from "@xyz17711/proxy-pool";
|
|
74
|
+
import { ProxyPoolToolkit } from "@xyz17711/proxy-pool/langchain";
|
|
75
|
+
|
|
76
|
+
const client = new Client("https://api.17711.xyz/registry/proxy-pool", { /* ...wallet options... */ });
|
|
77
|
+
const tools = new ProxyPoolToolkit(client).getTools();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Requires the optional `@langchain/core`+`zod` peer dependencies (`npm install @langchain/core
|
|
81
|
+
zod`) -- importing the base package above never requires them; only `@xyz17711/proxy-pool/langchain`
|
|
82
|
+
does.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT -- see [`LICENSE`](../../LICENSE), shared by every language's client library in the
|
|
87
|
+
`clients` repo this package lives in.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTP client and request/response interfaces for proxy-pool.
|
|
3
|
+
*/
|
|
4
|
+
import { Client as BaseClient, type ClientOptions } from "@xyz17711/core";
|
|
5
|
+
/** A `SourceProxy` joined with its `CheckedProxy` result, if it has been checked at least once -- what every read tool actually filters/returns. */
|
|
6
|
+
export interface ProxyView {
|
|
7
|
+
anonymity: string;
|
|
8
|
+
/** `None` if this service has never checked this proxy yet. */
|
|
9
|
+
checked_alive?: boolean | null;
|
|
10
|
+
checked_at?: number | null;
|
|
11
|
+
/** See `CheckedProxy::consecutive_successes`'s own doc comment. `0` if never checked. */
|
|
12
|
+
checked_consecutive_successes: number;
|
|
13
|
+
/** See `CheckedProxy::ema_latency_ms`'s own doc comment. */
|
|
14
|
+
checked_ema_latency_ms?: number | null;
|
|
15
|
+
checked_latency_ms?: number | null;
|
|
16
|
+
checked_protocol?: string | null;
|
|
17
|
+
city: string;
|
|
18
|
+
country: string;
|
|
19
|
+
id: string;
|
|
20
|
+
ip: string;
|
|
21
|
+
port: number;
|
|
22
|
+
protocols: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface GetBestProxyResponse {
|
|
25
|
+
proxy: ProxyView;
|
|
26
|
+
}
|
|
27
|
+
/** Typed client for proxy-pool, e.g. `client.getBestProxy(...)`. */
|
|
28
|
+
export declare class Client extends BaseClient {
|
|
29
|
+
/** Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402) */
|
|
30
|
+
getBestProxy(params: {
|
|
31
|
+
anonymity?: string | null;
|
|
32
|
+
city?: string | null;
|
|
33
|
+
country?: string | null;
|
|
34
|
+
protocol?: string | null;
|
|
35
|
+
}): Promise<GetBestProxyResponse>;
|
|
36
|
+
}
|
|
37
|
+
export { ClientOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTP client and request/response interfaces for proxy-pool.
|
|
3
|
+
*/
|
|
4
|
+
import { Client as BaseClient } from "@xyz17711/core";
|
|
5
|
+
/** Typed client for proxy-pool, e.g. `client.getBestProxy(...)`. */
|
|
6
|
+
export class Client extends BaseClient {
|
|
7
|
+
/** Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402) */
|
|
8
|
+
async getBestProxy(params) {
|
|
9
|
+
return this.get("/v1/proxy-pool/get_best_proxy", { anonymity: params.anonymity, city: params.city, country: params.country, protocol: params.protocol });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js tools for proxy-pool, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `proxy-pool/langchain`, never from the package root, so importing the base client never requires them installed.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { Client } from "./index.js";
|
|
6
|
+
export declare class ProxyPoolToolkit {
|
|
7
|
+
private client;
|
|
8
|
+
constructor(client: Client);
|
|
9
|
+
getTools(): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
|
|
10
|
+
anonymity: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
11
|
+
city: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
country: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
protocol: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
+
}, z.core.$strip>, {
|
|
15
|
+
anonymity?: string | null | undefined;
|
|
16
|
+
city?: string | null | undefined;
|
|
17
|
+
country?: string | null | undefined;
|
|
18
|
+
protocol?: string | null | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
anonymity?: string | null | undefined;
|
|
21
|
+
city?: string | null | undefined;
|
|
22
|
+
country?: string | null | undefined;
|
|
23
|
+
protocol?: string | null | undefined;
|
|
24
|
+
}, import("./index.js").GetBestProxyResponse, unknown, "getBestProxy">[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js tools for proxy-pool, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `proxy-pool/langchain`, never from the package root, so importing the base client never requires them installed.
|
|
3
|
+
*/
|
|
4
|
+
import { tool } from "@langchain/core/tools";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export class ProxyPoolToolkit {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
getTools() {
|
|
11
|
+
return [
|
|
12
|
+
tool(async (input) => this.client.getBestProxy(input), {
|
|
13
|
+
name: "getBestProxy",
|
|
14
|
+
description: "Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402)",
|
|
15
|
+
schema: z.object({ anonymity: z.string().nullable().optional(), city: z.string().nullable().optional(), country: z.string().nullable().optional(), protocol: z.string().nullable().optional() }),
|
|
16
|
+
}),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyz17711/proxy-pool",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generated typed client for the proxy-pool 17711.xyz microservice.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./langchain": {
|
|
14
|
+
"types": "./dist/langchain.d.ts",
|
|
15
|
+
"default": "./dist/langchain.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p .",
|
|
20
|
+
"test": "npm run build && node --test test/*.test.mjs"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@xyz17711/core": "^0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@langchain/core": ">=0.3",
|
|
27
|
+
"zod": "^3 || ^4"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"@langchain/core": {
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
"zod": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5",
|
|
39
|
+
"@langchain/core": "^1.2",
|
|
40
|
+
"zod": "^4"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTP client and request/response interfaces for proxy-pool.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Client as BaseClient, type ClientOptions } from "@xyz17711/core";
|
|
6
|
+
|
|
7
|
+
/** A `SourceProxy` joined with its `CheckedProxy` result, if it has been checked at least once -- what every read tool actually filters/returns. */
|
|
8
|
+
export interface ProxyView {
|
|
9
|
+
anonymity: string;
|
|
10
|
+
/** `None` if this service has never checked this proxy yet. */
|
|
11
|
+
checked_alive?: boolean | null;
|
|
12
|
+
checked_at?: number | null;
|
|
13
|
+
/** See `CheckedProxy::consecutive_successes`'s own doc comment. `0` if never checked. */
|
|
14
|
+
checked_consecutive_successes: number;
|
|
15
|
+
/** See `CheckedProxy::ema_latency_ms`'s own doc comment. */
|
|
16
|
+
checked_ema_latency_ms?: number | null;
|
|
17
|
+
checked_latency_ms?: number | null;
|
|
18
|
+
checked_protocol?: string | null;
|
|
19
|
+
city: string;
|
|
20
|
+
country: string;
|
|
21
|
+
id: string;
|
|
22
|
+
ip: string;
|
|
23
|
+
port: number;
|
|
24
|
+
protocols: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GetBestProxyResponse {
|
|
28
|
+
proxy: ProxyView;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Typed client for proxy-pool, e.g. `client.getBestProxy(...)`. */
|
|
32
|
+
export class Client extends BaseClient {
|
|
33
|
+
/** Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402) */
|
|
34
|
+
async getBestProxy(params: { anonymity?: string | null; city?: string | null; country?: string | null; protocol?: string | null }): Promise<GetBestProxyResponse> {
|
|
35
|
+
return this.get<GetBestProxyResponse>("/v1/proxy-pool/get_best_proxy", { anonymity: params.anonymity, city: params.city, country: params.country, protocol: params.protocol });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { ClientOptions };
|
package/src/langchain.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain.js tools for proxy-pool, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `proxy-pool/langchain`, never from the package root, so importing the base client never requires them installed.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { tool } from "@langchain/core/tools";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { Client } from "./index.js";
|
|
8
|
+
|
|
9
|
+
export class ProxyPoolToolkit {
|
|
10
|
+
private client: Client;
|
|
11
|
+
|
|
12
|
+
constructor(client: Client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getTools() {
|
|
17
|
+
return [
|
|
18
|
+
tool(
|
|
19
|
+
async (input) => this.client.getBestProxy(input),
|
|
20
|
+
{
|
|
21
|
+
name: "getBestProxy",
|
|
22
|
+
description: "Returns one of the fastest verified-alive proxies matching the filter, randomized to spread load ($0.001, x402)",
|
|
23
|
+
schema: z.object({ anonymity: z.string().nullable().optional(), city: z.string().nullable().optional(), country: z.string().nullable().optional(), protocol: z.string().nullable().optional() }),
|
|
24
|
+
},
|
|
25
|
+
),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies every proxy-pool client method sends a request to the expected path/HTTP verb and parses a well-formed response -- one test per operation, real fetch mocked via a plain reassignment of `globalThis.fetch` (no extra test/mocking dependency). Runs against the COMPILED package (`../dist/index.js`) -- build before testing.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { Client } from "../dist/index.js";
|
|
8
|
+
|
|
9
|
+
test("getBestProxy calls the expected path", async () => {
|
|
10
|
+
const originalFetch = globalThis.fetch;
|
|
11
|
+
globalThis.fetch = async (url, init = {}) => {
|
|
12
|
+
const parsed = new URL(url);
|
|
13
|
+
assert.equal((init.method ?? "GET").toUpperCase(), "GET");
|
|
14
|
+
assert.equal(parsed.pathname, "/v1/proxy-pool/get_best_proxy");
|
|
15
|
+
return new Response(JSON.stringify({ proxy: { anonymity: "test", checked_alive: null, checked_at: null, checked_consecutive_successes: 0, checked_ema_latency_ms: null, checked_latency_ms: null, checked_protocol: null, city: "test", country: "test", id: "test", ip: "test", port: 0, protocols: [] } }), { status: 200 });
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
const client = new Client("https://example.test");
|
|
19
|
+
const result = await client.getBestProxy({ anonymity: null, city: null, country: null, protocol: null });
|
|
20
|
+
assert.ok(result !== undefined);
|
|
21
|
+
} finally {
|
|
22
|
+
globalThis.fetch = originalFetch;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies every proxy-pool LangChain tool through the real StructuredTool (`.invoke()`), not just the underlying client method -- catches schema-shape bugs a plain client-method test would miss. Requires the `langchain`/`zod` dev dependencies.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { Client } from "../dist/index.js";
|
|
8
|
+
import { ProxyPoolToolkit } from "../dist/langchain.js";
|
|
9
|
+
|
|
10
|
+
test("getBestProxy tool invoke", async () => {
|
|
11
|
+
globalThis.fetch = async () => new Response(JSON.stringify({ proxy: { anonymity: "test", checked_alive: null, checked_at: null, checked_consecutive_successes: 0, checked_ema_latency_ms: null, checked_latency_ms: null, checked_protocol: null, city: "test", country: "test", id: "test", ip: "test", port: 0, protocols: [] } }), { status: 200 });
|
|
12
|
+
const toolkit = new ProxyPoolToolkit(new Client("https://example.test"));
|
|
13
|
+
const t = toolkit.getTools().find((x) => x.name === "getBestProxy");
|
|
14
|
+
const result = await t.invoke({ anonymity: "test", city: "test", country: "test", protocol: "test" });
|
|
15
|
+
assert.ok(result !== undefined);
|
|
16
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src"
|
|
15
|
+
]
|
|
16
|
+
}
|