Skip to content

Commit 6cb3c12

Browse files
committed
fix(tool): align JSON schema with conditional fetch fields
1 parent a9ac6b2 commit 6cb3c12

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

crates/fetchkit/src/tool.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ fn validate_args(tool: &Tool, args: &Value) -> Result<(), ToolError> {
660660
"as_markdown" => tool.enable_markdown,
661661
"as_text" => tool.enable_text,
662662
"save_to_file" => tool.enable_save_to_file,
663+
"if_none_match" | "if_modified_since" => true,
663664
_ => false,
664665
};
665666

@@ -722,6 +723,21 @@ fn build_input_schema(
722723
);
723724
}
724725

726+
properties.insert(
727+
"if_none_match".to_string(),
728+
json!({
729+
"type": "string",
730+
"description": "ETag value for conditional requests (If-None-Match header)"
731+
}),
732+
);
733+
properties.insert(
734+
"if_modified_since".to_string(),
735+
json!({
736+
"type": "string",
737+
"description": "Last-Modified value for conditional requests (If-Modified-Since header)"
738+
}),
739+
);
740+
725741
json!({
726742
"type": "object",
727743
"properties": properties,
@@ -739,6 +755,7 @@ fn build_output_schema() -> Value {
739755
"content_type": {"type": "string"},
740756
"size": {"type": "integer", "minimum": 0},
741757
"last_modified": {"type": "string"},
758+
"etag": {"type": "string"},
742759
"filename": {"type": "string"},
743760
"format": {"type": "string", "enum": ["markdown", "text", "raw", "github_repo"]},
744761
"content": {"type": "string"},
@@ -1165,11 +1182,14 @@ mod tests {
11651182
assert_eq!(input_schema["type"], "object");
11661183
assert_eq!(input_schema["properties"]["url"]["format"], "uri");
11671184
assert_eq!(input_schema["properties"]["method"]["default"], "GET");
1185+
assert!(input_schema["properties"]["if_none_match"].is_object());
1186+
assert!(input_schema["properties"]["if_modified_since"].is_object());
11681187
assert!(output_schema["properties"]["url"].is_object());
11691188
assert!(output_schema["properties"]["status_code"].is_object());
11701189
assert!(output_schema["properties"]["word_count"].is_object());
11711190
assert!(output_schema["properties"]["redirect_chain"].is_object());
11721191
assert!(output_schema["properties"]["is_paywall"].is_object());
1192+
assert!(output_schema["properties"]["etag"].is_object());
11731193
}
11741194

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

1233+
#[test]
1234+
fn test_execution_accepts_conditional_fetch_arguments() {
1235+
let ok = Tool::default().execution(json!({
1236+
"url": "https://example.com",
1237+
"if_none_match": "\"abc\"",
1238+
"if_modified_since": "Wed, 21 Oct 2015 07:28:00 GMT"
1239+
}));
1240+
assert!(ok.is_ok());
1241+
}
1242+
12131243
#[test]
12141244
fn test_execution_rejects_invalid_url_before_running() {
12151245
let err = Tool::default().execution(json!({"url": "ftp://example.com"}));

0 commit comments

Comments
 (0)