agentkit-cleanweb 0.0.0-stage → 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.
- package/README.md +118 -2
- package/dist/actions.d.ts +33 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +269 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/provider.d.ts +45 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +99 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/package.json +55 -4
- package/src/actions.ts +336 -0
- package/src/constants.ts +35 -0
- package/src/index.ts +12 -0
- package/src/provider.ts +149 -0
- package/src/types.ts +168 -0
package/src/provider.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CleanWebContentSchema,
|
|
3
|
+
CleanPdfSchema,
|
|
4
|
+
CleanYoutubeSchema,
|
|
5
|
+
OracleGroundingSchema,
|
|
6
|
+
ManageVaultSchema,
|
|
7
|
+
} from "./types.js";
|
|
8
|
+
import {
|
|
9
|
+
cleanWebContent,
|
|
10
|
+
cleanPdfResearch,
|
|
11
|
+
cleanYoutubeTranscript,
|
|
12
|
+
oracleGrounding,
|
|
13
|
+
manageX402Vault,
|
|
14
|
+
ActionInvocationOptions,
|
|
15
|
+
} from "./actions.js";
|
|
16
|
+
import { BASE_CHAIN_ID, BASE_SEPOLIA_CHAIN_ID } from "./constants.js";
|
|
17
|
+
|
|
18
|
+
export interface CleanWebActionProviderConfig {
|
|
19
|
+
gatewayUrl?: string;
|
|
20
|
+
vaultKey?: string;
|
|
21
|
+
agentNonce?: string;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AgentKitAction<TArgs = unknown, TResult = unknown> {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
schema: unknown;
|
|
29
|
+
invoke: (args: TArgs) => Promise<TResult>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NetworkLike {
|
|
33
|
+
chainId?: number | string;
|
|
34
|
+
networkId?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface WalletProviderLike {
|
|
38
|
+
getAddress?: () => Promise<string> | string;
|
|
39
|
+
getNetwork?: () => Promise<NetworkLike> | NetworkLike;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Coinbase AgentKit CleanWeb Action Provider
|
|
44
|
+
* Drop-in Action Provider supplying 87% token-compressed web scraping,
|
|
45
|
+
* research PDF analysis, YouTube Gemini Flash intelligence, and Base EIP-712 oracle attestations.
|
|
46
|
+
*/
|
|
47
|
+
export class CleanWebActionProvider {
|
|
48
|
+
public readonly name = "cleanweb";
|
|
49
|
+
public readonly description =
|
|
50
|
+
"87% token noise reduction web scraper, academic PDF analyzer, YouTube Gemini video intelligence, and Base Mainnet EIP-712 signed oracle grounding.";
|
|
51
|
+
|
|
52
|
+
private config: CleanWebActionProviderConfig;
|
|
53
|
+
|
|
54
|
+
constructor(config: CleanWebActionProviderConfig = {}) {
|
|
55
|
+
this.config = config;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Verifies if the provider supports the given network.
|
|
60
|
+
* Native support for Base (8453), Base Sepolia (84532), and all EVM chains.
|
|
61
|
+
*/
|
|
62
|
+
public supportsNetwork(network: NetworkLike): boolean {
|
|
63
|
+
if (!network || !network.chainId) return true;
|
|
64
|
+
const cid = Number(network.chainId);
|
|
65
|
+
return cid === BASE_CHAIN_ID || cid === BASE_SEPOLIA_CHAIN_ID || cid === 137 || cid === 42161;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns all 5 Action instances for Coinbase AgentKit runtime registration.
|
|
70
|
+
*/
|
|
71
|
+
public getActions(walletProvider?: WalletProviderLike): AgentKitAction[] {
|
|
72
|
+
const opts: ActionInvocationOptions = {
|
|
73
|
+
gatewayUrl: this.config.gatewayUrl,
|
|
74
|
+
vaultKey: this.config.vaultKey,
|
|
75
|
+
agentNonce: this.config.agentNonce,
|
|
76
|
+
timeoutMs: this.config.timeoutMs,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
name: "cleanweb_clean_web_content",
|
|
82
|
+
description:
|
|
83
|
+
"Scrapes any target webpage URL and compresses noise/ads into 87% token-reduced clean Markdown for LLMs.",
|
|
84
|
+
schema: CleanWebContentSchema,
|
|
85
|
+
invoke: async (args) => {
|
|
86
|
+
const parsed = CleanWebContentSchema.parse(args);
|
|
87
|
+
return await cleanWebContent(parsed, opts);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "cleanweb_clean_pdf_research",
|
|
92
|
+
description:
|
|
93
|
+
"Extracts structured academic text, executive findings, and sections from online PDF whitepapers and reports.",
|
|
94
|
+
schema: CleanPdfSchema,
|
|
95
|
+
invoke: async (args) => {
|
|
96
|
+
const parsed = CleanPdfSchema.parse(args);
|
|
97
|
+
return await cleanPdfResearch(parsed, opts);
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "cleanweb_clean_youtube_transcript",
|
|
102
|
+
description:
|
|
103
|
+
"Extracts high-precision subtitles and Google Gemini 3.8 Flash summary from YouTube videos without downloading media.",
|
|
104
|
+
schema: CleanYoutubeSchema,
|
|
105
|
+
invoke: async (args) => {
|
|
106
|
+
const parsed = CleanYoutubeSchema.parse(args);
|
|
107
|
+
return await cleanYoutubeTranscript(parsed, opts);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "cleanweb_oracle_grounding",
|
|
112
|
+
description:
|
|
113
|
+
"Discovers factual ground truth from the web and cryptographically signs an on-chain verifiable EIP-712 attestation for Base (8453).",
|
|
114
|
+
schema: OracleGroundingSchema,
|
|
115
|
+
invoke: async (args) => {
|
|
116
|
+
const parsed = OracleGroundingSchema.parse(args);
|
|
117
|
+
return await oracleGrounding(parsed, opts);
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "cleanweb_manage_x402_vault",
|
|
122
|
+
description:
|
|
123
|
+
"Checks prefunded agent USDC vault balance, retrieves Base USDC deposit address, or inspects VIP pass entitlements.",
|
|
124
|
+
schema: ManageVaultSchema,
|
|
125
|
+
invoke: async (args) => {
|
|
126
|
+
const parsed = ManageVaultSchema.parse(args);
|
|
127
|
+
let addr = parsed.agentAddress;
|
|
128
|
+
if (!addr && walletProvider && typeof walletProvider.getAddress === "function") {
|
|
129
|
+
try {
|
|
130
|
+
addr = await walletProvider.getAddress();
|
|
131
|
+
} catch {
|
|
132
|
+
// fallback
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return await manageX402Vault({ ...parsed, agentAddress: addr }, opts);
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Factory helper for clean instantiations
|
|
144
|
+
*/
|
|
145
|
+
export function cleanWebActionProvider(
|
|
146
|
+
config: CleanWebActionProviderConfig = {}
|
|
147
|
+
): CleanWebActionProvider {
|
|
148
|
+
return new CleanWebActionProvider(config);
|
|
149
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 1. Clean Web Content Schema
|
|
5
|
+
*/
|
|
6
|
+
export const CleanWebContentSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
url: z.string().url().describe("The HTTP/HTTPS webpage URL to scrape and compress into clean Markdown"),
|
|
9
|
+
maxLength: z
|
|
10
|
+
.number()
|
|
11
|
+
.int()
|
|
12
|
+
.positive()
|
|
13
|
+
.optional()
|
|
14
|
+
.default(50000)
|
|
15
|
+
.describe("Maximum character length for the returned markdown body (default 50,000)"),
|
|
16
|
+
includeLinks: z
|
|
17
|
+
.boolean()
|
|
18
|
+
.optional()
|
|
19
|
+
.default(true)
|
|
20
|
+
.describe("Whether to preserve relevant markdown links in the cleaned text"),
|
|
21
|
+
})
|
|
22
|
+
.strip()
|
|
23
|
+
.describe("Parameters for scraping and reducing webpage token noise by 87%");
|
|
24
|
+
|
|
25
|
+
export type CleanWebContentParams = z.infer<typeof CleanWebContentSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 2. Clean Research PDF Schema
|
|
29
|
+
*/
|
|
30
|
+
export const CleanPdfSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
pdfUrl: z.string().url().describe("The direct URL of the PDF whitepaper, financial filing, or arXiv research report"),
|
|
33
|
+
maxPages: z
|
|
34
|
+
.number()
|
|
35
|
+
.int()
|
|
36
|
+
.min(1)
|
|
37
|
+
.max(100)
|
|
38
|
+
.optional()
|
|
39
|
+
.default(50)
|
|
40
|
+
.describe("Maximum number of pages to parse (1-100, default 50)"),
|
|
41
|
+
})
|
|
42
|
+
.strip()
|
|
43
|
+
.describe("Parameters for extracting clean academic and financial text from online PDF whitepapers");
|
|
44
|
+
|
|
45
|
+
export type CleanPdfParams = z.infer<typeof CleanPdfSchema>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 3. Clean YouTube Transcript Schema
|
|
49
|
+
*/
|
|
50
|
+
export const CleanYoutubeSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
videoUrl: z.string().describe("YouTube video URL or 11-character video ID"),
|
|
53
|
+
includeSummary: z
|
|
54
|
+
.boolean()
|
|
55
|
+
.optional()
|
|
56
|
+
.default(true)
|
|
57
|
+
.describe("Whether to generate Gemini 3.8 Flash bullet-point executive summary"),
|
|
58
|
+
})
|
|
59
|
+
.strip()
|
|
60
|
+
.describe("Parameters for extracting timestamped subtitles and AI summaries from YouTube videos");
|
|
61
|
+
|
|
62
|
+
export type CleanYoutubeParams = z.infer<typeof CleanYoutubeSchema>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 4. Oracle Grounding & EIP-712 Attestation Schema
|
|
66
|
+
*/
|
|
67
|
+
export const OracleGroundingSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
query: z.string().min(3).describe("The factual proposition or topic to verify (e.g. 'Base TVL surpasses 4B' or 'CRMA compliance')"),
|
|
70
|
+
targetUrl: z
|
|
71
|
+
.string()
|
|
72
|
+
.url()
|
|
73
|
+
.optional()
|
|
74
|
+
.describe("Optional target webpage URL to ground the facts against"),
|
|
75
|
+
chainId: z
|
|
76
|
+
.number()
|
|
77
|
+
.int()
|
|
78
|
+
.optional()
|
|
79
|
+
.default(8453)
|
|
80
|
+
.describe("Target blockchain network ID for EIP-712 signature (Base Mainnet: 8453, Base Sepolia: 84532)"),
|
|
81
|
+
})
|
|
82
|
+
.strip()
|
|
83
|
+
.describe("Parameters for web ground-truth discovery with on-chain verifiable EIP-712 cryptographic attestation");
|
|
84
|
+
|
|
85
|
+
export type OracleGroundingParams = z.infer<typeof OracleGroundingSchema>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 5. Manage x402 Agent Vault Schema
|
|
89
|
+
*/
|
|
90
|
+
export const ManageVaultSchema = z
|
|
91
|
+
.object({
|
|
92
|
+
action: z
|
|
93
|
+
.enum(["balance", "deposit_info", "pass_status"])
|
|
94
|
+
.describe("Action to perform: 'balance' (check prefunded USDC balance), 'deposit_info' (get deposit address & chain parameters), or 'pass_status' (check agent VIP pass)"),
|
|
95
|
+
agentAddress: z
|
|
96
|
+
.string()
|
|
97
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Must be a valid EVM address (0x...)")
|
|
98
|
+
.optional()
|
|
99
|
+
.describe("The agent's EVM wallet address on Base Mainnet"),
|
|
100
|
+
})
|
|
101
|
+
.strip()
|
|
102
|
+
.describe("Parameters for managing gasless sub-millisecond x402 USDC micropayment session vaults");
|
|
103
|
+
|
|
104
|
+
export type ManageVaultParams = z.infer<typeof ManageVaultSchema>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* CleanWeb Universal Action Result Interfaces
|
|
108
|
+
*/
|
|
109
|
+
export interface CleanWebContentResult {
|
|
110
|
+
success: boolean;
|
|
111
|
+
url: string;
|
|
112
|
+
title: string;
|
|
113
|
+
cleanMarkdown: string;
|
|
114
|
+
tokenReductionRate: string;
|
|
115
|
+
sourceTokensEstimate: number;
|
|
116
|
+
compressedTokensEstimate: number;
|
|
117
|
+
latencyMs: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface CleanPdfResult {
|
|
121
|
+
success: boolean;
|
|
122
|
+
pdfUrl: string;
|
|
123
|
+
title: string;
|
|
124
|
+
pageCount: number;
|
|
125
|
+
wordCount: number;
|
|
126
|
+
text: string;
|
|
127
|
+
latencyMs: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface CleanYoutubeResult {
|
|
131
|
+
success: boolean;
|
|
132
|
+
videoId: string;
|
|
133
|
+
title: string;
|
|
134
|
+
channel: string;
|
|
135
|
+
summary?: string;
|
|
136
|
+
transcriptSample: string;
|
|
137
|
+
fullTranscriptLength: number;
|
|
138
|
+
latencyMs: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface OracleGroundingResult {
|
|
142
|
+
success: boolean;
|
|
143
|
+
query: string;
|
|
144
|
+
groundedFacts: string[];
|
|
145
|
+
summary: string;
|
|
146
|
+
verdict: "VERIFIED" | "CONTRADICTED" | "UNVERIFIED";
|
|
147
|
+
confidence: number;
|
|
148
|
+
attestation?: {
|
|
149
|
+
chainId: number;
|
|
150
|
+
signerAddress: string;
|
|
151
|
+
merkleRoot: string;
|
|
152
|
+
signature: string;
|
|
153
|
+
eip712Domain: Record<string, unknown>;
|
|
154
|
+
};
|
|
155
|
+
latencyMs: number;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface ManageVaultResult {
|
|
159
|
+
success: boolean;
|
|
160
|
+
action: string;
|
|
161
|
+
agentAddress?: string;
|
|
162
|
+
balanceUsdc?: number;
|
|
163
|
+
totalConsumedUsdc?: number;
|
|
164
|
+
depositAddress?: string;
|
|
165
|
+
supportedChains?: string[];
|
|
166
|
+
passTier?: string;
|
|
167
|
+
passActive?: boolean;
|
|
168
|
+
}
|