Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(rust-sdk): accept negative creditsUsed in crawl and batch scrape status (#4578)
Gaurav Rawate847d994264f
diff --git a/apps/rust-sdk/src/batch_scrape.rs b/apps/rust-sdk/src/batch_scrape.rsindex 84d0d30c6..672c3ea45 100644--- a/apps/rust-sdk/src/batch_scrape.rs+++ b/apps/rust-sdk/src/batch_scrape.rs@@ -83,8 +83,8 @@ pub struct BatchScrapeJob {pub completed: u32,/// Total number of URLs to scrape.pub total: u32,- /// Credits used by the batch scrape.- pub credits_used: Option<u32>,+ /// Credits used by the batch scrape; `-1` when no billing record exists.+ pub credits_used: Option<i64>,/// Expiry time of the batch data.pub expires_at: Option<String>,/// URL for the next page of results.@@ -484,6 +484,40 @@ mod tests {mock.assert();}+ #[tokio::test]+ async fn test_get_batch_scrape_status_accepts_negative_credits_used() {+ // Self-hosted instances without a billing record report creditsUsed: -1.+ let mut server = mockito::Server::new_async().await;++ let mock = server+ .mock("GET", "/v2/batch/scrape/batch-selfhosted")+ .with_status(200)+ .with_header("content-type", "application/json")+ .with_body(+ json!({+ "success": true,+ "status": "completed",+ "total": 1,+ "completed": 1,+ "creditsUsed": -1,+ "data": [{ "markdown": "# Page" }]+ })+ .to_string(),+ )+ .create();++ let client = Client::new_selfhosted(server.url(), None::<&str>).unwrap();+ let status = client+ .get_batch_scrape_status("batch-selfhosted")+ .await+ .unwrap();++ assert_eq!(status.status, JobStatus::Completed);+ assert_eq!(status.credits_used, Some(-1));+ assert_eq!(status.data.len(), 1);+ mock.assert();+ }+#[tokio::test]async fn test_batch_scrape_with_invalid_urls() {let mut server = mockito::Server::new_async().await;diff --git a/apps/rust-sdk/src/crawl.rs b/apps/rust-sdk/src/crawl.rsindex e9c8fba2b..25de1f293 100644--- a/apps/rust-sdk/src/crawl.rs+++ b/apps/rust-sdk/src/crawl.rs@@ -105,8 +105,8 @@ pub struct CrawlJob {pub total: u32,/// Number of pages completed.pub completed: u32,- /// Credits used by the crawl.- pub credits_used: Option<u32>,+ /// Credits used by the crawl; `-1` when no billing record exists.+ pub credits_used: Option<i64>,/// Expiry time of the crawl data.pub expires_at: Option<String>,/// URL for the next page of results.@@ -537,6 +537,38 @@ mod tests {mock.assert();}+ #[tokio::test]+ async fn test_get_crawl_status_accepts_negative_credits_used() {+ // Self-hosted instances without a billing record report creditsUsed: -1.+ let mut server = mockito::Server::new_async().await;++ let mock = server+ .mock("GET", "/v2/crawl/crawl-selfhosted")+ .with_status(200)+ .with_header("content-type", "application/json")+ .with_body(+ json!({+ "success": true,+ "status": "completed",+ "total": 1,+ "completed": 1,+ "creditsUsed": -1,+ "expiresAt": "2024-12-31T23:59:59Z",+ "data": [{ "markdown": "# Page" }]+ })+ .to_string(),+ )+ .create();++ let client = Client::new_selfhosted(server.url(), None::<&str>).unwrap();+ let status = client.get_crawl_status("crawl-selfhosted").await.unwrap();++ assert_eq!(status.status, JobStatus::Completed);+ assert_eq!(status.credits_used, Some(-1));+ assert_eq!(status.data.len(), 1);+ mock.assert();+ }+#[tokio::test]async fn test_cancel_crawl_with_mock() {let mut server = mockito::Server::new_async().await;