1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Utility modules for AI API handling
//!
//! These utilities provide robust handling for common AI API edge cases:
//! - Unicode sanitization for safe JSON serialization
//! - JSON parsing with repair for malformed streaming responses
//! - Context overflow detection across providers
//! - Tool call ID normalization for cross-provider compatibility
/// Normalize a tool call ID for cross-provider compatibility.
///
/// OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
/// Anthropic APIs require IDs matching `^[a-zA-Z0-9_-]+$` (max 64 chars).
///
/// This replaces non-alphanumeric (except `_` and `-`) chars with `_` and
/// truncates to 64 characters.