cloreai 4.1.0 → 5.0.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.
- package/README.md +35 -8
- package/dist/Cloreai.d.ts +5 -2
- package/dist/Cloreai.js +31 -28
- package/dist/CloreaiError.d.ts +14 -13
- package/dist/CloreaiError.js +3 -4
- package/dist/index.d.ts +2 -0
- package/dist/resources/createOrder.d.ts +8 -14
- package/dist/resources/marketplace.d.ts +1 -0
- package/dist/resources/myOrders.d.ts +11 -0
- package/dist/resources/myServers.d.ts +1 -0
- package/dist/resources/orderRenewals.d.ts +21 -0
- package/dist/resources/orderRenewals.js +1 -0
- package/dist/resources/serverConfig.d.ts +1 -0
- package/dist/resources/setOrderAutoRenew.d.ts +8 -0
- package/dist/resources/setOrderAutoRenew.js +1 -0
- package/dist/resources/setServerSettings.d.ts +1 -0
- package/dist/resources/setSpotPrice.d.ts +1 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ await cloreai.setServerSettings({
|
|
|
103
103
|
'USD-Blockchain': { on_demand: 1, spot: 1 },
|
|
104
104
|
'bitcoin': { on_demand: 1, spot: 1 },
|
|
105
105
|
},
|
|
106
|
+
'auto_renew_allowed': true,
|
|
106
107
|
})
|
|
107
108
|
```
|
|
108
109
|
|
|
@@ -136,26 +137,45 @@ await cloreai.cancelOrders({
|
|
|
136
137
|
|
|
137
138
|
```typescript
|
|
138
139
|
await cloreai.createOrder({
|
|
139
|
-
type: 'on-demand',
|
|
140
140
|
currency: 'CLORE-Blockchain',
|
|
141
141
|
image: 'cloreai/jupyter:ubuntu24.04-v2',
|
|
142
142
|
renting_server: 5738,
|
|
143
|
+
type: 'on-demand',
|
|
143
144
|
ports: { 22: 'tcp', 8888: 'http' },
|
|
144
145
|
env: { SSH_PASSWORD: 'SSH_PASSWORD', JUPYTER_TOKEN: 'JUPYTER_TOKEN' },
|
|
145
146
|
jupyter_token: 'JUPYTER_TOKEN',
|
|
146
147
|
ssh_password: 'SSH_PASSWORD',
|
|
147
148
|
required_price: 50,
|
|
148
|
-
|
|
149
|
+
remember_password: true,
|
|
150
|
+
auto_renew: true,
|
|
151
|
+
auto_renew_max_price: 50,
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 12. set_order_auto_renew
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
await cloreai.setOrderAutoRenew({
|
|
159
|
+
order_id: 38,
|
|
160
|
+
rental_hours: null,
|
|
161
|
+
auto_renew: true,
|
|
162
|
+
auto_renew_max_price: 300,
|
|
149
163
|
})
|
|
150
164
|
```
|
|
151
165
|
|
|
152
|
-
###
|
|
166
|
+
### 13. order_renewals
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const orderRenewals = await cloreai.orderRenewals({ order_id: 38 })
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 14. poh_balance
|
|
153
173
|
|
|
154
174
|
```typescript
|
|
155
175
|
const pohBalance = await cloreai.pohBalance()
|
|
156
176
|
```
|
|
157
177
|
|
|
158
|
-
###
|
|
178
|
+
### 15. renter_fees
|
|
159
179
|
|
|
160
180
|
```typescript
|
|
161
181
|
const renterFees = await cloreai.renterFees()
|
|
@@ -175,9 +195,16 @@ const marketplace = await cloreai.marketplace({
|
|
|
175
195
|
|
|
176
196
|
Use the `CloreaiError` class for error handling.
|
|
177
197
|
|
|
178
|
-
|
|
198
|
+
To check the error type based on its code, use the `statusCodes` constant.
|
|
199
|
+
|
|
200
|
+
Errors include an `error.data` field, which contains the server
|
|
201
|
+
response—including a code and a description of the error—and, in some cases,
|
|
202
|
+
additional fields with further error details.
|
|
179
203
|
|
|
180
|
-
|
|
204
|
+
This class only catches errors when a response has been successfully received,
|
|
205
|
+
but the response code is not equal to `statusCodes.NORMAL` (0). Be sure to
|
|
206
|
+
implement a pattern for propagating unknown exceptions (such as connection
|
|
207
|
+
errors, etc.), as shown in the example below.
|
|
181
208
|
|
|
182
209
|
```typescript
|
|
183
210
|
import { CloreaiError, statusCodes } from 'cloreai'
|
|
@@ -186,9 +213,9 @@ try {
|
|
|
186
213
|
const marketplace = await cloreai.marketplace()
|
|
187
214
|
} catch (error) {
|
|
188
215
|
if (error instanceof CloreaiError) {
|
|
189
|
-
console.log(
|
|
216
|
+
console.log('Error data:', error.data)
|
|
190
217
|
|
|
191
|
-
if (error.
|
|
218
|
+
if (error.data.code === statusCodes.EXCEEDED) {
|
|
192
219
|
console.log('Rate limit exceeded error')
|
|
193
220
|
}
|
|
194
221
|
} else {
|
package/dist/Cloreai.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import PQueue, { type Options as
|
|
1
|
+
import PQueue, { type Options as QueueOptions } from 'p-queue';
|
|
2
2
|
import type { CancelOrderRequestData, CancelOrderResponseData } from './resources/cancelOrder.ts';
|
|
3
3
|
import type { CancelOrdersRequestData, CancelOrdersResponseData } from './resources/cancelOrders.ts';
|
|
4
4
|
import type { CreateOrderRequestData, CreateOrderResponseData } from './resources/createOrder.ts';
|
|
5
5
|
import type { MarketplaceResponseData } from './resources/marketplace.ts';
|
|
6
6
|
import type { MyOrdersRequestParams, MyOrdersResponseData } from './resources/myOrders.ts';
|
|
7
7
|
import type { MyServersResponseData } from './resources/myServers.ts';
|
|
8
|
+
import type { OrderRenewalsRequestData, OrderRenewalsResponseData } from './resources/orderRenewals.ts';
|
|
8
9
|
import type { PohBalanceResponseData } from './resources/pohBalance.ts';
|
|
9
10
|
import type { RenterFeesResponseData } from './resources/renterFees.ts';
|
|
10
11
|
import type { ServerConfigRequestData, ServerConfigResponseData } from './resources/serverConfig.ts';
|
|
12
|
+
import type { SetOrderAutoRenewRequestData, SetOrderAutoRenewResponseData } from './resources/setOrderAutoRenew.ts';
|
|
11
13
|
import type { SetServerSettingsRequestData, SetServerSettingsResponseData } from './resources/setServerSettings.ts';
|
|
12
14
|
import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './resources/setSpotPrice.ts';
|
|
13
15
|
import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './resources/spotMarketplace.ts';
|
|
@@ -19,7 +21,6 @@ export interface Options {
|
|
|
19
21
|
queueOptions?: QueueOptions;
|
|
20
22
|
queueCreateOrderOptions?: QueueOptions;
|
|
21
23
|
}
|
|
22
|
-
export type QueueOptions = PQueueOptions<Queue<() => Promise<unknown>, QueueAddOptions>, QueueAddOptions>;
|
|
23
24
|
declare class Cloreai {
|
|
24
25
|
#private;
|
|
25
26
|
apiKey: string;
|
|
@@ -40,6 +41,8 @@ declare class Cloreai {
|
|
|
40
41
|
cancelOrder(data: CancelOrderRequestData, init?: RequestInit): Promise<CancelOrderResponseData>;
|
|
41
42
|
cancelOrders(data: CancelOrdersRequestData, init?: RequestInit): Promise<CancelOrdersResponseData>;
|
|
42
43
|
createOrder(data: CreateOrderRequestData, init?: RequestInit): Promise<CreateOrderResponseData>;
|
|
44
|
+
setOrderAutoRenew(data: SetOrderAutoRenewRequestData, init?: RequestInit): Promise<SetOrderAutoRenewResponseData>;
|
|
45
|
+
orderRenewals(data: OrderRenewalsRequestData, init?: RequestInit): Promise<OrderRenewalsResponseData>;
|
|
43
46
|
pohBalance(init?: RequestInit): Promise<PohBalanceResponseData>;
|
|
44
47
|
renterFees(init?: RequestInit): Promise<RenterFeesResponseData>;
|
|
45
48
|
}
|
package/dist/Cloreai.js
CHANGED
|
@@ -47,34 +47,12 @@ class Cloreai {
|
|
|
47
47
|
headers,
|
|
48
48
|
signal,
|
|
49
49
|
};
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
let response;
|
|
53
|
-
try {
|
|
54
|
-
response = await this.fetch(request);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw new CloreaiError(error instanceof Error ? error.message : String(error), {
|
|
58
|
-
cause: error,
|
|
59
|
-
init: mergedInit,
|
|
60
|
-
request,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
50
|
+
const request = new Request(input, mergedInit);
|
|
51
|
+
const response = await this.fetch(request);
|
|
63
52
|
const originalJson = response.json;
|
|
64
53
|
// @ts-expect-error: json is readonly
|
|
65
54
|
response.json = async () => {
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
data = await originalJson.call(response);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
throw new CloreaiError(error instanceof Error ? error.message : String(error), {
|
|
72
|
-
cause: error,
|
|
73
|
-
init: mergedInit,
|
|
74
|
-
request,
|
|
75
|
-
response,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
55
|
+
const data = await originalJson.call(response);
|
|
78
56
|
if (data.code === statusCodes.NORMAL) {
|
|
79
57
|
return data;
|
|
80
58
|
}
|
|
@@ -83,11 +61,8 @@ class Cloreai {
|
|
|
83
61
|
? `Code "${data.code}, error "${data.error}"`
|
|
84
62
|
: `Code "${data.code}"`;
|
|
85
63
|
throw new CloreaiError(errorMessage, {
|
|
86
|
-
init: mergedInit,
|
|
87
64
|
request,
|
|
88
65
|
response,
|
|
89
|
-
statusCode: data.code,
|
|
90
|
-
description: data.error ?? '',
|
|
91
66
|
data,
|
|
92
67
|
});
|
|
93
68
|
};
|
|
@@ -248,6 +223,34 @@ class Cloreai {
|
|
|
248
223
|
});
|
|
249
224
|
return await response.json();
|
|
250
225
|
}
|
|
226
|
+
async setOrderAutoRenew(data, init = {}) {
|
|
227
|
+
const url = new URL(this.baseURL + '/set_order_auto_renew');
|
|
228
|
+
const response = await this.queue.add(async () => {
|
|
229
|
+
return await this.#fetch(url, {
|
|
230
|
+
...init,
|
|
231
|
+
method: 'POST',
|
|
232
|
+
body: JSON.stringify(data),
|
|
233
|
+
});
|
|
234
|
+
}, {
|
|
235
|
+
priority: priorityLevels.NORMAL,
|
|
236
|
+
signal: init.signal ?? undefined,
|
|
237
|
+
});
|
|
238
|
+
return await response.json();
|
|
239
|
+
}
|
|
240
|
+
async orderRenewals(data, init = {}) {
|
|
241
|
+
const url = new URL(this.baseURL + '/order_renewals');
|
|
242
|
+
const response = await this.queue.add(async () => {
|
|
243
|
+
return await this.#fetch(url, {
|
|
244
|
+
...init,
|
|
245
|
+
method: 'POST',
|
|
246
|
+
body: JSON.stringify(data),
|
|
247
|
+
});
|
|
248
|
+
}, {
|
|
249
|
+
priority: priorityLevels.NORMAL,
|
|
250
|
+
signal: init.signal ?? undefined,
|
|
251
|
+
});
|
|
252
|
+
return await response.json();
|
|
253
|
+
}
|
|
251
254
|
async pohBalance(init = {}) {
|
|
252
255
|
const url = new URL(this.baseURL + '/poh_balance');
|
|
253
256
|
const response = await this.queue.add(async () => {
|
package/dist/CloreaiError.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { ResponseData } from './types.ts';
|
|
2
|
+
export interface ErrorData extends ResponseData {
|
|
3
|
+
max_step?: number;
|
|
4
|
+
time_to_lowering?: number;
|
|
5
|
+
min_price?: number;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
1
8
|
export interface CloreaiErrorOptions extends ErrorOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
statusCode?: number;
|
|
6
|
-
description?: string;
|
|
7
|
-
data?: unknown;
|
|
9
|
+
request: Request;
|
|
10
|
+
response: Response;
|
|
11
|
+
data: ErrorData;
|
|
8
12
|
}
|
|
9
13
|
export declare class CloreaiError extends Error {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
description?: string;
|
|
15
|
-
data?: unknown;
|
|
16
|
-
constructor(message?: string, options?: CloreaiErrorOptions);
|
|
14
|
+
request: Request;
|
|
15
|
+
response: Response;
|
|
16
|
+
data: ErrorData;
|
|
17
|
+
constructor(message: string, options: CloreaiErrorOptions);
|
|
17
18
|
}
|
package/dist/CloreaiError.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
export class CloreaiError extends Error {
|
|
2
|
-
init;
|
|
3
2
|
request;
|
|
4
3
|
response;
|
|
5
|
-
statusCode;
|
|
6
|
-
description;
|
|
7
4
|
data;
|
|
8
5
|
constructor(message, options) {
|
|
9
6
|
super(message, options);
|
|
10
7
|
this.name = 'CloreaiError';
|
|
11
|
-
|
|
8
|
+
this.request = options.request;
|
|
9
|
+
this.response = options.response;
|
|
10
|
+
this.data = options.data;
|
|
12
11
|
}
|
|
13
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ export type * from './resources/createOrder.ts';
|
|
|
8
8
|
export type * from './resources/marketplace.ts';
|
|
9
9
|
export type * from './resources/myOrders.ts';
|
|
10
10
|
export type * from './resources/myServers.ts';
|
|
11
|
+
export type * from './resources/orderRenewals.ts';
|
|
11
12
|
export type * from './resources/pohBalance.ts';
|
|
12
13
|
export type * from './resources/renterFees.ts';
|
|
13
14
|
export type * from './resources/serverConfig.ts';
|
|
15
|
+
export type * from './resources/setOrderAutoRenew.ts';
|
|
14
16
|
export type * from './resources/setServerSettings.ts';
|
|
15
17
|
export type * from './resources/setSpotPrice.ts';
|
|
16
18
|
export type * from './resources/spotMarketplace.ts';
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import type { Currency, OrderType, ResponseData } from '../types.ts';
|
|
2
|
-
export
|
|
3
|
-
export interface CreateOrderOnDemand extends CreateOrderBase {
|
|
4
|
-
type: 'on-demand';
|
|
5
|
-
}
|
|
6
|
-
export interface CreateOrderSpot extends CreateOrderBase {
|
|
7
|
-
type: 'spot';
|
|
8
|
-
spotprice: number;
|
|
9
|
-
}
|
|
10
|
-
export interface CreateOrderBase {
|
|
11
|
-
type: OrderType;
|
|
2
|
+
export interface CreateOrderRequestData {
|
|
12
3
|
currency: Currency;
|
|
13
4
|
image: string;
|
|
14
5
|
renting_server: number;
|
|
6
|
+
type: OrderType;
|
|
7
|
+
spotprice?: number;
|
|
15
8
|
ports?: Record<string, string>;
|
|
16
9
|
env?: Record<string, string>;
|
|
17
10
|
jupyter_token?: string;
|
|
@@ -20,11 +13,12 @@ export interface CreateOrderBase {
|
|
|
20
13
|
command?: string;
|
|
21
14
|
required_price?: number;
|
|
22
15
|
autossh_entrypoint?: boolean;
|
|
23
|
-
|
|
16
|
+
remember_password?: boolean;
|
|
24
17
|
dockerhub_auth?: string;
|
|
25
18
|
gpu_count?: number;
|
|
26
19
|
gpu_indices?: number[];
|
|
20
|
+
rental_hours?: number;
|
|
21
|
+
auto_renew?: boolean;
|
|
22
|
+
auto_renew_max_price?: number;
|
|
27
23
|
}
|
|
28
|
-
export
|
|
29
|
-
min_price?: number;
|
|
30
|
-
}
|
|
24
|
+
export type CreateOrderResponseData = ResponseData;
|
|
@@ -23,6 +23,16 @@ export interface MyOrdersOrder {
|
|
|
23
23
|
total_gpus: number;
|
|
24
24
|
gpu_array: string[];
|
|
25
25
|
si: number;
|
|
26
|
+
rental_hours: number;
|
|
27
|
+
rental_end: number;
|
|
28
|
+
term_start: number;
|
|
29
|
+
term_end: number;
|
|
30
|
+
term_mrl: number;
|
|
31
|
+
last_renewal_at: number;
|
|
32
|
+
auto_renew: boolean;
|
|
33
|
+
auto_renew_max_price: number;
|
|
34
|
+
renewals_count: number;
|
|
35
|
+
ssh_auth: string;
|
|
26
36
|
my_past_rating?: number;
|
|
27
37
|
auto_login: string;
|
|
28
38
|
mon_container: number;
|
|
@@ -38,4 +48,5 @@ export interface MyOrdersOrder {
|
|
|
38
48
|
expired?: boolean;
|
|
39
49
|
paused?: boolean;
|
|
40
50
|
online: boolean;
|
|
51
|
+
autossh: boolean;
|
|
41
52
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ResponseData } from '../types.ts';
|
|
2
|
+
export interface OrderRenewalsRequestData {
|
|
3
|
+
order_id: number;
|
|
4
|
+
}
|
|
5
|
+
export interface OrderRenewalsResponseData extends ResponseData {
|
|
6
|
+
renewals: OrderRenewal;
|
|
7
|
+
}
|
|
8
|
+
export interface OrderRenewal {
|
|
9
|
+
order_id: number;
|
|
10
|
+
renewal_no: number;
|
|
11
|
+
outcome: string;
|
|
12
|
+
reason: string;
|
|
13
|
+
decided_at: number;
|
|
14
|
+
applied_at: number;
|
|
15
|
+
old_price: number;
|
|
16
|
+
new_price: number;
|
|
17
|
+
cap: number;
|
|
18
|
+
term_seconds: number;
|
|
19
|
+
term_start: number;
|
|
20
|
+
term_end: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResponseData } from '../types.ts';
|
|
2
|
+
export interface SetOrderAutoRenewRequestData {
|
|
3
|
+
order_id: number;
|
|
4
|
+
rental_hours?: number | null;
|
|
5
|
+
auto_renew?: boolean;
|
|
6
|
+
auto_renew_max_price?: number;
|
|
7
|
+
}
|
|
8
|
+
export type SetOrderAutoRenewResponseData = ResponseData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,8 +3,4 @@ export interface SetSpotPriceRequestData {
|
|
|
3
3
|
order_id: number;
|
|
4
4
|
desired_price: number;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
max_step?: number;
|
|
8
|
-
time_to_lowering?: number;
|
|
9
|
-
min_price?: number;
|
|
10
|
-
}
|
|
6
|
+
export type SetSpotPriceResponseData = ResponseData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloreai",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "CLORE.AI API client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloreai",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"p-queue": "^
|
|
32
|
+
"p-queue": "^10.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tsconfig/node-lts": "^24.0.1",
|
|
36
36
|
"@tsconfig/node-ts": "^23.6.4",
|
|
37
37
|
"@tsconfig/strictest": "^2.0.8",
|
|
38
38
|
"@types/node": "^26.6.5",
|
|
39
|
-
"eslint": "^10.
|
|
40
|
-
"eslint-config-vladpuz": "^4.
|
|
39
|
+
"eslint": "^10.13.0",
|
|
40
|
+
"eslint-config-vladpuz": "^4.4.1",
|
|
41
41
|
"husky": "^9.1.7",
|
|
42
42
|
"prettier": "^3.9.10",
|
|
43
43
|
"prettier-config-vladpuz": "^3.0.2",
|