Skip to content

Implement rate limiter token utilization exposure and React hook #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
05feb60
Implement rate limiter token utilization exposure and React hook
devin-ai-integration[bot] May 13, 2025
a2a3c56
Change getRateLimit to use queryGeneric instead of async function
devin-ai-integration[bot] May 13, 2025
d01d1bd
Fix type issues in isRateLimitError and queryGeneric implementation
devin-ai-integration[bot] May 13, 2025
3fe83b3
Fix FunctionReference type in useRateLimit hook
devin-ai-integration[bot] May 13, 2025
31fb00d
Add tests for getValue and calculateRateLimit functions
devin-ai-integration[bot] May 13, 2025
23aec20
Add tests for useRateLimit React hook
devin-ai-integration[bot] May 13, 2025
1141ae4
Address PR comments: fix getValue call and specify return type in use…
devin-ai-integration[bot] May 14, 2025
b4f2a1a
Add Vite example app demonstrating useRateLimit hook
devin-ai-integration[bot] May 14, 2025
c2cbc53
Implement clock skew handling with one-time server time mutation
devin-ai-integration[bot] May 14, 2025
9880503
Fix TypeScript errors in implementation
devin-ai-integration[bot] May 14, 2025
671ad3e
Fix TypeScript errors with function arguments and type constraints
devin-ai-integration[bot] May 14, 2025
869f9eb
Fix getValue method parameter handling in index.ts
devin-ai-integration[bot] May 14, 2025
fb329f6
Update convex-test to latest version
devin-ai-integration[bot] May 14, 2025
187d5a0
Fix type mismatch in getter function
devin-ai-integration[bot] May 14, 2025
10ee321
Update example README.md with better documentation
devin-ai-integration[bot] May 14, 2025
4881cbb
Fix TypeScript errors and add tsconfig.node.json
devin-ai-integration[bot] May 14, 2025
c979ebb
Fix TypeScript errors in client/index.ts, component/time.ts, and tsco…
devin-ai-integration[bot] May 14, 2025
90405bb
Update esm.json and commonjs.json to include React types
devin-ai-integration[bot] May 14, 2025
dec7395
Update GitHub workflow to install React types before running tests
devin-ai-integration[bot] May 14, 2025
4931081
Add .npmrc file to fix module resolution in CI
devin-ai-integration[bot] May 14, 2025
2cbb202
Update convex-test to latest version
devin-ai-integration[bot] May 14, 2025
95271d5
Add @types/react and @types/react-dom as dev dependencies
devin-ai-integration[bot] May 14, 2025
53ef9db
Fix TypeScript errors in client/index.ts and component/time.ts
devin-ai-integration[bot] May 14, 2025
d16d8f0
Update convex-test to use caret version range
devin-ai-integration[bot] May 14, 2025
b920112
undo some changes
ianmacartney May 14, 2025
ae84107
fix tests
ianmacartney May 13, 2025
22d12d6
more fixes
ianmacartney May 14, 2025
6f6587c
update api
ianmacartney May 14, 2025
d2c86d4
Update example app to use real Convex API
devin-ai-integration[bot] May 14, 2025
5d31e33
Fix TypeScript errors in client/index.ts and component/time.ts
devin-ai-integration[bot] May 14, 2025
8659531
Fix TypeScript errors in client/index.ts and example/src/convex.ts
devin-ai-integration[bot] May 14, 2025
17978a2
Update example app to use real Convex API with proper hooks
devin-ai-integration[bot] May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update example README.md with better documentation
Co-Authored-By: Ian Macartney <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and ianmacartney committed May 14, 2025
commit 10ee3213d339149f593654ecce71bdcaea61f250
42 changes: 39 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Example app
# Rate Limiter Example App

Components need an app that uses them in order to run codegen. An example app is also useful
for testing and documentation.
This example demonstrates how to use the rate-limiter component's React hook in a Vite application.

## Features

- Demonstrates the `useRateLimit` hook from the rate-limiter component
- Shows how to check available tokens and calculate retry times
- Visualizes token bucket refill over time
- Handles clock skew between client and server

## Getting Started

1. Install dependencies:
```bash
npm install
```

2. Start the development server:
```bash
npm run dev
```

3. Open your browser to the URL shown in the terminal (usually http://localhost:5173)

## How It Works

The example app demonstrates:

- How to use the useRateLimit hook in a React component
- How the hook provides status information (ok, retryAt)
- How to check available tokens and calculate retry times
- How the hook handles token refill over time and clock skew

## Implementation Details

The `useRateLimit` hook:
- Calculates clock skew between client and server using a one-time mutation
- Provides real-time token availability information
- Calculates retry times based on token consumption rate
- Supports both token bucket and fixed window rate limiting strategies