Skip to content

Commit a621cf8

Browse files
committed
feat: Add ergonomic Rig framework helpers and comprehensive documentation
- Add rig_validate(), rig_is_valid(), rig_validate_text(), rig_validate_json() - Add RigValidationResult type for cleaner Rig integration - Fix async runtime panics by using proper async functions - Add comprehensive API documentation and migration guide - Update README with AI-first focus and Rig framework emphasis - Add multiple example files showcasing different API levels - Improve async usage documentation with warnings
1 parent 9261063 commit a621cf8

File tree

11 files changed

+1328
-287
lines changed

11 files changed

+1328
-287
lines changed

API_REFERENCE.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
# Credify API Reference
2+
3+
## Table of Contents
4+
5+
- [Ergonomic Rig Functions](#ergonomic-rig-functions)
6+
- [AI-Optimized Functions](#ai-optimized-functions)
7+
- [LLM-Friendly Functions](#llm-friendly-functions)
8+
- [Traditional API](#traditional-api)
9+
- [Types and Structs](#types-and-structs)
10+
- [Error Types](#error-types)
11+
12+
## Ergonomic Rig Functions
13+
14+
These functions are specifically designed for Rig framework integration and AI agents. They are all async and provide clean, simple responses.
15+
16+
### `rig_is_valid`
17+
18+
```rust
19+
pub async fn rig_is_valid(url: &str) -> bool
20+
```
21+
22+
Ultra-simple boolean validation check.
23+
24+
**Example:**
25+
```rust
26+
if rig_is_valid("https://linkedin.com/in/johndoe").await {
27+
println!("Valid profile!");
28+
}
29+
```
30+
31+
### `rig_validate_text`
32+
33+
```rust
34+
pub async fn rig_validate_text(url: &str) -> String
35+
```
36+
37+
Returns a one-line human-readable response perfect for chat interfaces.
38+
39+
**Example responses:**
40+
- `"✅ Valid profile @johndoe (95% confidence)"`
41+
- `"❌ Invalid LinkedIn URL - Search for a different LinkedIn profile URL"`
42+
43+
### `rig_validate_json`
44+
45+
```rust
46+
pub async fn rig_validate_json(url: &str) -> String
47+
```
48+
49+
Returns clean JSON output optimized for tool responses.
50+
51+
**Example:**
52+
```rust
53+
impl Tool for LinkedInValidator {
54+
async fn call(&self, args: Args) -> Result<String, Error> {
55+
Ok(rig_validate_json(&args.url).await)
56+
}
57+
}
58+
```
59+
60+
### `rig_validate`
61+
62+
```rust
63+
pub async fn rig_validate(url: &str) -> RigValidationResult
64+
```
65+
66+
Returns structured validation data with all details.
67+
68+
**Returns:** [`RigValidationResult`](#rigvalidationresult)
69+
70+
## AI-Optimized Functions
71+
72+
These functions provide rich structured data for AI decision-making.
73+
74+
### `ai_validate`
75+
76+
```rust
77+
pub fn ai_validate(url: &str) -> AIValidationResult
78+
```
79+
80+
Synchronous validation returning comprehensive structured data.
81+
82+
**Returns:** [`AIValidationResult`](#aivalidationresult)
83+
84+
### `ai_validate_async`
85+
86+
```rust
87+
pub async fn ai_validate_async(url: &str) -> AIValidationResult
88+
```
89+
90+
Async version of `ai_validate`.
91+
92+
### `ai_validate_json`
93+
94+
```rust
95+
pub fn ai_validate_json(url: &str) -> String
96+
```
97+
98+
Returns AI validation result as JSON string.
99+
100+
### `ai_validate_json_async`
101+
102+
```rust
103+
pub async fn ai_validate_json_async(url: &str) -> String
104+
```
105+
106+
Async version of `ai_validate_json`.
107+
108+
## LLM-Friendly Functions
109+
110+
These functions return verbose text reports designed for LLM consumption.
111+
112+
### `validate_for_llm`
113+
114+
```rust
115+
pub fn validate_for_llm(url: &str) -> String
116+
```
117+
118+
Returns extremely verbose validation report with:
119+
- Timestamps
120+
- Severity levels
121+
- Detailed explanations
122+
- 5-7 suggested actions
123+
- Recommended next steps
124+
125+
### `validate_for_llm_async`
126+
127+
```rust
128+
pub async fn validate_for_llm_async(url: &str) -> String
129+
```
130+
131+
Async version of `validate_for_llm`.
132+
133+
## Traditional API
134+
135+
### `LinkedInValidator`
136+
137+
```rust
138+
pub struct LinkedInValidator { /* private fields */ }
139+
```
140+
141+
Main validator struct for traditional usage.
142+
143+
#### Methods
144+
145+
##### `new`
146+
147+
```rust
148+
pub fn new() -> Result<Self, LinkedInUrlError>
149+
```
150+
151+
Creates a new validator with default settings.
152+
153+
##### `new_with_user_agent`
154+
155+
```rust
156+
pub fn new_with_user_agent(user_agent: &str) -> Result<Self, LinkedInUrlError>
157+
```
158+
159+
Creates a validator with custom user agent.
160+
161+
##### `is_valid_linkedin_profile_url`
162+
163+
```rust
164+
pub fn is_valid_linkedin_profile_url(&self, url: &str) -> Result<bool, LinkedInUrlError>
165+
```
166+
167+
Validates a LinkedIn profile URL with network check.
168+
169+
### Standalone Functions
170+
171+
#### `is_valid_linkedin_profile_format`
172+
173+
```rust
174+
pub fn is_valid_linkedin_profile_format(url: &str) -> bool
175+
```
176+
177+
Checks URL format without network calls.
178+
179+
#### `validate_linkedin_url_async`
180+
181+
```rust
182+
pub async fn validate_linkedin_url_async(url: &str) -> Result<bool, LinkedInUrlError>
183+
```
184+
185+
Async validation with network check.
186+
187+
## Types and Structs
188+
189+
### `RigValidationResult`
190+
191+
```rust
192+
pub struct RigValidationResult {
193+
pub valid: bool, // Simple pass/fail
194+
pub username: Option<String>, // LinkedIn username if found
195+
pub confidence: u8, // 0-100 percentage
196+
pub status: String, // Human-readable status
197+
pub action: String, // Suggested action for AI
198+
}
199+
```
200+
201+
### `AIValidationResult`
202+
203+
```rust
204+
pub struct AIValidationResult {
205+
pub is_valid: bool,
206+
pub confidence: f32, // 0.0 to 1.0
207+
pub decision: AIDecision,
208+
pub username: Option<String>,
209+
pub reason: String,
210+
pub metadata: ValidationMetadata,
211+
}
212+
```
213+
214+
### `AIDecision`
215+
216+
```rust
217+
pub enum AIDecision {
218+
Accept, // Definitely use this URL
219+
Retry, // Temporary issue, try again
220+
Reject, // Invalid URL, search for another
221+
}
222+
```
223+
224+
### `ValidationMetadata`
225+
226+
```rust
227+
pub struct ValidationMetadata {
228+
pub url_format_valid: bool,
229+
pub domain_verified: bool,
230+
pub profile_pattern_matched: bool,
231+
pub http_status: Option<u16>,
232+
pub error_type: Option<String>,
233+
pub timestamp: String,
234+
}
235+
```
236+
237+
## Error Types
238+
239+
### `LinkedInUrlError`
240+
241+
```rust
242+
pub enum LinkedInUrlError {
243+
InvalidUrl(String),
244+
NotLinkedInUrl,
245+
NotProfileUrl,
246+
NetworkError(reqwest::Error),
247+
ProfileNotFound,
248+
AuthenticationRequired,
249+
}
250+
```
251+
252+
| Error | Description |
253+
|-------|-------------|
254+
| `InvalidUrl` | The URL format is invalid |
255+
| `NotLinkedInUrl` | Not a LinkedIn domain |
256+
| `NotProfileUrl` | LinkedIn URL but not a profile |
257+
| `NetworkError` | Network request failed |
258+
| `ProfileNotFound` | Profile doesn't exist (404) |
259+
| `AuthenticationRequired` | LinkedIn requires auth (999) |
260+
261+
## Usage Patterns
262+
263+
### For Rig Tools
264+
265+
```rust
266+
impl Tool for LinkedInValidator {
267+
async fn call(&self, args: Args) -> Result<String, Error> {
268+
// Use ergonomic helper
269+
Ok(rig_validate_json(&args.url).await)
270+
}
271+
}
272+
```
273+
274+
### For AI Decision Making
275+
276+
```rust
277+
let result = ai_validate_async(url).await;
278+
match result.decision {
279+
AIDecision::Accept => use_profile(result.username),
280+
AIDecision::Retry => schedule_retry(),
281+
AIDecision::Reject => search_for_another(),
282+
}
283+
```
284+
285+
### For Simple Checks
286+
287+
```rust
288+
if is_valid_linkedin_profile_format(url) {
289+
// Format is correct, proceed with validation
290+
}
291+
```

0 commit comments

Comments
 (0)