@fouradata/mcp 0.2.11

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,316 @@
1
+ import { request } from "undici";
2
+ import { z } from "zod";
3
+ import { getApiKey } from "../auth.js";
4
+ import { assertPublicTarget, SsrfBlockedError } from "../safe-target.js";
5
+ import { storePayload, THRESHOLD_BYTES } from "../resources.js";
6
+ function extractContentTypeFromObject(headers) {
7
+ if (!headers || typeof headers !== "object")
8
+ return null;
9
+ for (const [k, v] of Object.entries(headers)) {
10
+ if (k.toLowerCase() === "content-type") {
11
+ const value = Array.isArray(v) ? v[0] : v;
12
+ if (typeof value === "string")
13
+ return value.split(";")[0]?.trim() ?? null;
14
+ }
15
+ }
16
+ return null;
17
+ }
18
+ function deriveCode(status, envelope) {
19
+ if (status === 400)
20
+ return "bad_request";
21
+ if (status === 401)
22
+ return "auth_failed";
23
+ if (status === 403)
24
+ return "forbidden";
25
+ if (status === 404)
26
+ return "not_found";
27
+ if (status === 429)
28
+ return "rate_limited";
29
+ if (status === 503) {
30
+ if (envelope.current)
31
+ return "at_capacity";
32
+ const err = typeof envelope.error === "string" ? envelope.error : "";
33
+ if (err.toLowerCase().includes("disabled"))
34
+ return "service_disabled";
35
+ return "service_unavailable";
36
+ }
37
+ if (status >= 500)
38
+ return "upstream_error";
39
+ if (status >= 400)
40
+ return "upstream_client_error";
41
+ return "upstream_unknown";
42
+ }
43
+ async function guardHandler(service,
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ outputSchema,
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ fn) {
48
+ try {
49
+ const result = await fn();
50
+ if (result?.structuredContent) {
51
+ const parsed = outputSchema.safeParse(result.structuredContent);
52
+ if (!parsed.success) {
53
+ const issues = parsed.error.issues.slice(0, 5).map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
54
+ return {
55
+ isError: true,
56
+ content: [{ type: "text", text: `FourA ${service} — upstream response failed schema: ${issues}` }],
57
+ structuredContent: {
58
+ service,
59
+ code: "output_validation_failed",
60
+ error: `Upstream response did not match the expected schema: ${issues}`,
61
+ },
62
+ };
63
+ }
64
+ }
65
+ return result;
66
+ }
67
+ catch (e) {
68
+ const msg = e instanceof Error ? e.message : String(e);
69
+ return {
70
+ isError: true,
71
+ content: [{ type: "text", text: `FourA ${service} — internal error: ${msg}` }],
72
+ structuredContent: {
73
+ service,
74
+ code: "output_validation_failed",
75
+ error: `Tool handler crashed before producing a response: ${msg}`,
76
+ },
77
+ };
78
+ }
79
+ }
80
+ const BROWSER_API_URL = (process.env.FOURA_API_BASE ?? "https://api.foura.ai/api") + "/browser/";
81
+ const BrowserCookieInputSchema = z.object({
82
+ name: z.string(),
83
+ value: z.string(),
84
+ domain: z.string().optional(),
85
+ });
86
+ // Full CDP cookie object — captured from Chrome via Network.getAllCookies after navigation.
87
+ // Permissive — Protocol.Network.Cookie has more fields than we model, and CDP versions vary.
88
+ const CdpCookieSchema = z
89
+ .object({
90
+ name: z.string(),
91
+ value: z.string(),
92
+ domain: z.string().optional(),
93
+ path: z.string().optional(),
94
+ expires: z.number().optional(),
95
+ size: z.number().optional(),
96
+ httpOnly: z.boolean().optional(),
97
+ secure: z.boolean().optional(),
98
+ session: z.boolean().optional(),
99
+ sameSite: z.string().optional(),
100
+ })
101
+ .catchall(z.unknown());
102
+ const browserOutputShape = {
103
+ // Success — dwstack browser DwResponse (packages/browser/src/schema.ts:19-26)
104
+ status: z.number().int().optional().describe("HTTP status code from the target page. `0` indicates the navigation failed before any HTTP response (DNS / connection refused / timeout) — check the `error` field for the underlying reason."),
105
+ // CDP headers (Protocol.Network.Headers) are a Record but values can be
106
+ // string OR string[] in some CDP versions. Bug 11 fix — permissive.
107
+ headers: z
108
+ .record(z.string(), z.unknown())
109
+ .optional()
110
+ .describe("Response headers as a flat key-value object. Values are typically strings but may be arrays for repeated headers."),
111
+ // body: string | object in upstream (browser/src/schema.ts:25). Bug 7 fix.
112
+ body: z
113
+ .union([z.string(), z.record(z.string(), z.unknown())])
114
+ .optional()
115
+ .describe("Fully-rendered page content. String HTML when content-type is HTML; object when the page returned JSON and it was auto-parsed. Field is named `body`, not `data`. Omitted when offloaded."),
116
+ cookies: z.array(CdpCookieSchema).optional().describe("Full cookie objects collected after navigation (name, value, domain, path, expires, httpOnly, secure, session, sameSite, …)"),
117
+ userAgent: z.string().optional().describe("The User-Agent the browser session presented"),
118
+ // Offload path — MCP layer adds these when body >= 50KB AND offload_large=true
119
+ offloaded_resource_uri: z.string().optional().describe("foura-mcp://payload/<uuid>"),
120
+ size_bytes: z.number().int().optional().describe("Total offloaded body size in bytes"),
121
+ // Error path
122
+ error: z.string().optional().describe("Human-readable error message"),
123
+ service: z.enum(["single", "proxy", "browser", "api"]).optional(),
124
+ retryAfter: z.number().optional(),
125
+ current: z
126
+ .object({ concurrency: z.number().optional(), rpm: z.number().optional() })
127
+ .optional(),
128
+ limits: z
129
+ .object({ maxConcurrency: z.number().optional(), maxRpm: z.number().optional() })
130
+ .optional(),
131
+ code: z.string().optional().describe("Stable error code for retry classification. One of: ssrf_blocked, upstream_non_json, output_validation_failed, bad_request (400), auth_failed (401), forbidden (403), not_found (404), rate_limited (429), at_capacity (503), service_disabled (503), service_unavailable (503), upstream_error (>=500), upstream_client_error (other 4xx), upstream_unknown (defensive)."),
132
+ };
133
+ const browserInputShape = {
134
+ url: z.string().url().describe("Target URL to load in a full browser session. Public hosts only — private/reserved ranges (RFC 1918 + loopback + link-local + IPv6 ULA/loopback + *.local mDNS) are refused with code `ssrf_blocked`. Example: https://shop.example.com/product/123 or any single-page-app URL."),
135
+ headers: z
136
+ .record(z.string(), z.string())
137
+ .optional()
138
+ .describe("Custom HTTP headers as a key-value object (NOT [name, value] tuples). Example: {\"Referer\": \"https://google.com/\"}"),
139
+ cookies: z
140
+ .array(BrowserCookieInputSchema)
141
+ .optional()
142
+ .describe("Cookies to set before navigation: [{ name, value, domain? }]"),
143
+ userAgent: z.string().optional().describe("Override the browser's User-Agent string"),
144
+ proxy: z
145
+ .string()
146
+ .optional()
147
+ .describe("Optional proxy. Three forms: (1) URL `http://user:pass@host:port` or `socks5://host:port`; " +
148
+ "(2) base36 ID from foura_proxy (e.g. `4DZ3VE`) — same pool exit IP; (3) omit → fixed container egress."),
149
+ timeout_ms: z
150
+ .number()
151
+ .int()
152
+ .min(0)
153
+ .max(120_000)
154
+ .optional()
155
+ .describe("Page load timeout in ms (default 30000, max 120000)"),
156
+ checkStatus: z
157
+ .number()
158
+ .int()
159
+ .optional()
160
+ .describe("Expected HTTP status code. If the page returns a different status → tool returns an error envelope with the actual status carried in the envelope. Example: 200 for product pages, or 404 to assert a soft-404 didn't leak through."),
161
+ checkText: z
162
+ .string()
163
+ .optional()
164
+ .describe("One-shot post-render validator — substring search on the rendered HTML AFTER navigation completes. NOT a waiter: does not poll, does not block until the substring appears. If the substring is missing, the tool returns an error envelope. Use to catch silent failures like a 200 response that captured a challenge page or empty SPA shell. Example: \"add to cart\" for product pages."),
165
+ // Bug 3 fix — opt-in offload, default false (inline).
166
+ offload_large: z
167
+ .boolean()
168
+ .optional()
169
+ .describe("If true, response bodies >= 50KB are written to disk and returned as a resource_link instead of inlined. Default false."),
170
+ };
171
+ export function registerBrowserTool(server) {
172
+ server.registerTool("foura_browser", {
173
+ title: "FourA — full browser navigation",
174
+ description: "Load a URL in a real browser session. JS runs, DOM renders, cookies come back. 2–10s. " +
175
+ "Use for SPAs, lazy-loaded content, or JS anti-bot challenges (Cloudflare Turnstile etc.). " +
176
+ "Prefer foura_single for static HTML; foura_proxy for static pages where your IP is blocked. " +
177
+ "To rotate the browser's exit IP: call foura_proxy first, pass its returned `proxy` ID into " +
178
+ "this tool's `proxy` field — the browser exits through that pool IP. Default (no `proxy`) " +
179
+ "is one fixed container egress. If the target is behind a tier-1 WAF challenge (Vercel / " +
180
+ "Cloudflare / Akamai), calling this tool directly will usually still capture the challenge " +
181
+ "page rather than the post-challenge content — the snapshot fires before the challenge's " +
182
+ "deferred reload completes. Correct chain: call foura_proxy first with maxTries:25-30 against " +
183
+ "the same URL → take the returned proxy base36 ID → pass it into this tool's `proxy` field. " +
184
+ "The browser then exits through the IP that already cleared the challenge for this target. " +
185
+ "No `unblocker` flag — browser navigation already sends real browser headers by default, so " +
186
+ "the flag would be redundant.",
187
+ inputSchema: browserInputShape,
188
+ outputSchema: browserOutputShape,
189
+ annotations: {
190
+ readOnlyHint: true,
191
+ destructiveHint: false,
192
+ openWorldHint: true,
193
+ },
194
+ }, async (input) => guardHandler("browser", z.object(browserOutputShape), async () => {
195
+ try {
196
+ await assertPublicTarget(input.url);
197
+ }
198
+ catch (e) {
199
+ if (e instanceof SsrfBlockedError) {
200
+ return {
201
+ isError: true,
202
+ content: [{ type: "text", text: e.message }],
203
+ structuredContent: { service: "browser", code: "ssrf_blocked", error: e.message },
204
+ };
205
+ }
206
+ throw e;
207
+ }
208
+ const { offload_large, ...upstreamBody } = input;
209
+ const res = await request(BROWSER_API_URL, {
210
+ method: "POST",
211
+ headers: {
212
+ "X-API-Key": getApiKey(),
213
+ "Content-Type": "application/json",
214
+ "User-Agent": "foura-mcp/0.2.11 (browser)",
215
+ },
216
+ body: JSON.stringify(upstreamBody),
217
+ });
218
+ const text = await res.body.text();
219
+ let parsed;
220
+ try {
221
+ parsed = JSON.parse(text);
222
+ }
223
+ catch {
224
+ return {
225
+ isError: true,
226
+ content: [
227
+ {
228
+ type: "text",
229
+ text: `FourA browser — non-JSON response (${res.statusCode}): ${text.slice(0, 200)}`,
230
+ },
231
+ ],
232
+ structuredContent: {
233
+ service: "browser",
234
+ code: "upstream_non_json",
235
+ status: res.statusCode,
236
+ error: `Upstream returned non-JSON (${res.statusCode}): ${text.slice(0, 200)}`,
237
+ },
238
+ };
239
+ }
240
+ if (res.statusCode < 200 || res.statusCode >= 300) {
241
+ const e = parsed;
242
+ const errMsg = typeof e.error === "string" ? e.error : "Unknown";
243
+ const retryStr = typeof e.retryAfter === "number" ? ` · retry ${e.retryAfter}s` : "";
244
+ return {
245
+ isError: true,
246
+ content: [{ type: "text", text: `FourA browser error ${res.statusCode}: ${errMsg}${retryStr}` }],
247
+ structuredContent: {
248
+ ...e,
249
+ service: "browser",
250
+ code: deriveCode(res.statusCode, e),
251
+ status: typeof e.status === "number" ? e.status : res.statusCode,
252
+ },
253
+ };
254
+ }
255
+ const parsedObj = parsed;
256
+ // Bug 8 fix — browser request.ts also rejects with DwResponseError on
257
+ // page failure (timeout, navigation error, checkStatus mismatch).
258
+ // Service forwards as 200 + {error, ...} via dwRequestToExpressRes.
259
+ if (typeof parsedObj.error === "string" && parsedObj.error.length > 0) {
260
+ const innerStatus = typeof parsedObj.status === "number" ? parsedObj.status : 0;
261
+ return {
262
+ isError: true,
263
+ content: [
264
+ {
265
+ type: "text",
266
+ text: `FourA browser — page failure (status ${innerStatus}): ${parsedObj.error}`,
267
+ },
268
+ ],
269
+ structuredContent: {
270
+ ...parsedObj,
271
+ service: "browser",
272
+ code: innerStatus > 0
273
+ ? deriveCode(innerStatus, parsedObj)
274
+ : "upstream_error",
275
+ status: innerStatus,
276
+ },
277
+ };
278
+ }
279
+ const body = parsedObj.body;
280
+ let bodyStr = null;
281
+ if (typeof body === "string")
282
+ bodyStr = body;
283
+ else if (body && typeof body === "object")
284
+ bodyStr = JSON.stringify(body);
285
+ const statusLabel = parsedObj.status ?? "?";
286
+ const shouldOffload = offload_large === true
287
+ && bodyStr
288
+ && Buffer.byteLength(bodyStr, "utf8") >= THRESHOLD_BYTES;
289
+ if (shouldOffload && bodyStr) {
290
+ const ct = extractContentTypeFromObject(parsedObj.headers) ?? "text/html";
291
+ const stored = await storePayload(bodyStr, ct, "rendered-page.html");
292
+ const sizeKb = (stored.size / 1024).toFixed(1);
293
+ return {
294
+ content: [
295
+ { type: "text", text: `${statusLabel} · rendered ${sizeKb} KB offloaded` },
296
+ { type: "resource_link", uri: stored.uri, name: stored.name, mimeType: stored.mimeType },
297
+ ],
298
+ structuredContent: {
299
+ status: parsedObj.status,
300
+ headers: parsedObj.headers,
301
+ cookies: Array.isArray(parsedObj.cookies) ? parsedObj.cookies : undefined,
302
+ userAgent: parsedObj.userAgent,
303
+ offloaded_resource_uri: stored.uri,
304
+ size_bytes: stored.size,
305
+ },
306
+ };
307
+ }
308
+ const sizeKb = bodyStr ? (Buffer.byteLength(bodyStr, "utf8") / 1024).toFixed(1) : "0";
309
+ return {
310
+ content: [{ type: "text", text: `${statusLabel} OK · ${sizeKb} KB rendered` }],
311
+ structuredContent: parsedObj,
312
+ };
313
+ }));
314
+ }
315
+ export const __test = { deriveCode, CdpCookieSchema, BrowserCookieInputSchema, browserInputShape, browserOutputShape };
316
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/tools/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,SAAS,4BAA4B,CAAC,OAAgB;IACpD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAkC,CAAC,EAAE,CAAC;QACxE,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,cAAc,EAAE,CAAC;YACvC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C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;oBACjE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;oBACzE,SAAS,EAAE,SAAS,CAAC,SAAS;oBAC9B,sBAAsB,EAAE,MAAM,CAAC,GAAG;oBAClC,UAAU,EAAE,MAAM,CAAC,IAAI;iBACxB;aACF,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACtF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,SAAS,MAAM,cAAc,EAAE,CAAC;YAC9E,iBAAiB,EAAE,SAAoC;SACxD,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ declare function deriveCode(status: number, envelope: Record<string, unknown>): string;
4
+ export declare function registerProxyTool(server: McpServer): void;
5
+ export declare const __test: {
6
+ deriveCode: typeof deriveCode;
7
+ ProxyHeaderInfoSchema: z.ZodObject<{
8
+ result: z.ZodOptional<z.ZodObject<{
9
+ version: z.ZodOptional<z.ZodString>;
10
+ code: z.ZodOptional<z.ZodNumber>;
11
+ reason: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>>;
13
+ }, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
14
+ ProxyInnerRequestSchema: z.ZodObject<{
15
+ method: z.ZodString;
16
+ url: z.ZodString;
17
+ headers: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>>;
18
+ unblocker: z.ZodOptional<z.ZodBoolean>;
19
+ data: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
20
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
21
+ connect_timeout_ms: z.ZodOptional<z.ZodNumber>;
22
+ accept_timeout_ms: z.ZodOptional<z.ZodNumber>;
23
+ server_response_timeout_ms: z.ZodOptional<z.ZodNumber>;
24
+ dns_cache_timeout_sec: z.ZodOptional<z.ZodNumber>;
25
+ followRedirects: z.ZodOptional<z.ZodNumber>;
26
+ tryJsonData: z.ZodOptional<z.ZodBoolean>;
27
+ returnBuffer: z.ZodOptional<z.ZodBoolean>;
28
+ validate: z.ZodOptional<z.ZodObject<{
29
+ status: z.ZodOptional<z.ZodObject<{
30
+ accept: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
31
+ fail: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
32
+ }, z.core.$strip>>;
33
+ headers: z.ZodOptional<z.ZodObject<{
34
+ accept: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
35
+ fail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
36
+ }, z.core.$strip>>;
37
+ data: z.ZodOptional<z.ZodObject<{
38
+ accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
39
+ fail: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
+ }, z.core.$strip>>;
41
+ }, z.core.$strip>>;
42
+ }, z.core.$strip>;
43
+ proxyInputShape: {
44
+ request: z.ZodObject<{
45
+ method: z.ZodString;
46
+ url: z.ZodString;
47
+ headers: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>>;
48
+ unblocker: z.ZodOptional<z.ZodBoolean>;
49
+ data: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
50
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
51
+ connect_timeout_ms: z.ZodOptional<z.ZodNumber>;
52
+ accept_timeout_ms: z.ZodOptional<z.ZodNumber>;
53
+ server_response_timeout_ms: z.ZodOptional<z.ZodNumber>;
54
+ dns_cache_timeout_sec: z.ZodOptional<z.ZodNumber>;
55
+ followRedirects: z.ZodOptional<z.ZodNumber>;
56
+ tryJsonData: z.ZodOptional<z.ZodBoolean>;
57
+ returnBuffer: z.ZodOptional<z.ZodBoolean>;
58
+ validate: z.ZodOptional<z.ZodObject<{
59
+ status: z.ZodOptional<z.ZodObject<{
60
+ accept: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
61
+ fail: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
62
+ }, z.core.$strip>>;
63
+ headers: z.ZodOptional<z.ZodObject<{
64
+ accept: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
65
+ fail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
66
+ }, z.core.$strip>>;
67
+ data: z.ZodOptional<z.ZodObject<{
68
+ accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ fail: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ }, z.core.$strip>>;
71
+ }, z.core.$strip>>;
72
+ }, z.core.$strip>;
73
+ maxTries: z.ZodOptional<z.ZodNumber>;
74
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
75
+ ignoreProxies: z.ZodOptional<z.ZodArray<z.ZodString>>;
76
+ offload_large: z.ZodOptional<z.ZodBoolean>;
77
+ };
78
+ proxyOutputShape: {
79
+ status: z.ZodOptional<z.ZodNumber>;
80
+ headers: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
81
+ result: z.ZodOptional<z.ZodObject<{
82
+ version: z.ZodOptional<z.ZodString>;
83
+ code: z.ZodOptional<z.ZodNumber>;
84
+ reason: z.ZodOptional<z.ZodString>;
85
+ }, z.core.$strip>>;
86
+ }, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>>, z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
87
+ data: z.ZodOptional<z.ZodUnknown>;
88
+ total_time: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodNull]>>;
89
+ proxy: z.ZodOptional<z.ZodString>;
90
+ total: z.ZodOptional<z.ZodNumber>;
91
+ offloaded_resource_uri: z.ZodOptional<z.ZodString>;
92
+ size_bytes: z.ZodOptional<z.ZodNumber>;
93
+ error: z.ZodOptional<z.ZodString>;
94
+ service: z.ZodOptional<z.ZodEnum<{
95
+ single: "single";
96
+ proxy: "proxy";
97
+ browser: "browser";
98
+ api: "api";
99
+ }>>;
100
+ retryAfter: z.ZodOptional<z.ZodNumber>;
101
+ current: z.ZodOptional<z.ZodObject<{
102
+ concurrency: z.ZodOptional<z.ZodNumber>;
103
+ rpm: z.ZodOptional<z.ZodNumber>;
104
+ }, z.core.$strip>>;
105
+ limits: z.ZodOptional<z.ZodObject<{
106
+ maxConcurrency: z.ZodOptional<z.ZodNumber>;
107
+ maxRpm: z.ZodOptional<z.ZodNumber>;
108
+ }, z.core.$strip>>;
109
+ request: z.ZodOptional<z.ZodUnknown>;
110
+ code: z.ZodOptional<z.ZodString>;
111
+ };
112
+ };
113
+ export {};