Skip to main content

harness_webfetch/
lib.rs

1//! WebFetch tool — Rust port of `@agent-sh/harness-webfetch`.
2//!
3//! Conforms to `agent-knowledge/design/webfetch.md`. Same contract as the
4//! TS package: HTTP GET/POST with tool-layer SSRF defense, manual
5//! redirect loop with per-hop re-check, readability+markdown extraction,
6//! 3-tier size caps with spill-to-file, and an in-memory 5-min session
7//! cache.
8
9mod constants;
10mod engine;
11mod extractor;
12mod fence;
13mod format;
14mod run;
15mod schema;
16mod ssrf;
17mod types;
18
19pub use constants::*;
20pub use engine::{default_engine, FetchError, ReqwestEngine, WebFetchEngine, WebFetchEngineInput, WebFetchEngineResult};
21pub use format::{
22    format_http_error_text, format_ok_text, format_redirect_loop_text,
23    head_and_tail, render_request_block, spill_to_file,
24};
25pub use schema::{
26    safe_parse_webfetch_params, WebFetchParams, WebFetchParseError,
27    WEBFETCH_TOOL_DESCRIPTION, WEBFETCH_TOOL_NAME,
28};
29pub use ssrf::{classify_host, classify_ip, BlockClass, SsrfDecision};
30pub use types::{
31    CachedResponse, FetchMetadata, WebFetchCache, WebFetchError, WebFetchExtract,
32    WebFetchHttpError, WebFetchMethod, WebFetchOk, WebFetchPermissionPolicy,
33    WebFetchRedirectLoop, WebFetchResult, WebFetchSessionConfig,
34};
35
36pub async fn webfetch(
37    params: serde_json::Value,
38    session: &WebFetchSessionConfig,
39) -> WebFetchResult {
40    run::webfetch_run(params, session).await
41}