Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Duration, Schedule } from 'effect'; |
| 2 | |
| 3 | /** |
| 4 | * How long `composio login` and `composio link` wait for the person to finish in the browser. |
| 5 | * It is also the lifetime of a pending login, which `composio login --poll` waits out. |
| 6 | */ |
| 7 | export const AUTHORIZATION_TIMEOUT_MINUTES = 10; |
| 8 | |
| 9 | /** |
| 10 | * The default wait, and the longest one `composio login --poll --timeout` accepts: a longer |
| 11 | * wait outlives the pending login it waits for. |
| 12 | */ |
| 13 | export const AUTHORIZATION_TIMEOUT_SECONDS = AUTHORIZATION_TIMEOUT_MINUTES * 60; |
| 14 | |
| 15 | /** The longest wait between two checks, once the ramp has reached it. */ |
| 16 | export const AUTHORIZATION_POLL_INTERVAL_SECONDS = 5; |
| 17 | |
| 18 | /** |
| 19 | * When to check a pending authorization again: after 0.3s, doubling until one check every |
| 20 | * `AUTHORIZATION_POLL_INTERVAL_SECONDS`, for `timeoutSeconds` in all. |
| 21 | * |
| 22 | * `Schedule.min` waits for the shorter of the ramp and the spacing, which caps the ramp. |
| 23 | * (`Schedule.max` would wait for the longer one, and the ramp keeps doubling: fifteen checks |
| 24 | * that way take hours.) `Schedule.max` with `Schedule.during`, whose delay is zero, keeps those |
| 25 | * delays and stops once the time is up — after one more check, since the deadline is noticed |
| 26 | * after the delay that reaches it. A wait can therefore overshoot its bound by one poll |
| 27 | * interval. |
| 28 | */ |
| 29 | export const authorizationPollScheduleFor = (timeoutSeconds: number) => |
| 30 | Schedule.max([ |
| 31 | Schedule.min([ |
| 32 | Schedule.exponential('0.3 seconds'), |
| 33 | Schedule.spaced(`${AUTHORIZATION_POLL_INTERVAL_SECONDS} seconds`), |
| 34 | ]), |
| 35 | Schedule.during(Duration.seconds(timeoutSeconds)), |
| 36 | ]); |
| 37 | |
| 38 | /** The schedule a wait keeps when its caller asks for no particular bound. */ |
| 39 | export const authorizationPollSchedule = authorizationPollScheduleFor( |
| 40 | AUTHORIZATION_TIMEOUT_SECONDS |
| 41 | ); |