Skip to content

Commit ffb668a

Browse files
authored
Merge pull request #24 from PMDevSolutions/3-api-client-for-cloudflare-workers-chat-endpoint
feat: typed API client with retry, backoff, and debounce
2 parents 4086327 + b43e2a8 commit ffb668a

11 files changed

Lines changed: 1402 additions & 27 deletions

File tree

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ Manages chat state:
110110
- `sendMessage(text)` - Send a message to the API
111111
- `clearMessages()` - Clear chat history
112112

113+
### API Client
114+
115+
`ChatApiClient` in `widget/src/api/client.ts` handles communication with the Worker:
116+
- Typed requests/responses (`ChatRequest`, `ChatResponse`)
117+
- Retry on 429 (respects `Retry-After`) and 503 (exponential backoff: 1s, 3s)
118+
- Max 2 retries (3 total attempts)
119+
- Debounced sends (configurable, default 300ms)
120+
- Typed errors (`ChatApiError` with status/code, `DebounceError`)
121+
113122
### Worker API
114123

115124
| Endpoint | Method | Description |

0 commit comments

Comments
 (0)