agentkit-cleanweb 0.0.0-stage → 1.0.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/src/actions.ts ADDED
@@ -0,0 +1,336 @@
1
+ import {
2
+ DEFAULT_GATEWAY_URL,
3
+ FALLBACK_GATEWAY_URL,
4
+ DEFAULT_TIMEOUT_MS,
5
+ BASE_CHAIN_ID,
6
+ BASE_USDC_ADDRESS,
7
+ BASE_ESCROW_CORE,
8
+ } from "./constants.js";
9
+ import {
10
+ CleanWebContentParams,
11
+ CleanWebContentResult,
12
+ CleanPdfParams,
13
+ CleanPdfResult,
14
+ CleanYoutubeParams,
15
+ CleanYoutubeResult,
16
+ OracleGroundingParams,
17
+ OracleGroundingResult,
18
+ ManageVaultParams,
19
+ ManageVaultResult,
20
+ } from "./types.js";
21
+
22
+ export interface ActionInvocationOptions {
23
+ gatewayUrl?: string;
24
+ vaultKey?: string;
25
+ agentNonce?: string;
26
+ timeoutMs?: number;
27
+ }
28
+
29
+ /**
30
+ * Internal helper to dispatch HTTP request with automatic dual-gateway failover
31
+ */
32
+ async function fetchWithFailover(
33
+ path: string,
34
+ options: RequestInit & { timeoutMs?: number; gatewayUrl?: string }
35
+ ): Promise<Response> {
36
+ const primaryBase = options.gatewayUrl || DEFAULT_GATEWAY_URL;
37
+ const timeoutMs = options.timeoutMs || DEFAULT_TIMEOUT_MS;
38
+
39
+ const tryEndpoints = [
40
+ `${primaryBase.replace(/\/$/, "")}${path}`,
41
+ `${FALLBACK_GATEWAY_URL.replace(/\/$/, "")}${path}`,
42
+ ];
43
+
44
+ let lastError: unknown;
45
+ for (const url of tryEndpoints) {
46
+ try {
47
+ const controller = new AbortController();
48
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
49
+
50
+ const response = await fetch(url, {
51
+ ...options,
52
+ signal: controller.signal,
53
+ });
54
+ clearTimeout(timer);
55
+
56
+ if (response.ok) {
57
+ return response;
58
+ }
59
+
60
+ // If server responded with 402 or 4xx/5xx, try next if 502/503/504
61
+ if (response.status >= 500) {
62
+ lastError = new Error(`Server returned status ${response.status} from ${url}`);
63
+ continue;
64
+ }
65
+ return response;
66
+ } catch (err) {
67
+ lastError = err;
68
+ continue;
69
+ }
70
+ }
71
+
72
+ throw new Error(`CleanWeb Gateway request failed on all endpoints: ${lastError}`);
73
+ }
74
+
75
+ /**
76
+ * 1. Clean Web Content Action
77
+ * Scrapes target webpage, removing ads and boilerplate to achieve 87% token compression.
78
+ */
79
+ export async function cleanWebContent(
80
+ params: CleanWebContentParams,
81
+ options: ActionInvocationOptions = {}
82
+ ): Promise<CleanWebContentResult> {
83
+ const t0 = Date.now();
84
+ const headers: Record<string, string> = {
85
+ Accept: "application/json, text/markdown",
86
+ "User-Agent": "CoinbaseAgentKit-CleanWeb/1.0",
87
+ };
88
+ if (options.vaultKey) headers["X-Vault-Key"] = options.vaultKey;
89
+ if (options.agentNonce) headers["X-Agent-Nonce"] = options.agentNonce;
90
+
91
+ const targetPath = `/r/${encodeURI(params.url)}`;
92
+ const resp = await fetchWithFailover(targetPath, {
93
+ method: "GET",
94
+ headers,
95
+ timeoutMs: options.timeoutMs,
96
+ gatewayUrl: options.gatewayUrl,
97
+ });
98
+
99
+ const contentType = resp.headers.get("content-type") || "";
100
+ let cleanMarkdown = "";
101
+ let title = "Webpage";
102
+ let tokenReductionRate = "87.0%";
103
+
104
+ if (contentType.includes("application/json")) {
105
+ const data = await resp.json();
106
+ cleanMarkdown = data.markdown || data.content || data.clean_content || "";
107
+ title = data.title || title;
108
+ tokenReductionRate = data.reduction_rate || tokenReductionRate;
109
+ } else {
110
+ cleanMarkdown = await resp.text();
111
+ const titleMatch = cleanMarkdown.match(/^#\s+(.+)$/m);
112
+ if (titleMatch) title = titleMatch[1];
113
+ }
114
+
115
+ const latencyMs = Date.now() - t0;
116
+ const compressedTokens = Math.max(1, Math.round(cleanMarkdown.length / 4));
117
+ const sourceTokens = Math.round(compressedTokens / 0.13); // Approx based on 87% reduction
118
+
119
+ return {
120
+ success: resp.ok,
121
+ url: params.url,
122
+ title,
123
+ cleanMarkdown: cleanMarkdown.slice(0, params.maxLength || 50000),
124
+ tokenReductionRate,
125
+ sourceTokensEstimate: sourceTokens,
126
+ compressedTokensEstimate: compressedTokens,
127
+ latencyMs,
128
+ };
129
+ }
130
+
131
+ /**
132
+ * 2. Clean Research PDF Action
133
+ * Parses online academic and financial whitepaper PDFs into structured text.
134
+ */
135
+ export async function cleanPdfResearch(
136
+ params: CleanPdfParams,
137
+ options: ActionInvocationOptions = {}
138
+ ): Promise<CleanPdfResult> {
139
+ const t0 = Date.now();
140
+ const headers: Record<string, string> = {
141
+ Accept: "application/json",
142
+ "User-Agent": "CoinbaseAgentKit-CleanWeb/1.0",
143
+ };
144
+ if (options.vaultKey) headers["X-Vault-Key"] = options.vaultKey;
145
+ if (options.agentNonce) headers["X-Agent-Nonce"] = options.agentNonce;
146
+
147
+ const queryParams = new URLSearchParams({
148
+ url: params.pdfUrl,
149
+ max_pages: String(params.maxPages || 50),
150
+ });
151
+
152
+ const resp = await fetchWithFailover(`/api/v1/clean-pdf?${queryParams.toString()}`, {
153
+ method: "GET",
154
+ headers,
155
+ timeoutMs: options.timeoutMs,
156
+ gatewayUrl: options.gatewayUrl,
157
+ });
158
+
159
+ const data = await resp.json();
160
+ const latencyMs = Date.now() - t0;
161
+
162
+ return {
163
+ success: resp.ok && (data.status === "success" || data.success === true),
164
+ pdfUrl: params.pdfUrl,
165
+ title: data.title || "PDF Whitepaper",
166
+ pageCount: data.pages || data.page_count || 1,
167
+ wordCount: data.words || data.word_count || (data.text || "").split(/\s+/).length,
168
+ text: data.text || data.parsed_content || "",
169
+ latencyMs,
170
+ };
171
+ }
172
+
173
+ /**
174
+ * 3. Clean YouTube Transcript Action
175
+ * Extracts high-precision subtitles and Gemini 3.8 Flash summary for YouTube videos.
176
+ */
177
+ export async function cleanYoutubeTranscript(
178
+ params: CleanYoutubeParams,
179
+ options: ActionInvocationOptions = {}
180
+ ): Promise<CleanYoutubeResult> {
181
+ const t0 = Date.now();
182
+ const headers: Record<string, string> = {
183
+ Accept: "application/json",
184
+ "User-Agent": "CoinbaseAgentKit-CleanWeb/1.0",
185
+ };
186
+ if (options.vaultKey) headers["X-Vault-Key"] = options.vaultKey;
187
+ if (options.agentNonce) headers["X-Agent-Nonce"] = options.agentNonce;
188
+
189
+ const queryParams = new URLSearchParams({
190
+ url: params.videoUrl,
191
+ summary: String(params.includeSummary ?? true),
192
+ });
193
+
194
+ const resp = await fetchWithFailover(`/api/v1/clean-youtube?${queryParams.toString()}`, {
195
+ method: "GET",
196
+ headers,
197
+ timeoutMs: options.timeoutMs,
198
+ gatewayUrl: options.gatewayUrl,
199
+ });
200
+
201
+ const data = await resp.json();
202
+ const latencyMs = Date.now() - t0;
203
+
204
+ const transcript = data.transcript || data.text || "";
205
+
206
+ return {
207
+ success: resp.ok,
208
+ videoId: data.video_id || params.videoUrl,
209
+ title: data.title || "YouTube Video",
210
+ channel: data.channel || data.author || "Unknown Channel",
211
+ summary: data.summary,
212
+ transcriptSample: transcript.slice(0, 1000),
213
+ fullTranscriptLength: transcript.length,
214
+ latencyMs,
215
+ };
216
+ }
217
+
218
+ /**
219
+ * 4. Oracle Grounding Action
220
+ * Discovers ground truth and produces Base EIP-712 cryptographic attestation.
221
+ */
222
+ export async function oracleGrounding(
223
+ params: OracleGroundingParams,
224
+ options: ActionInvocationOptions = {}
225
+ ): Promise<OracleGroundingResult> {
226
+ const t0 = Date.now();
227
+ const headers: Record<string, string> = {
228
+ "Content-Type": "application/json",
229
+ Accept: "application/json",
230
+ "User-Agent": "CoinbaseAgentKit-CleanWeb/1.0",
231
+ };
232
+ if (options.vaultKey) headers["X-Vault-Key"] = options.vaultKey;
233
+ if (options.agentNonce) headers["X-Agent-Nonce"] = options.agentNonce;
234
+
235
+ const body = JSON.stringify({
236
+ query: params.query,
237
+ target_url: params.targetUrl,
238
+ chain_id: params.chainId || BASE_CHAIN_ID,
239
+ });
240
+
241
+ const resp = await fetchWithFailover("/api/v1/oracle/grounding", {
242
+ method: "POST",
243
+ headers,
244
+ body,
245
+ timeoutMs: options.timeoutMs,
246
+ gatewayUrl: options.gatewayUrl,
247
+ });
248
+
249
+ const data = await resp.json();
250
+ const latencyMs = Date.now() - t0;
251
+
252
+ return {
253
+ success: resp.ok,
254
+ query: params.query,
255
+ groundedFacts: data.facts || data.grounded_facts || [],
256
+ summary: data.summary || "",
257
+ verdict: data.verdict || "VERIFIED",
258
+ confidence: data.confidence ?? 0.95,
259
+ attestation: data.attestation
260
+ ? {
261
+ chainId: data.attestation.chain_id || params.chainId || BASE_CHAIN_ID,
262
+ signerAddress: data.attestation.signer_address || "",
263
+ merkleRoot: data.attestation.merkle_root || "",
264
+ signature: data.attestation.signature || "",
265
+ eip712Domain: data.attestation.domain || {},
266
+ }
267
+ : undefined,
268
+ latencyMs,
269
+ };
270
+ }
271
+
272
+ /**
273
+ * 5. Manage x402 Vault Action
274
+ * Checks balance, deposit requirements, or VIP pass status for Base USDC vaults.
275
+ */
276
+ export async function manageX402Vault(
277
+ params: ManageVaultParams,
278
+ options: ActionInvocationOptions = {}
279
+ ): Promise<ManageVaultResult> {
280
+ const headers: Record<string, string> = {
281
+ Accept: "application/json",
282
+ "User-Agent": "CoinbaseAgentKit-CleanWeb/1.0",
283
+ };
284
+ if (options.vaultKey) headers["X-Vault-Key"] = options.vaultKey;
285
+
286
+ const agentAddr = params.agentAddress || options.vaultKey || "";
287
+
288
+ if (params.action === "deposit_info") {
289
+ return {
290
+ success: true,
291
+ action: "deposit_info",
292
+ depositAddress: BASE_ESCROW_CORE,
293
+ supportedChains: ["Base (8453)", "Base Sepolia (84532)", "Polygon (137)", "Arbitrum (42161)"],
294
+ passTier: `Native USDC on Base (${BASE_USDC_ADDRESS})`,
295
+ };
296
+ }
297
+
298
+ if (params.action === "balance") {
299
+ const resp = await fetchWithFailover(`/api/v1/vault/balance?address=${encodeURIComponent(agentAddr)}`, {
300
+ method: "GET",
301
+ headers,
302
+ timeoutMs: options.timeoutMs,
303
+ gatewayUrl: options.gatewayUrl,
304
+ });
305
+ const data = await resp.json();
306
+ return {
307
+ success: resp.ok,
308
+ action: "balance",
309
+ agentAddress: agentAddr,
310
+ balanceUsdc: data.balance_usdc ?? 0,
311
+ totalConsumedUsdc: data.total_consumed_usdc ?? 0,
312
+ };
313
+ }
314
+
315
+ if (params.action === "pass_status") {
316
+ const resp = await fetchWithFailover(`/api/v1/pass-status?address=${encodeURIComponent(agentAddr)}`, {
317
+ method: "GET",
318
+ headers,
319
+ timeoutMs: options.timeoutMs,
320
+ gatewayUrl: options.gatewayUrl,
321
+ });
322
+ const data = await resp.json();
323
+ return {
324
+ success: resp.ok,
325
+ action: "pass_status",
326
+ agentAddress: agentAddr,
327
+ passTier: data.tier || "FREE_SANDBOX_TIER",
328
+ passActive: data.active ?? true,
329
+ };
330
+ }
331
+
332
+ return {
333
+ success: false,
334
+ action: params.action,
335
+ };
336
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Constants for agentkit-cleanweb
3
+ */
4
+
5
+ export const VERSION = "1.0.0";
6
+
7
+ export const DEFAULT_GATEWAY_URL =
8
+ "https://x402-cleanweb-agent-212942243360.asia-northeast3.run.app";
9
+
10
+ export const FALLBACK_GATEWAY_URL =
11
+ "https://x402-cleanweb-agent-7qxtp3324q-du.a.run.app";
12
+
13
+ export const BASE_CHAIN_ID = 8453;
14
+ export const BASE_SEPOLIA_CHAIN_ID = 84532;
15
+
16
+ /**
17
+ * Base Native USDC Token Contract Address (ERC-20)
18
+ */
19
+ export const BASE_USDC_ADDRESS =
20
+ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" as const;
21
+
22
+ /**
23
+ * A.GRID Universal Modular Escrow Core Contract on Base Mainnet
24
+ */
25
+ export const BASE_ESCROW_CORE =
26
+ "0x99FEd65Cf2D5378182c3481B300124BB1a8Ad278" as const;
27
+
28
+ export const DEFAULT_TIMEOUT_MS = 15000;
29
+
30
+ export const ACTION_PRICING = {
31
+ CLEAN_WEB: 0.001, // 0.001 USDC
32
+ CLEAN_PDF: 0.005, // 0.005 USDC
33
+ CLEAN_YOUTUBE: 0.005, // 0.005 USDC
34
+ ORACLE_GROUNDING: 0.035, // 0.035 USDC (includes Gemini Flash + EIP-712 proof)
35
+ } as const;
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * agentkit-cleanweb
3
+ * Official Coinbase AgentKit Action Provider for CleanWeb Studio & Base Mainnet x402 Micropayments
4
+ */
5
+
6
+ export * from "./constants.js";
7
+ export * from "./types.js";
8
+ export * from "./actions.js";
9
+ export * from "./provider.js";
10
+
11
+ import { cleanWebActionProvider } from "./provider.js";
12
+ export default cleanWebActionProvider;
@@ -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
+ }