Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crates/fetchkit/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ fn validate_args(tool: &Tool, args: &Value) -> Result<(), ToolError> {
"as_markdown" => tool.enable_markdown,
"as_text" => tool.enable_text,
"save_to_file" => tool.enable_save_to_file,
"if_none_match" | "if_modified_since" => true,
_ => false,
};

Expand Down Expand Up @@ -722,6 +723,21 @@ fn build_input_schema(
);
}

properties.insert(
"if_none_match".to_string(),
json!({
"type": "string",
"description": "ETag value for conditional requests (If-None-Match header)"
}),
);
properties.insert(
"if_modified_since".to_string(),
json!({
"type": "string",
"description": "Last-Modified value for conditional requests (If-Modified-Since header)"
}),
);

json!({
"type": "object",
"properties": properties,
Expand All @@ -739,6 +755,7 @@ fn build_output_schema() -> Value {
"content_type": {"type": "string"},
"size": {"type": "integer", "minimum": 0},
"last_modified": {"type": "string"},
"etag": {"type": "string"},
"filename": {"type": "string"},
"format": {"type": "string", "enum": ["markdown", "text", "raw", "github_repo"]},
"content": {"type": "string"},
Expand Down Expand Up @@ -1165,11 +1182,14 @@ mod tests {
assert_eq!(input_schema["type"], "object");
assert_eq!(input_schema["properties"]["url"]["format"], "uri");
assert_eq!(input_schema["properties"]["method"]["default"], "GET");
assert!(input_schema["properties"]["if_none_match"].is_object());
assert!(input_schema["properties"]["if_modified_since"].is_object());
assert!(output_schema["properties"]["url"].is_object());
assert!(output_schema["properties"]["status_code"].is_object());
assert!(output_schema["properties"]["word_count"].is_object());
assert!(output_schema["properties"]["redirect_chain"].is_object());
assert!(output_schema["properties"]["is_paywall"].is_object());
assert!(output_schema["properties"]["etag"].is_object());
}

#[test]
Expand Down Expand Up @@ -1210,6 +1230,16 @@ mod tests {
assert!(err.unwrap_err().to_string().contains("Unknown parameter"));
}

#[test]
fn test_execution_accepts_conditional_fetch_arguments() {
let ok = Tool::default().execution(json!({
"url": "https://example.com",
"if_none_match": "\"abc\"",
"if_modified_since": "Wed, 21 Oct 2015 07:28:00 GMT"
}));
assert!(ok.is_ok());
}

#[test]
fn test_execution_rejects_invalid_url_before_running() {
let err = Tool::default().execution(json!({"url": "ftp://example.com"}));
Expand Down
Loading