@acedatacloud/sdk 2026.322.1 → 2026.418.1
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/README.md +28 -0
- package/dist/index.d.mts +336 -0
- package/dist/index.d.ts +336 -4
- package/dist/index.js +713 -19
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +665 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -2
- package/src/index.ts +4 -0
- package/src/resources/audio.ts +6 -3
- package/src/resources/images.ts +7 -3
- package/src/resources/tasks.ts +6 -0
- package/src/resources/video.ts +6 -3
- package/dist/client.d.ts +0 -31
- package/dist/client.js +0 -46
- package/dist/resources/audio.d.ts +0 -17
- package/dist/resources/audio.js +0 -30
- package/dist/resources/chat.d.ts +0 -30
- package/dist/resources/chat.js +0 -38
- package/dist/resources/files.d.ts +0 -9
- package/dist/resources/files.js +0 -59
- package/dist/resources/images.d.ts +0 -18
- package/dist/resources/images.js +0 -32
- package/dist/resources/openai.d.ts +0 -46
- package/dist/resources/openai.js +0 -59
- package/dist/resources/platform.d.ts +0 -41
- package/dist/resources/platform.js +0 -76
- package/dist/resources/search.d.ts +0 -14
- package/dist/resources/search.js +0 -22
- package/dist/resources/tasks.d.ts +0 -14
- package/dist/resources/tasks.js +0 -36
- package/dist/resources/video.d.ts +0 -17
- package/dist/resources/video.js +0 -30
- package/dist/runtime/errors.d.ts +0 -44
- package/dist/runtime/errors.js +0 -89
- package/dist/runtime/index.d.ts +0 -3
- package/dist/runtime/index.js +0 -19
- package/dist/runtime/tasks.d.ts +0 -17
- package/dist/runtime/tasks.js +0 -46
- package/dist/runtime/transport.d.ts +0 -31
- package/dist/runtime/transport.js +0 -213
package/dist/index.js
CHANGED
|
@@ -1,20 +1,714 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
APIError: () => APIError,
|
|
34
|
+
AceDataCloud: () => AceDataCloud,
|
|
35
|
+
AceDataCloudError: () => AceDataCloudError,
|
|
36
|
+
AuthenticationError: () => AuthenticationError,
|
|
37
|
+
InsufficientBalanceError: () => InsufficientBalanceError,
|
|
38
|
+
ModerationError: () => ModerationError,
|
|
39
|
+
RateLimitError: () => RateLimitError,
|
|
40
|
+
ResourceDisabledError: () => ResourceDisabledError,
|
|
41
|
+
TaskHandle: () => TaskHandle,
|
|
42
|
+
TimeoutError: () => TimeoutError,
|
|
43
|
+
TokenMismatchError: () => TokenMismatchError,
|
|
44
|
+
TransportError: () => TransportError,
|
|
45
|
+
ValidationError: () => ValidationError
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
48
|
+
|
|
49
|
+
// src/runtime/errors.ts
|
|
50
|
+
var AceDataCloudError = class extends Error {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "AceDataCloudError";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var TransportError = class extends AceDataCloudError {
|
|
57
|
+
constructor(message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = "TransportError";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var APIError = class extends AceDataCloudError {
|
|
63
|
+
statusCode;
|
|
64
|
+
code;
|
|
65
|
+
traceId;
|
|
66
|
+
body;
|
|
67
|
+
constructor(opts) {
|
|
68
|
+
super(opts.message);
|
|
69
|
+
this.name = "APIError";
|
|
70
|
+
this.statusCode = opts.statusCode;
|
|
71
|
+
this.code = opts.code;
|
|
72
|
+
this.traceId = opts.traceId;
|
|
73
|
+
this.body = opts.body ?? {};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var AuthenticationError = class extends APIError {
|
|
77
|
+
constructor(opts) {
|
|
78
|
+
super(opts);
|
|
79
|
+
this.name = "AuthenticationError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var TokenMismatchError = class extends APIError {
|
|
83
|
+
constructor(opts) {
|
|
84
|
+
super(opts);
|
|
85
|
+
this.name = "TokenMismatchError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var RateLimitError = class extends APIError {
|
|
89
|
+
constructor(opts) {
|
|
90
|
+
super(opts);
|
|
91
|
+
this.name = "RateLimitError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var ValidationError = class extends APIError {
|
|
95
|
+
constructor(opts) {
|
|
96
|
+
super(opts);
|
|
97
|
+
this.name = "ValidationError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var InsufficientBalanceError = class extends APIError {
|
|
101
|
+
constructor(opts) {
|
|
102
|
+
super(opts);
|
|
103
|
+
this.name = "InsufficientBalanceError";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var ResourceDisabledError = class extends APIError {
|
|
107
|
+
constructor(opts) {
|
|
108
|
+
super(opts);
|
|
109
|
+
this.name = "ResourceDisabledError";
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var ModerationError = class extends APIError {
|
|
113
|
+
constructor(opts) {
|
|
114
|
+
super(opts);
|
|
115
|
+
this.name = "ModerationError";
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var TimeoutError = class extends APIError {
|
|
119
|
+
constructor(opts) {
|
|
120
|
+
super(opts);
|
|
121
|
+
this.name = "TimeoutError";
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/runtime/transport.ts
|
|
126
|
+
var ERROR_CODE_MAP = {
|
|
127
|
+
invalid_token: AuthenticationError,
|
|
128
|
+
token_expired: AuthenticationError,
|
|
129
|
+
no_token: AuthenticationError,
|
|
130
|
+
token_mismatched: TokenMismatchError,
|
|
131
|
+
used_up: InsufficientBalanceError,
|
|
132
|
+
disabled: ResourceDisabledError,
|
|
133
|
+
too_many_requests: RateLimitError,
|
|
134
|
+
bad_request: ValidationError
|
|
135
|
+
};
|
|
136
|
+
var RETRY_STATUS_CODES = /* @__PURE__ */ new Set([408, 409, 429, 500, 502, 503, 504]);
|
|
137
|
+
function mapError(statusCode, body) {
|
|
138
|
+
const errorData = body.error ?? {};
|
|
139
|
+
const code = errorData.code ?? "";
|
|
140
|
+
const message = errorData.message ?? "";
|
|
141
|
+
const traceId = body.trace_id;
|
|
142
|
+
let ErrorClass = ERROR_CODE_MAP[code];
|
|
143
|
+
if (!ErrorClass) {
|
|
144
|
+
if (statusCode === 403) ErrorClass = ModerationError;
|
|
145
|
+
else if (statusCode === 401) ErrorClass = AuthenticationError;
|
|
146
|
+
else if (statusCode === 429) ErrorClass = RateLimitError;
|
|
147
|
+
else if (statusCode === 400) ErrorClass = ValidationError;
|
|
148
|
+
else ErrorClass = APIError;
|
|
149
|
+
}
|
|
150
|
+
return new ErrorClass({ message, statusCode, code, traceId, body });
|
|
151
|
+
}
|
|
152
|
+
function backoffDelay(attempt) {
|
|
153
|
+
const base = Math.min(2 ** attempt, 8);
|
|
154
|
+
return base + Math.random() * 0.5;
|
|
155
|
+
}
|
|
156
|
+
function sleep(ms) {
|
|
157
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
158
|
+
}
|
|
159
|
+
var Transport = class {
|
|
160
|
+
baseURL;
|
|
161
|
+
platformBaseURL;
|
|
162
|
+
timeout;
|
|
163
|
+
maxRetries;
|
|
164
|
+
headers;
|
|
165
|
+
constructor(opts = {}) {
|
|
166
|
+
const token = opts.apiToken ?? process.env.ACEDATACLOUD_API_TOKEN ?? "";
|
|
167
|
+
if (!token) {
|
|
168
|
+
throw new AuthenticationError({
|
|
169
|
+
message: "apiToken is required. Pass it to the client or set ACEDATACLOUD_API_TOKEN.",
|
|
170
|
+
statusCode: 0,
|
|
171
|
+
code: "no_token"
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
this.baseURL = (opts.baseURL ?? "https://api.acedata.cloud").replace(/\/+$/, "");
|
|
175
|
+
this.platformBaseURL = (opts.platformBaseURL ?? "https://platform.acedata.cloud").replace(/\/+$/, "");
|
|
176
|
+
this.timeout = opts.timeout ?? 3e5;
|
|
177
|
+
this.maxRetries = opts.maxRetries ?? 2;
|
|
178
|
+
this.headers = {
|
|
179
|
+
accept: "application/json",
|
|
180
|
+
authorization: `Bearer ${token}`,
|
|
181
|
+
"content-type": "application/json",
|
|
182
|
+
"user-agent": "acedatacloud-node/0.1.0",
|
|
183
|
+
...opts.headers ?? {}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async request(method, path2, opts = {}) {
|
|
187
|
+
const base = opts.platform ? this.platformBaseURL : this.baseURL;
|
|
188
|
+
let url = `${base}${path2}`;
|
|
189
|
+
if (opts.params) {
|
|
190
|
+
const qs = new URLSearchParams(opts.params).toString();
|
|
191
|
+
url += `?${qs}`;
|
|
192
|
+
}
|
|
193
|
+
const headers = { ...this.headers, ...opts.headers ?? {} };
|
|
194
|
+
const timeoutMs = opts.timeout ?? this.timeout;
|
|
195
|
+
let lastError = null;
|
|
196
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
197
|
+
const controller = new AbortController();
|
|
198
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
199
|
+
try {
|
|
200
|
+
const resp = await fetch(url, {
|
|
201
|
+
method,
|
|
202
|
+
headers,
|
|
203
|
+
body: opts.json ? JSON.stringify(opts.json) : void 0,
|
|
204
|
+
signal: controller.signal
|
|
205
|
+
});
|
|
206
|
+
clearTimeout(timer);
|
|
207
|
+
if (resp.status >= 400) {
|
|
208
|
+
const text = await resp.text();
|
|
209
|
+
let body;
|
|
210
|
+
try {
|
|
211
|
+
body = JSON.parse(text);
|
|
212
|
+
} catch {
|
|
213
|
+
body = { error: { code: "unknown", message: text } };
|
|
214
|
+
}
|
|
215
|
+
if (RETRY_STATUS_CODES.has(resp.status) && attempt < this.maxRetries) {
|
|
216
|
+
await sleep(backoffDelay(attempt) * 1e3);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
throw mapError(resp.status, body);
|
|
220
|
+
}
|
|
221
|
+
return await resp.json();
|
|
222
|
+
} catch (err) {
|
|
223
|
+
clearTimeout(timer);
|
|
224
|
+
if (err instanceof APIError) throw err;
|
|
225
|
+
lastError = err;
|
|
226
|
+
if (attempt < this.maxRetries) {
|
|
227
|
+
await sleep(backoffDelay(attempt) * 1e3);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
throw lastError ?? new TransportError("Request failed after retries");
|
|
233
|
+
}
|
|
234
|
+
async *requestStream(method, path2, opts = {}) {
|
|
235
|
+
const url = `${this.baseURL}${path2}`;
|
|
236
|
+
const headers = { ...this.headers, accept: "text/event-stream" };
|
|
237
|
+
const controller = new AbortController();
|
|
238
|
+
const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
|
|
239
|
+
try {
|
|
240
|
+
const resp = await fetch(url, {
|
|
241
|
+
method,
|
|
242
|
+
headers,
|
|
243
|
+
body: opts.json ? JSON.stringify(opts.json) : void 0,
|
|
244
|
+
signal: controller.signal
|
|
245
|
+
});
|
|
246
|
+
if (resp.status >= 400) {
|
|
247
|
+
const text = await resp.text();
|
|
248
|
+
let body;
|
|
249
|
+
try {
|
|
250
|
+
body = JSON.parse(text);
|
|
251
|
+
} catch {
|
|
252
|
+
body = { error: { code: "unknown", message: text } };
|
|
253
|
+
}
|
|
254
|
+
throw mapError(resp.status, body);
|
|
255
|
+
}
|
|
256
|
+
if (!resp.body) throw new TransportError("No response body for stream");
|
|
257
|
+
const reader = resp.body.getReader();
|
|
258
|
+
const decoder = new TextDecoder();
|
|
259
|
+
let buffer = "";
|
|
260
|
+
while (true) {
|
|
261
|
+
const { done, value } = await reader.read();
|
|
262
|
+
if (done) break;
|
|
263
|
+
buffer += decoder.decode(value, { stream: true });
|
|
264
|
+
const lines = buffer.split("\n");
|
|
265
|
+
buffer = lines.pop() ?? "";
|
|
266
|
+
for (const line of lines) {
|
|
267
|
+
if (line.startsWith("data: ")) {
|
|
268
|
+
const data = line.slice(6);
|
|
269
|
+
if (data === "[DONE]") return;
|
|
270
|
+
yield data;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} finally {
|
|
275
|
+
clearTimeout(timer);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async upload(path2, fileData, filename, opts = {}) {
|
|
279
|
+
const url = `${this.platformBaseURL}${path2}`;
|
|
280
|
+
const boundary = `----AceDataCloudBoundary${Date.now()}`;
|
|
281
|
+
const headers = {
|
|
282
|
+
...this.headers,
|
|
283
|
+
"content-type": `multipart/form-data; boundary=${boundary}`
|
|
284
|
+
};
|
|
285
|
+
delete headers["content-type"];
|
|
286
|
+
const body = new FormData();
|
|
287
|
+
body.append("file", new Blob([fileData]), filename);
|
|
288
|
+
const authHeaders = {
|
|
289
|
+
authorization: this.headers.authorization,
|
|
290
|
+
"user-agent": this.headers["user-agent"]
|
|
291
|
+
};
|
|
292
|
+
const controller = new AbortController();
|
|
293
|
+
const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
|
|
294
|
+
try {
|
|
295
|
+
const resp = await fetch(url, {
|
|
296
|
+
method: "POST",
|
|
297
|
+
headers: authHeaders,
|
|
298
|
+
body,
|
|
299
|
+
signal: controller.signal
|
|
300
|
+
});
|
|
301
|
+
clearTimeout(timer);
|
|
302
|
+
if (resp.status >= 400) {
|
|
303
|
+
const text = await resp.text();
|
|
304
|
+
let respBody;
|
|
305
|
+
try {
|
|
306
|
+
respBody = JSON.parse(text);
|
|
307
|
+
} catch {
|
|
308
|
+
respBody = { error: { code: "unknown", message: text } };
|
|
309
|
+
}
|
|
310
|
+
throw mapError(resp.status, respBody);
|
|
311
|
+
}
|
|
312
|
+
return await resp.json();
|
|
313
|
+
} finally {
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// src/resources/chat.ts
|
|
320
|
+
var Messages = class {
|
|
321
|
+
constructor(transport) {
|
|
322
|
+
this.transport = transport;
|
|
323
|
+
}
|
|
324
|
+
transport;
|
|
325
|
+
async create(opts) {
|
|
326
|
+
const { model, messages, maxTokens = 4096, stream, ...rest } = opts;
|
|
327
|
+
const body = { model, messages, max_tokens: maxTokens, ...rest };
|
|
328
|
+
if (stream) {
|
|
329
|
+
body.stream = true;
|
|
330
|
+
return this.stream(body);
|
|
331
|
+
}
|
|
332
|
+
return this.transport.request("POST", "/v1/messages", { json: body });
|
|
333
|
+
}
|
|
334
|
+
async *stream(body) {
|
|
335
|
+
for await (const chunk of this.transport.requestStream("POST", "/v1/messages", { json: body })) {
|
|
336
|
+
yield JSON.parse(chunk);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async countTokens(opts) {
|
|
340
|
+
const { model, messages, ...rest } = opts;
|
|
341
|
+
return this.transport.request("POST", "/v1/messages/count_tokens", {
|
|
342
|
+
json: { model, messages, ...rest }
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var Chat = class {
|
|
347
|
+
messages;
|
|
348
|
+
constructor(transport) {
|
|
349
|
+
this.messages = new Messages(transport);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/runtime/tasks.ts
|
|
354
|
+
var TaskHandle = class {
|
|
355
|
+
id;
|
|
356
|
+
pollEndpoint;
|
|
357
|
+
transport;
|
|
358
|
+
_result = null;
|
|
359
|
+
constructor(taskId, pollEndpoint, transport) {
|
|
360
|
+
this.id = taskId;
|
|
361
|
+
this.pollEndpoint = pollEndpoint;
|
|
362
|
+
this.transport = transport;
|
|
363
|
+
}
|
|
364
|
+
async get() {
|
|
365
|
+
return this.transport.request("POST", this.pollEndpoint, {
|
|
366
|
+
json: { id: this.id, action: "retrieve" }
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async isCompleted() {
|
|
370
|
+
const state = await this.get();
|
|
371
|
+
const response = state.response ?? state;
|
|
372
|
+
const status = response.status;
|
|
373
|
+
return status === "succeeded" || status === "failed";
|
|
374
|
+
}
|
|
375
|
+
async wait(opts = {}) {
|
|
376
|
+
const pollInterval = opts.pollInterval ?? 3e3;
|
|
377
|
+
const maxWait = opts.maxWait ?? 6e5;
|
|
378
|
+
const start = Date.now();
|
|
379
|
+
while (Date.now() - start < maxWait) {
|
|
380
|
+
const state = await this.get();
|
|
381
|
+
const response = state.response ?? state;
|
|
382
|
+
const status = response.status;
|
|
383
|
+
if (status === "succeeded" || status === "failed") {
|
|
384
|
+
this._result = state;
|
|
385
|
+
return state;
|
|
386
|
+
}
|
|
387
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
388
|
+
}
|
|
389
|
+
throw new Error(`Task ${this.id} did not complete within ${maxWait}ms`);
|
|
390
|
+
}
|
|
391
|
+
get result() {
|
|
392
|
+
return this._result;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/resources/images.ts
|
|
397
|
+
var Images = class {
|
|
398
|
+
constructor(transport) {
|
|
399
|
+
this.transport = transport;
|
|
400
|
+
}
|
|
401
|
+
transport;
|
|
402
|
+
async generate(opts) {
|
|
403
|
+
const { prompt, provider = "nano-banana", model, negativePrompt, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
|
|
404
|
+
const body = { prompt, ...rest };
|
|
405
|
+
if (model !== void 0) body.model = model;
|
|
406
|
+
if (negativePrompt !== void 0) body.negative_prompt = negativePrompt;
|
|
407
|
+
if (imageUrl !== void 0) body.image_url = imageUrl;
|
|
408
|
+
if (callbackUrl !== void 0) body.callback_url = callbackUrl;
|
|
409
|
+
const endpoint = provider === "midjourney" ? "/midjourney/imagine" : `/${provider}/images`;
|
|
410
|
+
const result = await this.transport.request("POST", endpoint, { json: body });
|
|
411
|
+
const taskId = result.task_id;
|
|
412
|
+
if (!taskId || result.data && !shouldWait) return result;
|
|
413
|
+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
|
|
414
|
+
if (shouldWait) return handle.wait({ pollInterval, maxWait });
|
|
415
|
+
return handle;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// src/resources/audio.ts
|
|
420
|
+
var Audio = class {
|
|
421
|
+
constructor(transport) {
|
|
422
|
+
this.transport = transport;
|
|
423
|
+
}
|
|
424
|
+
transport;
|
|
425
|
+
async generate(opts) {
|
|
426
|
+
const { prompt, provider = "suno", model, tags, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
|
|
427
|
+
const body = { prompt, ...rest };
|
|
428
|
+
if (model !== void 0) body.model = model;
|
|
429
|
+
if (tags !== void 0) body.tags = tags;
|
|
430
|
+
if (callbackUrl !== void 0) body.callback_url = callbackUrl;
|
|
431
|
+
const result = await this.transport.request("POST", `/${provider}/audios`, { json: body });
|
|
432
|
+
const taskId = result.task_id;
|
|
433
|
+
if (!taskId || result.data && !shouldWait) return result;
|
|
434
|
+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
|
|
435
|
+
if (shouldWait) return handle.wait({ pollInterval, maxWait });
|
|
436
|
+
return handle;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/resources/video.ts
|
|
441
|
+
var Video = class {
|
|
442
|
+
constructor(transport) {
|
|
443
|
+
this.transport = transport;
|
|
444
|
+
}
|
|
445
|
+
transport;
|
|
446
|
+
async generate(opts) {
|
|
447
|
+
const { prompt, provider = "sora", model, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
|
|
448
|
+
const body = { prompt, ...rest };
|
|
449
|
+
if (model !== void 0) body.model = model;
|
|
450
|
+
if (imageUrl !== void 0) body.image_url = imageUrl;
|
|
451
|
+
if (callbackUrl !== void 0) body.callback_url = callbackUrl;
|
|
452
|
+
const result = await this.transport.request("POST", `/${provider}/videos`, { json: body });
|
|
453
|
+
const taskId = result.task_id;
|
|
454
|
+
if (!taskId || result.data && !shouldWait) return result;
|
|
455
|
+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
|
|
456
|
+
if (shouldWait) return handle.wait({ pollInterval, maxWait });
|
|
457
|
+
return handle;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/resources/search.ts
|
|
462
|
+
var Search = class {
|
|
463
|
+
constructor(transport) {
|
|
464
|
+
this.transport = transport;
|
|
465
|
+
}
|
|
466
|
+
transport;
|
|
467
|
+
async google(opts) {
|
|
468
|
+
const { query, type = "search", country, language, page, ...rest } = opts;
|
|
469
|
+
const body = { query, type, ...rest };
|
|
470
|
+
if (country !== void 0) body.country = country;
|
|
471
|
+
if (language !== void 0) body.language = language;
|
|
472
|
+
if (page !== void 0) body.page = page;
|
|
473
|
+
return this.transport.request("POST", "/serp/google", { json: body });
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
// src/resources/tasks.ts
|
|
478
|
+
var SERVICE_TASK_ENDPOINTS = {
|
|
479
|
+
suno: "/suno/tasks",
|
|
480
|
+
producer: "/producer/tasks",
|
|
481
|
+
"nano-banana": "/nano-banana/tasks",
|
|
482
|
+
seedream: "/seedream/tasks",
|
|
483
|
+
seedance: "/seedance/tasks",
|
|
484
|
+
sora: "/sora/tasks",
|
|
485
|
+
midjourney: "/midjourney/tasks",
|
|
486
|
+
luma: "/luma/tasks",
|
|
487
|
+
veo: "/veo/tasks",
|
|
488
|
+
flux: "/flux/tasks",
|
|
489
|
+
kling: "/kling/tasks",
|
|
490
|
+
hailuo: "/hailuo/tasks",
|
|
491
|
+
wan: "/wan/tasks",
|
|
492
|
+
pika: "/pika/tasks",
|
|
493
|
+
pixverse: "/pixverse/tasks"
|
|
494
|
+
};
|
|
495
|
+
var Tasks = class {
|
|
496
|
+
constructor(transport) {
|
|
497
|
+
this.transport = transport;
|
|
498
|
+
}
|
|
499
|
+
transport;
|
|
500
|
+
async get(taskId, opts = {}) {
|
|
501
|
+
const service = opts.service ?? "suno";
|
|
502
|
+
const endpoint = SERVICE_TASK_ENDPOINTS[service] ?? `/${service}/tasks`;
|
|
503
|
+
return this.transport.request("POST", endpoint, {
|
|
504
|
+
json: { id: taskId, action: "retrieve" }
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
async wait(taskId, opts = {}) {
|
|
508
|
+
const service = opts.service ?? "suno";
|
|
509
|
+
const endpoint = SERVICE_TASK_ENDPOINTS[service] ?? `/${service}/tasks`;
|
|
510
|
+
const handle = new TaskHandle(taskId, endpoint, this.transport);
|
|
511
|
+
return handle.wait({ pollInterval: opts.pollInterval, maxWait: opts.maxWait });
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/resources/files.ts
|
|
516
|
+
var fs = __toESM(require("fs"));
|
|
517
|
+
var path = __toESM(require("path"));
|
|
518
|
+
var Files = class {
|
|
519
|
+
constructor(transport) {
|
|
520
|
+
this.transport = transport;
|
|
521
|
+
}
|
|
522
|
+
transport;
|
|
523
|
+
async upload(file, opts = {}) {
|
|
524
|
+
let data;
|
|
525
|
+
let filename;
|
|
526
|
+
if (typeof file === "string") {
|
|
527
|
+
data = fs.readFileSync(file);
|
|
528
|
+
filename = opts.filename ?? path.basename(file);
|
|
529
|
+
} else {
|
|
530
|
+
data = file;
|
|
531
|
+
filename = opts.filename ?? "upload";
|
|
532
|
+
}
|
|
533
|
+
return this.transport.upload("/api/v1/files/", data, filename);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
// src/resources/platform.ts
|
|
538
|
+
var Applications = class {
|
|
539
|
+
constructor(transport) {
|
|
540
|
+
this.transport = transport;
|
|
541
|
+
}
|
|
542
|
+
transport;
|
|
543
|
+
async list(params) {
|
|
544
|
+
return this.transport.request("GET", "/api/v1/applications/", { params, platform: true });
|
|
545
|
+
}
|
|
546
|
+
async create(opts) {
|
|
547
|
+
const { serviceId, ...rest } = opts;
|
|
548
|
+
return this.transport.request("POST", "/api/v1/applications/", {
|
|
549
|
+
json: { service_id: serviceId, ...rest },
|
|
550
|
+
platform: true
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
async get(applicationId) {
|
|
554
|
+
return this.transport.request("GET", `/api/v1/applications/${applicationId}/`, { platform: true });
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
var Credentials = class {
|
|
558
|
+
constructor(transport) {
|
|
559
|
+
this.transport = transport;
|
|
560
|
+
}
|
|
561
|
+
transport;
|
|
562
|
+
async list(params) {
|
|
563
|
+
return this.transport.request("GET", "/api/v1/credentials/", { params, platform: true });
|
|
564
|
+
}
|
|
565
|
+
async create(opts) {
|
|
566
|
+
const { applicationId, ...rest } = opts;
|
|
567
|
+
return this.transport.request("POST", "/api/v1/credentials/", {
|
|
568
|
+
json: { application_id: applicationId, ...rest },
|
|
569
|
+
platform: true
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
async rotate(credentialId) {
|
|
573
|
+
return this.transport.request("POST", `/api/v1/credentials/${credentialId}/rotate/`, { platform: true });
|
|
574
|
+
}
|
|
575
|
+
async delete(credentialId) {
|
|
576
|
+
return this.transport.request("DELETE", `/api/v1/credentials/${credentialId}/`, { platform: true });
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
var Models = class {
|
|
580
|
+
constructor(transport) {
|
|
581
|
+
this.transport = transport;
|
|
582
|
+
}
|
|
583
|
+
transport;
|
|
584
|
+
async list(params) {
|
|
585
|
+
return this.transport.request("GET", "/api/v1/models/", { params, platform: true });
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
var Config = class {
|
|
589
|
+
constructor(transport) {
|
|
590
|
+
this.transport = transport;
|
|
591
|
+
}
|
|
592
|
+
transport;
|
|
593
|
+
async get() {
|
|
594
|
+
return this.transport.request("GET", "/api/v1/config/", { platform: true });
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var Platform = class {
|
|
598
|
+
applications;
|
|
599
|
+
credentials;
|
|
600
|
+
models;
|
|
601
|
+
config;
|
|
602
|
+
constructor(transport) {
|
|
603
|
+
this.applications = new Applications(transport);
|
|
604
|
+
this.credentials = new Credentials(transport);
|
|
605
|
+
this.models = new Models(transport);
|
|
606
|
+
this.config = new Config(transport);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// src/resources/openai.ts
|
|
611
|
+
var Completions = class {
|
|
612
|
+
constructor(transport) {
|
|
613
|
+
this.transport = transport;
|
|
614
|
+
}
|
|
615
|
+
transport;
|
|
616
|
+
async create(opts) {
|
|
617
|
+
const { model, messages, stream, ...rest } = opts;
|
|
618
|
+
const body = { model, messages, ...rest };
|
|
619
|
+
if (stream) {
|
|
620
|
+
body.stream = true;
|
|
621
|
+
return this.streamResponse(body);
|
|
622
|
+
}
|
|
623
|
+
return this.transport.request("POST", "/v1/chat/completions", { json: body });
|
|
624
|
+
}
|
|
625
|
+
async *streamResponse(body) {
|
|
626
|
+
for await (const chunk of this.transport.requestStream("POST", "/v1/chat/completions", { json: body })) {
|
|
627
|
+
yield JSON.parse(chunk);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
var ChatNamespace = class {
|
|
632
|
+
completions;
|
|
633
|
+
constructor(transport) {
|
|
634
|
+
this.completions = new Completions(transport);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var Responses = class {
|
|
638
|
+
constructor(transport) {
|
|
639
|
+
this.transport = transport;
|
|
640
|
+
}
|
|
641
|
+
transport;
|
|
642
|
+
async create(opts) {
|
|
643
|
+
const { model, input, stream, ...rest } = opts;
|
|
644
|
+
const body = { model, input, ...rest };
|
|
645
|
+
if (stream) {
|
|
646
|
+
body.stream = true;
|
|
647
|
+
return this.streamResponse(body);
|
|
648
|
+
}
|
|
649
|
+
return this.transport.request("POST", "/openai/responses", { json: body });
|
|
650
|
+
}
|
|
651
|
+
async *streamResponse(body) {
|
|
652
|
+
for await (const chunk of this.transport.requestStream("POST", "/openai/responses", { json: body })) {
|
|
653
|
+
yield JSON.parse(chunk);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var OpenAI = class {
|
|
658
|
+
chat;
|
|
659
|
+
responses;
|
|
660
|
+
constructor(transport) {
|
|
661
|
+
this.chat = new ChatNamespace(transport);
|
|
662
|
+
this.responses = new Responses(transport);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// src/client.ts
|
|
667
|
+
var AceDataCloud = class {
|
|
668
|
+
chat;
|
|
669
|
+
images;
|
|
670
|
+
audio;
|
|
671
|
+
video;
|
|
672
|
+
search;
|
|
673
|
+
tasks;
|
|
674
|
+
files;
|
|
675
|
+
platform;
|
|
676
|
+
openai;
|
|
677
|
+
transport;
|
|
678
|
+
constructor(opts = {}) {
|
|
679
|
+
this.transport = new Transport({
|
|
680
|
+
apiToken: opts.apiToken,
|
|
681
|
+
baseURL: opts.baseURL,
|
|
682
|
+
platformBaseURL: opts.platformBaseURL,
|
|
683
|
+
timeout: opts.timeout,
|
|
684
|
+
maxRetries: opts.maxRetries,
|
|
685
|
+
headers: opts.headers
|
|
686
|
+
});
|
|
687
|
+
this.chat = new Chat(this.transport);
|
|
688
|
+
this.images = new Images(this.transport);
|
|
689
|
+
this.audio = new Audio(this.transport);
|
|
690
|
+
this.video = new Video(this.transport);
|
|
691
|
+
this.search = new Search(this.transport);
|
|
692
|
+
this.tasks = new Tasks(this.transport);
|
|
693
|
+
this.files = new Files(this.transport);
|
|
694
|
+
this.platform = new Platform(this.transport);
|
|
695
|
+
this.openai = new OpenAI(this.transport);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
699
|
+
0 && (module.exports = {
|
|
700
|
+
APIError,
|
|
701
|
+
AceDataCloud,
|
|
702
|
+
AceDataCloudError,
|
|
703
|
+
AuthenticationError,
|
|
704
|
+
InsufficientBalanceError,
|
|
705
|
+
ModerationError,
|
|
706
|
+
RateLimitError,
|
|
707
|
+
ResourceDisabledError,
|
|
708
|
+
TaskHandle,
|
|
709
|
+
TimeoutError,
|
|
710
|
+
TokenMismatchError,
|
|
711
|
+
TransportError,
|
|
712
|
+
ValidationError
|
|
713
|
+
});
|
|
714
|
+
//# sourceMappingURL=index.js.map
|