feat: add wait_until_database_online helper for knowledge base databa… #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements
wait_until_database_online()method for polling knowledge base database creation status, following the established pattern ofagents.wait_until_ready().Changes Made
1. New Exception Classes (
src/gradient/_exceptions.py)Added two new exception types for database polling:
KnowledgeBaseDatabaseError: Raised when database creation fails with terminal statusKnowledgeBaseDatabaseTimeoutError: Raised when polling exceeds timeout limitBoth exceptions store relevant identifiers for debugging:
statusattribute onKnowledgeBaseDatabaseErrorknowledge_base_idattribute onKnowledgeBaseDatabaseTimeoutError2. Resource Methods (
src/gradient/resources/knowledge_bases/knowledge_bases.py)Synchronous Method
Asynchronous Method
Behavior:
retrieve(uuid)untildatabase_status == "ONLINE"KnowledgeBaseRetrieveResponseKnowledgeBaseDatabaseErroron terminal status ("DECOMMISSIONED", "UNHEALTHY")KnowledgeBaseDatabaseTimeoutErrorif exceededValueErroron empty UUID3. Wrapper Classes
Updated all four wrapper classes to expose the new method:
KnowledgeBasesResourceWithRawResponseAsyncKnowledgeBasesResourceWithRawResponseKnowledgeBasesResourceWithStreamingResponseAsyncKnowledgeBasesResourceWithStreamingResponseEnables usage patterns:
4. Comprehensive Tests (
tests/api_resources/test_knowledge_bases.py)Synchronous Tests (4):
test_method_wait_until_database_online: Success path with status progressiontest_wait_until_database_online_timeout: Timeout handlingtest_wait_until_database_online_failed: Failure status handling (UNHEALTHY)test_wait_until_database_online_empty_uuid: Input validationAsynchronous Tests (4):
Test Characteristics:
respx_mockto simulate server responsesagents.wait_until_readytestsImplementation Details
Polling Logic
Key Design Decisions
agents.wait_until_ready()for familiarityextra_headers,extra_query,extra_bodyfor consistencyTesting & Validation
✓ Code Quality Checks
✓ Functional Tests
✓ Integration
import timefor polling functionalityimport httpxfor test mock responsesFiles Modified
src/gradient/_exceptions.py- Added 2 exception classessrc/gradient/resources/knowledge_bases/knowledge_bases.py- Added sync/async methods + wrapperstests/api_resources/test_knowledge_bases.py- Added 8 unit teststests/api_resources/test_agents.py,examples/agent_wait_until_ready.pyCommit Information
feat: add wait_until_database_online helper for knowledge base database pollingUsage Example
Async Example
Related Issue
Closes #42