@acedatacloud/sdk 2026.322.1 → 2026.418.0

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.
Files changed (40) hide show
  1. package/dist/index.d.mts +336 -0
  2. package/dist/index.d.ts +336 -4
  3. package/dist/index.js +713 -19
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +665 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +16 -2
  8. package/src/index.ts +4 -0
  9. package/src/resources/audio.ts +6 -3
  10. package/src/resources/images.ts +7 -3
  11. package/src/resources/tasks.ts +6 -0
  12. package/src/resources/video.ts +6 -3
  13. package/dist/client.d.ts +0 -31
  14. package/dist/client.js +0 -46
  15. package/dist/resources/audio.d.ts +0 -17
  16. package/dist/resources/audio.js +0 -30
  17. package/dist/resources/chat.d.ts +0 -30
  18. package/dist/resources/chat.js +0 -38
  19. package/dist/resources/files.d.ts +0 -9
  20. package/dist/resources/files.js +0 -59
  21. package/dist/resources/images.d.ts +0 -18
  22. package/dist/resources/images.js +0 -32
  23. package/dist/resources/openai.d.ts +0 -46
  24. package/dist/resources/openai.js +0 -59
  25. package/dist/resources/platform.d.ts +0 -41
  26. package/dist/resources/platform.js +0 -76
  27. package/dist/resources/search.d.ts +0 -14
  28. package/dist/resources/search.js +0 -22
  29. package/dist/resources/tasks.d.ts +0 -14
  30. package/dist/resources/tasks.js +0 -36
  31. package/dist/resources/video.d.ts +0 -17
  32. package/dist/resources/video.js +0 -30
  33. package/dist/runtime/errors.d.ts +0 -44
  34. package/dist/runtime/errors.js +0 -89
  35. package/dist/runtime/index.d.ts +0 -3
  36. package/dist/runtime/index.js +0 -19
  37. package/dist/runtime/tasks.d.ts +0 -17
  38. package/dist/runtime/tasks.js +0 -46
  39. package/dist/runtime/transport.d.ts +0 -31
  40. package/dist/runtime/transport.js +0 -213
@@ -1,213 +0,0 @@
1
- "use strict";
2
- /** HTTP transport for AceDataCloud SDK. Uses native fetch (Node 18+). */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Transport = void 0;
5
- const errors_1 = require("./errors");
6
- const ERROR_CODE_MAP = {
7
- invalid_token: errors_1.AuthenticationError,
8
- token_expired: errors_1.AuthenticationError,
9
- no_token: errors_1.AuthenticationError,
10
- token_mismatched: errors_1.TokenMismatchError,
11
- used_up: errors_1.InsufficientBalanceError,
12
- disabled: errors_1.ResourceDisabledError,
13
- too_many_requests: errors_1.RateLimitError,
14
- bad_request: errors_1.ValidationError,
15
- };
16
- const RETRY_STATUS_CODES = new Set([408, 409, 429, 500, 502, 503, 504]);
17
- function mapError(statusCode, body) {
18
- const errorData = (body.error ?? {});
19
- const code = (errorData.code ?? '');
20
- const message = (errorData.message ?? '');
21
- const traceId = body.trace_id;
22
- let ErrorClass = ERROR_CODE_MAP[code];
23
- if (!ErrorClass) {
24
- if (statusCode === 403)
25
- ErrorClass = errors_1.ModerationError;
26
- else if (statusCode === 401)
27
- ErrorClass = errors_1.AuthenticationError;
28
- else if (statusCode === 429)
29
- ErrorClass = errors_1.RateLimitError;
30
- else if (statusCode === 400)
31
- ErrorClass = errors_1.ValidationError;
32
- else
33
- ErrorClass = errors_1.APIError;
34
- }
35
- return new ErrorClass({ message, statusCode, code, traceId, body });
36
- }
37
- function backoffDelay(attempt) {
38
- const base = Math.min(2 ** attempt, 8);
39
- return base + Math.random() * 0.5;
40
- }
41
- function sleep(ms) {
42
- return new Promise((resolve) => setTimeout(resolve, ms));
43
- }
44
- class Transport {
45
- baseURL;
46
- platformBaseURL;
47
- timeout;
48
- maxRetries;
49
- headers;
50
- constructor(opts = {}) {
51
- const token = opts.apiToken ?? process.env.ACEDATACLOUD_API_TOKEN ?? '';
52
- if (!token) {
53
- throw new errors_1.AuthenticationError({
54
- message: 'apiToken is required. Pass it to the client or set ACEDATACLOUD_API_TOKEN.',
55
- statusCode: 0,
56
- code: 'no_token',
57
- });
58
- }
59
- this.baseURL = (opts.baseURL ?? 'https://api.acedata.cloud').replace(/\/+$/, '');
60
- this.platformBaseURL = (opts.platformBaseURL ?? 'https://platform.acedata.cloud').replace(/\/+$/, '');
61
- this.timeout = opts.timeout ?? 300_000;
62
- this.maxRetries = opts.maxRetries ?? 2;
63
- this.headers = {
64
- accept: 'application/json',
65
- authorization: `Bearer ${token}`,
66
- 'content-type': 'application/json',
67
- 'user-agent': 'acedatacloud-node/0.1.0',
68
- ...(opts.headers ?? {}),
69
- };
70
- }
71
- async request(method, path, opts = {}) {
72
- const base = opts.platform ? this.platformBaseURL : this.baseURL;
73
- let url = `${base}${path}`;
74
- if (opts.params) {
75
- const qs = new URLSearchParams(opts.params).toString();
76
- url += `?${qs}`;
77
- }
78
- const headers = { ...this.headers, ...(opts.headers ?? {}) };
79
- const timeoutMs = opts.timeout ?? this.timeout;
80
- let lastError = null;
81
- for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
82
- const controller = new AbortController();
83
- const timer = setTimeout(() => controller.abort(), timeoutMs);
84
- try {
85
- const resp = await fetch(url, {
86
- method,
87
- headers,
88
- body: opts.json ? JSON.stringify(opts.json) : undefined,
89
- signal: controller.signal,
90
- });
91
- clearTimeout(timer);
92
- if (resp.status >= 400) {
93
- const text = await resp.text();
94
- let body;
95
- try {
96
- body = JSON.parse(text);
97
- }
98
- catch {
99
- body = { error: { code: 'unknown', message: text } };
100
- }
101
- if (RETRY_STATUS_CODES.has(resp.status) && attempt < this.maxRetries) {
102
- await sleep(backoffDelay(attempt) * 1000);
103
- continue;
104
- }
105
- throw mapError(resp.status, body);
106
- }
107
- return (await resp.json());
108
- }
109
- catch (err) {
110
- clearTimeout(timer);
111
- if (err instanceof errors_1.APIError)
112
- throw err;
113
- lastError = err;
114
- if (attempt < this.maxRetries) {
115
- await sleep(backoffDelay(attempt) * 1000);
116
- continue;
117
- }
118
- }
119
- }
120
- throw lastError ?? new errors_1.TransportError('Request failed after retries');
121
- }
122
- async *requestStream(method, path, opts = {}) {
123
- const url = `${this.baseURL}${path}`;
124
- const headers = { ...this.headers, accept: 'text/event-stream' };
125
- const controller = new AbortController();
126
- const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
127
- try {
128
- const resp = await fetch(url, {
129
- method,
130
- headers,
131
- body: opts.json ? JSON.stringify(opts.json) : undefined,
132
- signal: controller.signal,
133
- });
134
- if (resp.status >= 400) {
135
- const text = await resp.text();
136
- let body;
137
- try {
138
- body = JSON.parse(text);
139
- }
140
- catch {
141
- body = { error: { code: 'unknown', message: text } };
142
- }
143
- throw mapError(resp.status, body);
144
- }
145
- if (!resp.body)
146
- throw new errors_1.TransportError('No response body for stream');
147
- const reader = resp.body.getReader();
148
- const decoder = new TextDecoder();
149
- let buffer = '';
150
- while (true) {
151
- const { done, value } = await reader.read();
152
- if (done)
153
- break;
154
- buffer += decoder.decode(value, { stream: true });
155
- const lines = buffer.split('\n');
156
- buffer = lines.pop() ?? '';
157
- for (const line of lines) {
158
- if (line.startsWith('data: ')) {
159
- const data = line.slice(6);
160
- if (data === '[DONE]')
161
- return;
162
- yield data;
163
- }
164
- }
165
- }
166
- }
167
- finally {
168
- clearTimeout(timer);
169
- }
170
- }
171
- async upload(path, fileData, filename, opts = {}) {
172
- const url = `${this.platformBaseURL}${path}`;
173
- const boundary = `----AceDataCloudBoundary${Date.now()}`;
174
- const headers = {
175
- ...this.headers,
176
- 'content-type': `multipart/form-data; boundary=${boundary}`,
177
- };
178
- delete headers['content-type'];
179
- const body = new FormData();
180
- body.append('file', new Blob([fileData]), filename);
181
- const authHeaders = {
182
- authorization: this.headers.authorization,
183
- 'user-agent': this.headers['user-agent'],
184
- };
185
- const controller = new AbortController();
186
- const timer = setTimeout(() => controller.abort(), opts.timeout ?? this.timeout);
187
- try {
188
- const resp = await fetch(url, {
189
- method: 'POST',
190
- headers: authHeaders,
191
- body,
192
- signal: controller.signal,
193
- });
194
- clearTimeout(timer);
195
- if (resp.status >= 400) {
196
- const text = await resp.text();
197
- let respBody;
198
- try {
199
- respBody = JSON.parse(text);
200
- }
201
- catch {
202
- respBody = { error: { code: 'unknown', message: text } };
203
- }
204
- throw mapError(resp.status, respBody);
205
- }
206
- return (await resp.json());
207
- }
208
- finally {
209
- clearTimeout(timer);
210
- }
211
- }
212
- }
213
- exports.Transport = Transport;