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/dist/types.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* 1. Clean Web Content Schema
|
|
4
|
+
*/
|
|
5
|
+
export declare const CleanWebContentSchema: z.ZodObject<{
|
|
6
|
+
url: z.ZodString;
|
|
7
|
+
maxLength: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
8
|
+
includeLinks: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
url: string;
|
|
11
|
+
maxLength: number;
|
|
12
|
+
includeLinks: boolean;
|
|
13
|
+
}, {
|
|
14
|
+
url: string;
|
|
15
|
+
maxLength?: number | undefined;
|
|
16
|
+
includeLinks?: boolean | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export type CleanWebContentParams = z.infer<typeof CleanWebContentSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* 2. Clean Research PDF Schema
|
|
21
|
+
*/
|
|
22
|
+
export declare const CleanPdfSchema: z.ZodObject<{
|
|
23
|
+
pdfUrl: z.ZodString;
|
|
24
|
+
maxPages: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
pdfUrl: string;
|
|
27
|
+
maxPages: number;
|
|
28
|
+
}, {
|
|
29
|
+
pdfUrl: string;
|
|
30
|
+
maxPages?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export type CleanPdfParams = z.infer<typeof CleanPdfSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* 3. Clean YouTube Transcript Schema
|
|
35
|
+
*/
|
|
36
|
+
export declare const CleanYoutubeSchema: z.ZodObject<{
|
|
37
|
+
videoUrl: z.ZodString;
|
|
38
|
+
includeSummary: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
videoUrl: string;
|
|
41
|
+
includeSummary: boolean;
|
|
42
|
+
}, {
|
|
43
|
+
videoUrl: string;
|
|
44
|
+
includeSummary?: boolean | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
export type CleanYoutubeParams = z.infer<typeof CleanYoutubeSchema>;
|
|
47
|
+
/**
|
|
48
|
+
* 4. Oracle Grounding & EIP-712 Attestation Schema
|
|
49
|
+
*/
|
|
50
|
+
export declare const OracleGroundingSchema: z.ZodObject<{
|
|
51
|
+
query: z.ZodString;
|
|
52
|
+
targetUrl: z.ZodOptional<z.ZodString>;
|
|
53
|
+
chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
query: string;
|
|
56
|
+
chainId: number;
|
|
57
|
+
targetUrl?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
query: string;
|
|
60
|
+
targetUrl?: string | undefined;
|
|
61
|
+
chainId?: number | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
export type OracleGroundingParams = z.infer<typeof OracleGroundingSchema>;
|
|
64
|
+
/**
|
|
65
|
+
* 5. Manage x402 Agent Vault Schema
|
|
66
|
+
*/
|
|
67
|
+
export declare const ManageVaultSchema: z.ZodObject<{
|
|
68
|
+
action: z.ZodEnum<["balance", "deposit_info", "pass_status"]>;
|
|
69
|
+
agentAddress: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
action: "balance" | "deposit_info" | "pass_status";
|
|
72
|
+
agentAddress?: string | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
action: "balance" | "deposit_info" | "pass_status";
|
|
75
|
+
agentAddress?: string | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
export type ManageVaultParams = z.infer<typeof ManageVaultSchema>;
|
|
78
|
+
/**
|
|
79
|
+
* CleanWeb Universal Action Result Interfaces
|
|
80
|
+
*/
|
|
81
|
+
export interface CleanWebContentResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
url: string;
|
|
84
|
+
title: string;
|
|
85
|
+
cleanMarkdown: string;
|
|
86
|
+
tokenReductionRate: string;
|
|
87
|
+
sourceTokensEstimate: number;
|
|
88
|
+
compressedTokensEstimate: number;
|
|
89
|
+
latencyMs: number;
|
|
90
|
+
}
|
|
91
|
+
export interface CleanPdfResult {
|
|
92
|
+
success: boolean;
|
|
93
|
+
pdfUrl: string;
|
|
94
|
+
title: string;
|
|
95
|
+
pageCount: number;
|
|
96
|
+
wordCount: number;
|
|
97
|
+
text: string;
|
|
98
|
+
latencyMs: number;
|
|
99
|
+
}
|
|
100
|
+
export interface CleanYoutubeResult {
|
|
101
|
+
success: boolean;
|
|
102
|
+
videoId: string;
|
|
103
|
+
title: string;
|
|
104
|
+
channel: string;
|
|
105
|
+
summary?: string;
|
|
106
|
+
transcriptSample: string;
|
|
107
|
+
fullTranscriptLength: number;
|
|
108
|
+
latencyMs: number;
|
|
109
|
+
}
|
|
110
|
+
export interface OracleGroundingResult {
|
|
111
|
+
success: boolean;
|
|
112
|
+
query: string;
|
|
113
|
+
groundedFacts: string[];
|
|
114
|
+
summary: string;
|
|
115
|
+
verdict: "VERIFIED" | "CONTRADICTED" | "UNVERIFIED";
|
|
116
|
+
confidence: number;
|
|
117
|
+
attestation?: {
|
|
118
|
+
chainId: number;
|
|
119
|
+
signerAddress: string;
|
|
120
|
+
merkleRoot: string;
|
|
121
|
+
signature: string;
|
|
122
|
+
eip712Domain: Record<string, unknown>;
|
|
123
|
+
};
|
|
124
|
+
latencyMs: number;
|
|
125
|
+
}
|
|
126
|
+
export interface ManageVaultResult {
|
|
127
|
+
success: boolean;
|
|
128
|
+
action: string;
|
|
129
|
+
agentAddress?: string;
|
|
130
|
+
balanceUsdc?: number;
|
|
131
|
+
totalConsumedUsdc?: number;
|
|
132
|
+
depositAddress?: string;
|
|
133
|
+
supportedChains?: string[];
|
|
134
|
+
passTier?: string;
|
|
135
|
+
passActive?: boolean;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAiB4C,CAAC;AAE/E,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;EAa2E,CAAC;AAEvG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;EAUoE,CAAC;AAEpG,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAgBiF,CAAC;AAEpH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;EAYsE,CAAC;AAErG,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,wBAAwB,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY,CAAC;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACvC,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* 1. Clean Web Content Schema
|
|
4
|
+
*/
|
|
5
|
+
export const CleanWebContentSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
url: z.string().url().describe("The HTTP/HTTPS webpage URL to scrape and compress into clean Markdown"),
|
|
8
|
+
maxLength: z
|
|
9
|
+
.number()
|
|
10
|
+
.int()
|
|
11
|
+
.positive()
|
|
12
|
+
.optional()
|
|
13
|
+
.default(50000)
|
|
14
|
+
.describe("Maximum character length for the returned markdown body (default 50,000)"),
|
|
15
|
+
includeLinks: z
|
|
16
|
+
.boolean()
|
|
17
|
+
.optional()
|
|
18
|
+
.default(true)
|
|
19
|
+
.describe("Whether to preserve relevant markdown links in the cleaned text"),
|
|
20
|
+
})
|
|
21
|
+
.strip()
|
|
22
|
+
.describe("Parameters for scraping and reducing webpage token noise by 87%");
|
|
23
|
+
/**
|
|
24
|
+
* 2. Clean Research PDF Schema
|
|
25
|
+
*/
|
|
26
|
+
export const CleanPdfSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
pdfUrl: z.string().url().describe("The direct URL of the PDF whitepaper, financial filing, or arXiv research report"),
|
|
29
|
+
maxPages: z
|
|
30
|
+
.number()
|
|
31
|
+
.int()
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(100)
|
|
34
|
+
.optional()
|
|
35
|
+
.default(50)
|
|
36
|
+
.describe("Maximum number of pages to parse (1-100, default 50)"),
|
|
37
|
+
})
|
|
38
|
+
.strip()
|
|
39
|
+
.describe("Parameters for extracting clean academic and financial text from online PDF whitepapers");
|
|
40
|
+
/**
|
|
41
|
+
* 3. Clean YouTube Transcript Schema
|
|
42
|
+
*/
|
|
43
|
+
export const CleanYoutubeSchema = z
|
|
44
|
+
.object({
|
|
45
|
+
videoUrl: z.string().describe("YouTube video URL or 11-character video ID"),
|
|
46
|
+
includeSummary: z
|
|
47
|
+
.boolean()
|
|
48
|
+
.optional()
|
|
49
|
+
.default(true)
|
|
50
|
+
.describe("Whether to generate Gemini 3.8 Flash bullet-point executive summary"),
|
|
51
|
+
})
|
|
52
|
+
.strip()
|
|
53
|
+
.describe("Parameters for extracting timestamped subtitles and AI summaries from YouTube videos");
|
|
54
|
+
/**
|
|
55
|
+
* 4. Oracle Grounding & EIP-712 Attestation Schema
|
|
56
|
+
*/
|
|
57
|
+
export const OracleGroundingSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
query: z.string().min(3).describe("The factual proposition or topic to verify (e.g. 'Base TVL surpasses 4B' or 'CRMA compliance')"),
|
|
60
|
+
targetUrl: z
|
|
61
|
+
.string()
|
|
62
|
+
.url()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe("Optional target webpage URL to ground the facts against"),
|
|
65
|
+
chainId: z
|
|
66
|
+
.number()
|
|
67
|
+
.int()
|
|
68
|
+
.optional()
|
|
69
|
+
.default(8453)
|
|
70
|
+
.describe("Target blockchain network ID for EIP-712 signature (Base Mainnet: 8453, Base Sepolia: 84532)"),
|
|
71
|
+
})
|
|
72
|
+
.strip()
|
|
73
|
+
.describe("Parameters for web ground-truth discovery with on-chain verifiable EIP-712 cryptographic attestation");
|
|
74
|
+
/**
|
|
75
|
+
* 5. Manage x402 Agent Vault Schema
|
|
76
|
+
*/
|
|
77
|
+
export const ManageVaultSchema = z
|
|
78
|
+
.object({
|
|
79
|
+
action: z
|
|
80
|
+
.enum(["balance", "deposit_info", "pass_status"])
|
|
81
|
+
.describe("Action to perform: 'balance' (check prefunded USDC balance), 'deposit_info' (get deposit address & chain parameters), or 'pass_status' (check agent VIP pass)"),
|
|
82
|
+
agentAddress: z
|
|
83
|
+
.string()
|
|
84
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Must be a valid EVM address (0x...)")
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("The agent's EVM wallet address on Base Mainnet"),
|
|
87
|
+
})
|
|
88
|
+
.strip()
|
|
89
|
+
.describe("Parameters for managing gasless sub-millisecond x402 USDC micropayment session vaults");
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentkit-cleanweb",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Coinbase AgentKit Action Provider for CleanWeb 87% Token Reduction, Research PDF Parser, YouTube Gemini Intelligence, and Base Mainnet EIP-712 Oracle Grounding",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/nohosa001-pixel/x402-cleanweb-agent.git",
|
|
12
|
+
"directory": "packages/agentkit-cleanweb"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "node --test tests/test_action_provider.test.mjs"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"coinbase",
|
|
23
|
+
"agentkit",
|
|
24
|
+
"base",
|
|
25
|
+
"x402",
|
|
26
|
+
"ai-agent",
|
|
27
|
+
"web-scraping",
|
|
28
|
+
"token-reduction",
|
|
29
|
+
"ground-truth",
|
|
30
|
+
"eip712",
|
|
31
|
+
"oracle",
|
|
32
|
+
"gemini"
|
|
33
|
+
],
|
|
34
|
+
"author": "CleanWeb & A.GRID Team",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@coinbase/agentkit": ">=0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@coinbase/agentkit": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"zod": "^3.23.8"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.13.0",
|
|
49
|
+
"typescript": "^5.8.2",
|
|
50
|
+
"zod": "^3.23.8"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"src",
|
|
55
|
+
"README.md"
|
|
56
|
+
]
|
|
57
|
+
}
|
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
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -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;
|