Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type CacheControlEphemeral = {
* - `1h`: 1 hour
*
* Defaults to `5m`. See [prompt caching
* pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching) for details.
* pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for
* details.
*/
ttl: Ttl | null, type: CacheControlEphemeralType, };
3 changes: 2 additions & 1 deletion bindings/typescript/src/generated/anthropic/Ttl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* - `1h`: 1 hour
*
* Defaults to `5m`. See [prompt caching
* pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching) for details.
* pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for
* details.
*/
export type Ttl = "1h" | "5m";
4 changes: 2 additions & 2 deletions crates/generate-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ pub struct ToolSearchTool {
);

with_struct.replace(
" #[serde(rename = \"web_search_20260209\")]\n WebSearch20260209(WebSearchTool20260209),\n\n #[serde(untagged)]",
" #[serde(rename = \"web_search_20260209\")]\n WebSearch20260209(WebSearchTool20260209),\n\n #[serde(rename = \"tool_search_tool_bm25\")]\n ToolSearchToolBm25(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_bm25_20251119\")]\n ToolSearchToolBm2520251119(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_regex\")]\n ToolSearchToolRegex(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_regex_20251119\")]\n ToolSearchToolRegex20251119(ToolSearchTool),\n\n #[serde(untagged)]",
" #[serde(untagged)]\n Custom(CustomTool),",
" #[serde(rename = \"tool_search_tool_bm25\")]\n ToolSearchToolBm25(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_bm25_20251119\")]\n ToolSearchToolBm2520251119(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_regex\")]\n ToolSearchToolRegex(ToolSearchTool),\n\n #[serde(rename = \"tool_search_tool_regex_20251119\")]\n ToolSearchToolRegex20251119(ToolSearchTool),\n\n #[serde(untagged)]\n Custom(CustomTool),",
)
}

Expand Down
86 changes: 86 additions & 0 deletions crates/lingua/src/providers/anthropic/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3541,4 +3541,90 @@ mod tests {
assert!(matches!(err, ConvertError::InvalidToolSchema { .. }));
assert!(err.to_string().contains("root type is required"));
}

#[test]
fn test_web_search_20260318_roundtrips_through_universal() {
let tool_json = json!({
"type": "web_search_20260318",
"name": "web_search",
"allowed_domains": ["example.com"],
"max_uses": 5
});

let tool: Tool = serde_json::from_value(tool_json.clone()).expect("should parse");
let universal = UniversalTool::from(&tool);
assert!(universal.is_builtin());

let round_tripped = Tool::try_from(&universal).expect("should convert back");
let round_tripped_json = serde_json::to_value(&round_tripped).expect("should serialize");
assert_eq!(
round_tripped_json.get("type").and_then(|v| v.as_str()),
Some("web_search_20260318")
);
assert_eq!(
round_tripped_json.get("name").and_then(|v| v.as_str()),
Some("web_search")
);
assert_eq!(
round_tripped_json
.get("allowed_domains")
.and_then(|v| v.as_array())
.map(|a| a.len()),
Some(1)
);
}

#[test]
fn test_web_fetch_20260318_roundtrips_through_universal() {
let tool_json = json!({
"type": "web_fetch_20260318",
"name": "web_fetch",
"blocked_domains": ["evil.com"],
"max_content_tokens": 4096,
"use_cache": false
});

let tool: Tool = serde_json::from_value(tool_json.clone()).expect("should parse");
let universal = UniversalTool::from(&tool);
assert!(universal.is_builtin());

let round_tripped = Tool::try_from(&universal).expect("should convert back");
let round_tripped_json = serde_json::to_value(&round_tripped).expect("should serialize");
assert_eq!(
round_tripped_json.get("type").and_then(|v| v.as_str()),
Some("web_fetch_20260318")
);
assert_eq!(
round_tripped_json.get("name").and_then(|v| v.as_str()),
Some("web_fetch")
);
assert_eq!(
round_tripped_json
.get("max_content_tokens")
.and_then(|v| v.as_i64()),
Some(4096)
);
}

#[test]
fn test_tool_search_variants_still_deserialize() {
for tool_type in [
"tool_search_tool_bm25",
"tool_search_tool_bm25_20251119",
"tool_search_tool_regex",
"tool_search_tool_regex_20251119",
] {
let tool_json = json!({
"type": tool_type,
"name": "tool_search"
});
let tool: Tool = serde_json::from_value(tool_json)
.unwrap_or_else(|e| panic!("{tool_type} should deserialize as Tool variant: {e}"));
let universal = UniversalTool::from(&tool);
assert!(
universal.is_builtin(),
"{tool_type} should map to builtin universal tool"
);
}
}
}
Loading
Loading