wavespeed 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +22 -0
- package/dist/index.js +37 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,12 +11,23 @@ export type PredictionStatus = 'created' | 'processing' | 'completed' | 'failed'
|
|
|
11
11
|
export interface PredictionUrls {
|
|
12
12
|
get: string;
|
|
13
13
|
}
|
|
14
|
+
export interface UploadFileResp {
|
|
15
|
+
code: number;
|
|
16
|
+
message: string;
|
|
17
|
+
data: {
|
|
18
|
+
type: string;
|
|
19
|
+
download_url: string;
|
|
20
|
+
filename: string;
|
|
21
|
+
size: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
14
24
|
/**
|
|
15
25
|
* Request options for fetch
|
|
16
26
|
*/
|
|
17
27
|
export interface RequestOptions extends RequestInit {
|
|
18
28
|
timeout?: number;
|
|
19
29
|
maxRetries?: number;
|
|
30
|
+
webhook?: string;
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
22
33
|
* Prediction model representing an image generation job
|
|
@@ -93,5 +104,16 @@ export declare class WaveSpeed {
|
|
|
93
104
|
* @param options Additional fetch options
|
|
94
105
|
*/
|
|
95
106
|
create(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>;
|
|
107
|
+
/**
|
|
108
|
+
* Upload a file (binary) to the /media/upload/binary endpoint
|
|
109
|
+
* @param filePath Absolute path to the file to upload
|
|
110
|
+
* @returns The API response JSON
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Upload a file (binary) to the /media/upload/binary endpoint (browser Blob version)
|
|
114
|
+
* @param file Blob to upload
|
|
115
|
+
* @returns The API response JSON
|
|
116
|
+
*/
|
|
117
|
+
upload(file: Blob, options?: RequestOptions): Promise<string>;
|
|
96
118
|
}
|
|
97
119
|
export default WaveSpeed;
|
package/dist/index.js
CHANGED
|
@@ -90,8 +90,8 @@ class WaveSpeed {
|
|
|
90
90
|
if (options.baseUrl) {
|
|
91
91
|
this.baseUrl = options.baseUrl;
|
|
92
92
|
}
|
|
93
|
-
this.pollInterval = options.pollInterval || Number(getEnvVar('WAVESPEED_POLL_INTERVAL')) ||
|
|
94
|
-
this.timeout = options.timeout || Number(getEnvVar('WAVESPEED_TIMEOUT')) ||
|
|
93
|
+
this.pollInterval = options.pollInterval || Number(getEnvVar('WAVESPEED_POLL_INTERVAL')) || 0.5;
|
|
94
|
+
this.timeout = options.timeout || Number(getEnvVar('WAVESPEED_TIMEOUT')) || 120;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Fetch with timeout support
|
|
@@ -198,7 +198,12 @@ class WaveSpeed {
|
|
|
198
198
|
* @param options Additional fetch options
|
|
199
199
|
*/
|
|
200
200
|
async create(modelId, input, options) {
|
|
201
|
-
|
|
201
|
+
// Build URL with webhook if provided in options
|
|
202
|
+
let url = `${modelId}`;
|
|
203
|
+
if (options === null || options === void 0 ? void 0 : options.webhook) {
|
|
204
|
+
url += `?webhook=${options.webhook}`;
|
|
205
|
+
}
|
|
206
|
+
const response = await this.fetchWithTimeout(url, {
|
|
202
207
|
method: 'POST',
|
|
203
208
|
body: JSON.stringify(input),
|
|
204
209
|
...options
|
|
@@ -208,8 +213,37 @@ class WaveSpeed {
|
|
|
208
213
|
throw new Error(`Failed to create prediction: ${response.status} ${errorText}`);
|
|
209
214
|
}
|
|
210
215
|
const data = await response.json();
|
|
216
|
+
if (data.code !== 200) {
|
|
217
|
+
throw new Error(`Failed to create prediction: ${data.code} ${data}`);
|
|
218
|
+
}
|
|
211
219
|
return new Prediction(data.data, this);
|
|
212
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Upload a file (binary) to the /media/upload/binary endpoint
|
|
223
|
+
* @param filePath Absolute path to the file to upload
|
|
224
|
+
* @returns The API response JSON
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* Upload a file (binary) to the /media/upload/binary endpoint (browser Blob version)
|
|
228
|
+
* @param file Blob to upload
|
|
229
|
+
* @returns The API response JSON
|
|
230
|
+
*/
|
|
231
|
+
async upload(file, options) {
|
|
232
|
+
const form = new FormData();
|
|
233
|
+
form.append('file', file);
|
|
234
|
+
// Only set Authorization header; browser will set Content-Type
|
|
235
|
+
const response = await this.fetchWithTimeout('media/upload/binary', {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
body: form,
|
|
238
|
+
...options
|
|
239
|
+
});
|
|
240
|
+
if (!response.ok) {
|
|
241
|
+
const errorText = await response.text();
|
|
242
|
+
throw new Error(`Failed to upload file: ${response.status} ${errorText}`);
|
|
243
|
+
}
|
|
244
|
+
const resp = await response.json();
|
|
245
|
+
return resp.data.download_url;
|
|
246
|
+
}
|
|
213
247
|
}
|
|
214
248
|
exports.WaveSpeed = WaveSpeed;
|
|
215
249
|
// Export default and named exports for different import styles
|