Skip to content

Commit 5a64926

Browse files
Leeon-Tangclaude
andcommitted
feat: add sync mode and retry support
- Add enableSyncMode option for single request without polling - Add configurable retry logic for task-level and connection retries - Update GitHub Actions workflow to separate test, publish and release jobs - Update README with sync mode and retry configuration examples - Add author info to package.json 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 6f3f5f6 commit 5a64926

File tree

6 files changed

+289
-23
lines changed

6 files changed

+289
-23
lines changed

.github/workflows/release.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ on:
66
- 'v*.*.*'
77

88
jobs:
9-
release:
9+
test:
10+
name: Test
1011
runs-on: ubuntu-latest
11-
1212
steps:
1313
- name: Checkout code
1414
uses: actions/checkout@v4
@@ -18,7 +18,6 @@ jobs:
1818
with:
1919
node-version: '18'
2020
cache: 'npm'
21-
registry-url: 'https://registry.npmjs.org'
2221

2322
- name: Install dependencies
2423
run: npm ci
@@ -29,21 +28,57 @@ jobs:
2928
- name: Build project
3029
run: npm run build
3130

31+
publish-npm:
32+
name: Publish to npm
33+
runs-on: ubuntu-latest
34+
needs: test
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v4
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '18'
43+
cache: 'npm'
44+
registry-url: 'https://registry.npmjs.org'
45+
46+
- name: Install dependencies
47+
run: npm ci
48+
49+
- name: Build project
50+
run: npm run build
51+
3252
- name: Publish to npm
3353
run: npm publish
3454
env:
3555
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3656

57+
github-release:
58+
name: Create GitHub Release
59+
runs-on: ubuntu-latest
60+
needs: test
61+
permissions:
62+
contents: write
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
3767
- name: Create GitHub Release
38-
uses: actions/create-release@v1
39-
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
uses: softprops/action-gh-release@v1
4169
with:
42-
tag_name: ${{ github.ref }}
43-
release_name: Release ${{ github.ref }}
70+
name: Release ${{ github.ref_name }}
4471
body: |
45-
Version ${{ github.ref }} has been released.
72+
Version ${{ github.ref_name }} has been released to npm.
73+
74+
## Installation
75+
76+
```bash
77+
npm install wavespeed@${{ github.ref_name }}
78+
```
79+
80+
## Changes
4681
47-
To install: `npm install wavespeed@${{ github.ref }}`
82+
See commit history for changes in this release.
4883
draft: false
4984
prerelease: false

CLAUDE.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
WaveSpeed JavaScript/TypeScript SDK - Official JavaScript/TypeScript SDK for WaveSpeedAI inference platform.
8+
9+
## Commands
10+
11+
### Testing
12+
```bash
13+
# Run all tests
14+
npm test
15+
16+
# Run tests in watch mode
17+
npm run test:watch
18+
19+
# Run tests with coverage
20+
npm run test:coverage
21+
```
22+
23+
### Building
24+
```bash
25+
# Build the TypeScript code
26+
npm run build
27+
28+
# Clean and rebuild
29+
rm -rf dist && npm run build
30+
```
31+
32+
### Development
33+
```bash
34+
# Install dependencies
35+
npm install
36+
37+
# Run linter
38+
npm run lint
39+
40+
# Format code (if configured)
41+
npm run format
42+
```
43+
44+
## Architecture
45+
46+
### Client Structure
47+
48+
Entry point: `new WaveSpeed(apiKey?: string, options?: {...})`
49+
50+
The SDK provides a simple client for running models:
51+
52+
```typescript
53+
const client = new WaveSpeed('your-api-key');
54+
const prediction = await client.run('model-id', input);
55+
```
56+
57+
### Key Classes and Interfaces
58+
59+
- `WaveSpeed` - Main client class
60+
- `Prediction` - Prediction object with status and outputs
61+
- `RunOptions` - Options for run calls
62+
- `UploadFileResp` - Upload response interface
63+
64+
### Features
65+
66+
- **Async/Await**: Modern promise-based API
67+
- **Sync Mode**: Single request that waits for result (`enableSyncMode`)
68+
- **Retry Logic**: Configurable task-level and connection-level retries
69+
- **Timeout Control**: Per-request and overall timeouts
70+
- **File Upload**: Direct file upload to WaveSpeed storage
71+
- **TypeScript Support**: Full type definitions included
72+
73+
### Configuration
74+
75+
Client-level configuration:
76+
- `baseUrl` - API base URL
77+
- `pollInterval` - Polling interval in seconds
78+
- `timeout` - Overall timeout in seconds
79+
- `maxRetries` - Task-level retries
80+
- `maxConnectionRetries` - HTTP connection retries
81+
- `retryInterval` - Base retry delay in seconds
82+
83+
Per-request configuration via `RunOptions`:
84+
- `timeout` - Override timeout
85+
- `pollInterval` - Override poll interval
86+
- `enableSyncMode` - Use sync mode
87+
- `maxRetries` - Override retry count
88+
89+
### Environment Variables
90+
91+
- `WAVESPEED_API_KEY` - API key
92+
- `WAVESPEED_BASE_URL` - Base URL (default: https://api.wavespeed.ai)
93+
- `WAVESPEED_POLL_INTERVAL` - Poll interval in seconds
94+
- `WAVESPEED_TIMEOUT` - Timeout in seconds
95+
- `WAVESPEED_REQUEST_TIMEOUT` - Per-request timeout (internal)
96+
97+
## Project Structure
98+
99+
```
100+
src/
101+
├── index.ts # Main SDK implementation
102+
tests/
103+
├── index.test.ts # Test suite
104+
dist/
105+
├── index.js # Compiled JavaScript
106+
├── index.d.ts # TypeScript definitions
107+
```
108+
109+
## Testing
110+
111+
Tests are located in `tests/` directory and use Jest:
112+
- Client initialization tests
113+
- Run method tests
114+
- Sync mode tests
115+
- Retry logic tests
116+
- Upload functionality tests
117+
118+
## Release Process
119+
120+
This project uses `npm version` with Git tags for versioning. See VERSIONING.md for details.
121+
122+
To create a release:
123+
1. Ensure all changes are committed
124+
2. Bump version: `npm version patch|minor|major`
125+
3. Push changes: `git push origin main --tags`
126+
4. GitHub Actions will automatically publish to npm
127+
128+
## TypeScript
129+
130+
This project is written in TypeScript and provides full type definitions. The TypeScript configuration is in `tsconfig.json`.
131+
132+
Build artifacts are in the `dist/` directory and include both JavaScript and TypeScript declaration files.

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<p>
1313
<a href="https://wavespeed.ai" target="_blank" rel="noopener noreferrer">🌐 Visit wavespeed.ai</a> •
1414
<a href="https://wavespeed.ai/docs">📖 Documentation</a> •
15-
<a href="https://github.com/WaveSpeedAI/client-javascript/issues">💬 Issues</a>
15+
<a href="https://github.com/WaveSpeedAI/wavespeed-javascript/issues">💬 Issues</a>
1616
</p>
1717
</div>
1818

@@ -75,6 +75,40 @@ const client = new WaveSpeed('your-api-key', {
7575
timeout: 36000, // Max wait time in seconds (default: 36000)
7676
pollInterval: 1, // Status check interval (default: 1)
7777
});
78+
79+
const prediction = await client.run('wavespeed-ai/z-image/turbo', {
80+
prompt: 'Cat'
81+
}, {
82+
timeout: 300, // Override timeout for this request
83+
pollInterval: 2, // Override poll interval for this request
84+
enableSyncMode: false, // Single request mode, no polling (default: false)
85+
});
86+
```
87+
88+
### Sync Mode
89+
90+
Use `enableSyncMode: true` for a single request that waits for the result (no polling).
91+
92+
> **Note:** Not all models support sync mode. Check the model documentation for availability.
93+
94+
```javascript
95+
const prediction = await client.run('wavespeed-ai/z-image/turbo', {
96+
prompt: 'Cat'
97+
}, {
98+
enableSyncMode: true
99+
});
100+
```
101+
102+
### Retry Configuration
103+
104+
Configure retries at the client level:
105+
106+
```javascript
107+
const client = new WaveSpeed('your-api-key', {
108+
maxRetries: 0, // Task-level retries (default: 0)
109+
maxConnectionRetries: 3, // HTTP connection retries (default: 3)
110+
retryInterval: 1, // Base delay between retries in seconds (default: 1)
111+
});
78112
```
79113

80114
### Upload Files

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"sdk",
1919
"wavespeed"
2020
],
21-
"author": "",
21+
"author": "WaveSpeedAI <support@wavespeed.ai>",
2222
"license": "MIT",
2323
"repository": {
2424
"type": "git",

0 commit comments

Comments
 (0)