Skip to content

Conversation

sathwik-14
Copy link

The helper does interval based polling for checking agent rediness.

This is needed to avoid running tight loops & respect API rate limits

Example

const agent = await waitForAgentReady(client, 'agent-123', {
timeout: 60000, // 1 minute
onUpdate: (status, elapsed) => {
console.log(`Status: ${status} (${elapsed}ms elapsed)`);
}
});

Edge Cases Handled

  • Graceful Cancellation: Supports AbortSignal for canceling long-running polls
  • Timeout Protection: Prevents infinite polling with configurable timeout (default: 3 minutes), checking before each API call to respect time bounds
  • Deployment Failures: Detects terminal failure states (STATUS_FAILED, STATUS_UNDEPLOYMENT_FAILED) and throws structured errors
  • Transitional States: Continues polling through intermediate deployment states without false positives
  • Network Errors: API failures propagate to caller, allowing custom retry/error handling strategies
  • Structured Error Types: Custom AgentTimeoutError and AgentDeploymentError classes enable type-safe error handling with accessible metadata
  • Concurrent Polling: Stateless implementation supports multiple independent polls of the same agent
  • Progress Monitoring: Optional onUpdate callback provides real-time status updates for UI/logging integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant