@itzannetos/x402-tools 1.0.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.
@@ -0,0 +1,106 @@
1
+ import type { Plugin } from "@opencode-ai/plugin"
2
+ import { tool } from "@opencode-ai/plugin"
3
+ import axios from "axios"
4
+ import { withPaymentInterceptor } from "x402-axios"
5
+ import { config as loadEnv } from "dotenv"
6
+ import { createWalletClient, http } from "viem"
7
+ import { privateKeyToAccount } from "viem/accounts"
8
+ import { base } from "viem/chains"
9
+ import { readFile } from "fs/promises"
10
+ import { join } from "path"
11
+
12
+ const BASE_URL = "https://agents.402box.io"
13
+ const X_SEARCHER_PATH = "/x_searcher"
14
+ const FIND_PEOPLE_PATH = "/find_people"
15
+ const TIMEOUT_MS = 300000
16
+
17
+ const getPrivateKey = async (): Promise<`0x${string}`> => {
18
+ const configPath = join(process.cwd(), ".opencode", "x402-tools.json")
19
+ try {
20
+ const contents = await readFile(configPath, "utf-8")
21
+ const parsed = JSON.parse(contents) as { private_key?: string }
22
+ if (parsed.private_key) {
23
+ const key = parsed.private_key
24
+ return (key.startsWith("0x") ? key : `0x${key}`) as `0x${string}`
25
+ }
26
+ } catch (error) {
27
+ if (error instanceof Error && (error as NodeJS.ErrnoException).code !== "ENOENT") {
28
+ throw error
29
+ }
30
+ }
31
+
32
+ loadEnv({ path: join(process.cwd(), ".env") })
33
+ const key = process.env.X402_PRIVATE_KEY
34
+ if (!key) {
35
+ throw new Error(
36
+ "X402 private key missing. Set .opencode/x402-tools.json or X402_PRIVATE_KEY in .env."
37
+ )
38
+ }
39
+ return (key.startsWith("0x") ? key : `0x${key}`) as `0x${string}`
40
+ }
41
+
42
+ const createPaymentClient = (privateKey: `0x${string}`) => {
43
+ const account = privateKeyToAccount(privateKey)
44
+ const walletClient = createWalletClient({
45
+ account,
46
+ chain: base,
47
+ transport: http(),
48
+ })
49
+
50
+ return withPaymentInterceptor(
51
+ axios.create({
52
+ baseURL: BASE_URL,
53
+ timeout: TIMEOUT_MS,
54
+ }),
55
+ walletClient
56
+ )
57
+ }
58
+
59
+ export const X402ToolsPlugin: Plugin = async () => {
60
+ return {
61
+ tool: {
62
+ x_searcher: tool({
63
+ description:
64
+ "AI-powered X/Twitter search agent - Get real-time trends, news, and social media insights",
65
+ args: {
66
+ query: tool.schema.string(),
67
+ },
68
+ async execute(args) {
69
+ const privateKey = await getPrivateKey()
70
+ const client = createPaymentClient(privateKey)
71
+
72
+ const response = await client.post(X_SEARCHER_PATH, {
73
+ message: args.query,
74
+ })
75
+
76
+ if (!response.data?.data?.response) {
77
+ throw new Error("Unexpected response from X Searcher")
78
+ }
79
+
80
+ return response.data.data.response
81
+ },
82
+ }),
83
+ find_people: tool({
84
+ description:
85
+ "Find People is a real-time Open Source Intelligence (OSINT) agent specialized in researching individuals and professional entities.\n\n**What it does:**\n• Identifies people by name, role, or company affiliation\n• Retrieves verified career timelines and professional backgrounds\n• Finds similar professionals in any industry or domain\n• Synthesizes biographical information with source citations\n• Validates identities across LinkedIn, company sites, and public records\n\n**Best for:**\n→ Due diligence research on potential hires or partners\n→ Competitive intelligence on industry leaders\n→ Journalist & researcher background verification\n→ Sales prospecting and lead enrichment\n→ Investor research on startup founders and executives\n\n**Powered by:**\nNeural and deep search capabilities that go beyond standard search engines to find hard-to-reach biographical details, executive profiles, and professional networks.\n\n**Output format:**\nReturns structured summaries with key details (career, education, notable works) and numbered source citations for verification.",
86
+ args: {
87
+ query: tool.schema.string(),
88
+ },
89
+ async execute(args) {
90
+ const privateKey = await getPrivateKey()
91
+ const client = createPaymentClient(privateKey)
92
+
93
+ const response = await client.post(FIND_PEOPLE_PATH, {
94
+ message: args.query,
95
+ })
96
+
97
+ if (!response.data?.data?.response) {
98
+ throw new Error("Unexpected response from Find People")
99
+ }
100
+
101
+ return response.data.data.response
102
+ },
103
+ }),
104
+ },
105
+ }
106
+ }
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # x402-tools-plugin
2
+
3
+ Local OpenCode plugin that provides payment-gated tools via X402.
4
+
5
+ ## Tools
6
+
7
+ - `x_searcher` - AI-powered X/Twitter search agent for real-time trends and social insights.
8
+ - `find_people` - OSINT agent for researching individuals and professional entities.
9
+
10
+ ## Install from npm
11
+
12
+ 1. Add the plugin to `opencode.json`:
13
+
14
+ ```json
15
+ {
16
+ "$schema": "https://opencode.ai/config.json",
17
+ "plugin": ["@itzannetos/x402-tools"]
18
+ }
19
+ ```
20
+
21
+ 2. Create `.opencode/x402-tools.json` with your key:
22
+
23
+ ```json
24
+ {
25
+ "private_key": "0x..."
26
+ }
27
+ ```
28
+
29
+ 3. Or set it in `.env` at the project root:
30
+
31
+ ```
32
+ X402_PRIVATE_KEY=0x...
33
+ ```
34
+
35
+ 4. Restart OpenCode so the plugin is loaded.
36
+
37
+ ## Local Installation
38
+
39
+ 1. Ensure Bun is installed.
40
+ 2. Install dependencies for local plugins:
41
+
42
+ ```bash
43
+ cd /Users/itzannet/Documents/GitHub/x402-tools-plugin/.opencode
44
+ bun install
45
+ ```
46
+
47
+ 3. Create `.opencode/x402-tools.json` with your key:
48
+
49
+ ```json
50
+ {
51
+ "private_key": "0x..."
52
+ }
53
+ ```
54
+
55
+ 4. Or set it in `.env` at the project root:
56
+
57
+ ```
58
+ X402_PRIVATE_KEY=0x...
59
+ ```
60
+
61
+ 5. Restart OpenCode so the plugin is loaded.
62
+
63
+ ## Usage
64
+
65
+ In OpenCode, invoke the tools by name:
66
+
67
+ ```
68
+ Use the x_searcher tool to search for "AI breakthroughs in 2026".
69
+ ```
70
+
71
+ ```
72
+ Use the find_people tool to research "Jane Doe, head of AI at ExampleCorp".
73
+ ```
74
+
75
+ ## Local Plugin Location
76
+
77
+ The plugin is loaded automatically from:
78
+
79
+ ```
80
+ .opencode/plugins/x402-tools.ts
81
+ ```
82
+
83
+ ## Publishing and Updates
84
+
85
+ - Publish to npm and reference the package in `opencode.json` using a version range, for example: `"@itzannetos/x402-tools": "^1.0.0"`.
86
+ - OpenCode installs npm plugins at startup; with a semver range it will pick up compatible updates automatically.
87
+ - Pin an exact version if you want to control upgrades manually.
88
+
89
+ ## Notes
90
+
91
+ - The plugin reads `.opencode/x402-tools.json` first, then falls back to `X402_PRIVATE_KEY` in `.env`.
92
+ - Do not commit your key file; keep `.opencode/x402-tools.json` local.
93
+ - No account address or metadata is printed; only the markdown response is returned.
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { X402ToolsPlugin } from "./.opencode/plugins/x402-tools"
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@itzannetos/x402-tools",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.ts",
6
+ "files": [
7
+ "index.ts",
8
+ ".opencode/plugins/x402-tools.ts",
9
+ "README.md"
10
+ ],
11
+ "dependencies": {
12
+ "@opencode-ai/plugin": "^1.1.25",
13
+ "axios": "^1.7.9",
14
+ "dotenv": "^16.4.5",
15
+ "viem": "^2.21.26",
16
+ "x402-axios": "^1.1.0"
17
+ }
18
+ }