@sogni-ai/sogni-client 1.0.0-alpha.3 → 1.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/CHANGELOG.md +6 -0
- package/dist/Account/CurrentAccount.d.ts +5 -4
- package/dist/Account/CurrentAccount.js +29 -9
- package/dist/Account/CurrentAccount.js.map +1 -1
- package/dist/Account/index.d.ts +3 -5
- package/dist/Account/index.js +9 -20
- package/dist/Account/index.js.map +1 -1
- package/dist/Account/types.d.ts +0 -2
- package/dist/ApiClient/WebSocketClient/index.d.ts +4 -4
- package/dist/ApiClient/WebSocketClient/index.js +49 -33
- package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/index.d.ts +10 -4
- package/dist/ApiClient/index.js +17 -26
- package/dist/ApiClient/index.js.map +1 -1
- package/dist/Projects/createJobRequestMessage.js +1 -1
- package/dist/Projects/createJobRequestMessage.js.map +1 -1
- package/dist/Projects/index.d.ts +2 -27
- package/dist/Projects/index.js +14 -94
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/models.json +8906 -0
- package/dist/Projects/types/index.d.ts +0 -32
- package/dist/lib/RestClient.d.ts +7 -4
- package/dist/lib/RestClient.js +7 -7
- package/dist/lib/RestClient.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +6 -1
- package/src/Account/CurrentAccount.ts +33 -12
- package/src/Account/index.ts +8 -18
- package/src/Account/types.ts +0 -2
- package/src/ApiClient/WebSocketClient/index.ts +25 -16
- package/src/ApiClient/index.ts +27 -19
- package/src/Projects/createJobRequestMessage.ts +1 -2
- package/src/Projects/index.ts +8 -97
- package/src/Projects/models.json +8906 -0
- package/src/Projects/types/index.ts +0 -34
- package/src/lib/RestClient.ts +13 -8
- package/src/version.ts +1 -1
- package/dist/lib/AuthManager.d.ts +0 -51
- package/dist/lib/AuthManager.js +0 -157
- package/dist/lib/AuthManager.js.map +0 -1
- package/dist/lib/Cache.d.ts +0 -9
- package/dist/lib/Cache.js +0 -30
- package/dist/lib/Cache.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -8
- package/dist/lib/utils.js +0 -20
- package/dist/lib/utils.js.map +0 -1
- package/src/lib/AuthManager.ts +0 -172
- package/src/lib/Cache.ts +0 -36
- package/src/lib/utils.ts +0 -17
package/src/Projects/index.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import ApiGroup, { ApiConfig } from '../ApiGroup';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
EstimateRequest,
|
|
5
|
-
ImageUrlParams,
|
|
6
|
-
ProjectParams,
|
|
7
|
-
SizePreset,
|
|
8
|
-
SupportedModel
|
|
9
|
-
} from './types';
|
|
2
|
+
import models from './models.json';
|
|
3
|
+
import { AvailableModel, EstimateRequest, ImageUrlParams, ProjectParams } from './types';
|
|
10
4
|
import {
|
|
11
5
|
JobErrorData,
|
|
12
6
|
JobProgressData,
|
|
@@ -22,12 +16,8 @@ import { JobEvent, ProjectApiEvents, ProjectEvent } from './types/events';
|
|
|
22
16
|
import getUUID from '../lib/getUUID';
|
|
23
17
|
import { RawProject } from './types/RawProject';
|
|
24
18
|
import ErrorData from '../types/ErrorData';
|
|
25
|
-
import { SupernetType } from '../ApiClient/WebSocketClient/types';
|
|
26
|
-
import Cache from '../lib/Cache';
|
|
27
19
|
|
|
28
|
-
const sizePresetCache = new Cache<SizePreset[]>(10 * 60 * 1000);
|
|
29
20
|
const GARBAGE_COLLECT_TIMEOUT = 10000;
|
|
30
|
-
const MODELS_REFRESH_INTERVAL = 1000 * 60 * 60 * 24; // 24 hours
|
|
31
21
|
|
|
32
22
|
function mapErrorCodes(code: string): number {
|
|
33
23
|
switch (code) {
|
|
@@ -49,10 +39,6 @@ function mapErrorCodes(code: string): number {
|
|
|
49
39
|
class ProjectsApi extends ApiGroup<ProjectApiEvents> {
|
|
50
40
|
private _availableModels: AvailableModel[] = [];
|
|
51
41
|
private projects: Project[] = [];
|
|
52
|
-
private _supportedModels: { data: SupportedModel[] | null; updatedAt: Date } = {
|
|
53
|
-
data: null,
|
|
54
|
-
updatedAt: new Date(0)
|
|
55
|
-
};
|
|
56
42
|
|
|
57
43
|
get availableModels() {
|
|
58
44
|
return this._availableModels;
|
|
@@ -79,20 +65,14 @@ class ProjectsApi extends ApiGroup<ProjectApiEvents> {
|
|
|
79
65
|
this.emit('availableModels', this._availableModels);
|
|
80
66
|
}
|
|
81
67
|
|
|
82
|
-
private
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
models = await this.getSupportedModels();
|
|
86
|
-
} catch (e) {
|
|
87
|
-
this.client.logger.error(e);
|
|
88
|
-
}
|
|
89
|
-
const modelIndex = models.reduce((acc: Record<string, SupportedModel>, model) => {
|
|
90
|
-
acc[model.id] = model;
|
|
68
|
+
private handleSwarmModels(data: SocketEventMap['swarmModels']) {
|
|
69
|
+
const modelIndex = models.reduce((acc: Record<string, any>, model) => {
|
|
70
|
+
acc[model.modelId] = model;
|
|
91
71
|
return acc;
|
|
92
72
|
}, {});
|
|
93
73
|
this._availableModels = Object.entries(data).map(([id, workerCount]) => ({
|
|
94
74
|
id,
|
|
95
|
-
name: modelIndex[id]?.
|
|
75
|
+
name: modelIndex[id]?.modelShortName || id.replace(/-/g, ' '),
|
|
96
76
|
workerCount
|
|
97
77
|
}));
|
|
98
78
|
this.emit('availableModels', this._availableModels);
|
|
@@ -390,32 +370,10 @@ class ProjectsApi extends ApiGroup<ProjectApiEvents> {
|
|
|
390
370
|
stepCount,
|
|
391
371
|
previewCount,
|
|
392
372
|
cnEnabled,
|
|
393
|
-
startingImageStrength
|
|
394
|
-
width,
|
|
395
|
-
height,
|
|
396
|
-
sizePreset
|
|
373
|
+
startingImageStrength
|
|
397
374
|
}: EstimateRequest) {
|
|
398
|
-
const pathParams = [
|
|
399
|
-
network,
|
|
400
|
-
model,
|
|
401
|
-
imageCount,
|
|
402
|
-
stepCount,
|
|
403
|
-
previewCount,
|
|
404
|
-
cnEnabled ? 1 : 0,
|
|
405
|
-
startingImageStrength ? 1 - startingImageStrength : 0
|
|
406
|
-
];
|
|
407
|
-
if (sizePreset) {
|
|
408
|
-
const presets = await this.getSizePresets(network, model);
|
|
409
|
-
const preset = presets.find((p) => p.id === sizePreset);
|
|
410
|
-
if (!preset) {
|
|
411
|
-
throw new Error('Invalid size preset');
|
|
412
|
-
}
|
|
413
|
-
pathParams.push(preset.width, preset.height);
|
|
414
|
-
} else if (width && height) {
|
|
415
|
-
pathParams.push(width, height);
|
|
416
|
-
}
|
|
417
375
|
const r = await this.client.socket.get<EstimationResponse>(
|
|
418
|
-
`/api/v1/job/estimate/${
|
|
376
|
+
`/api/v1/job/estimate/${network}/${model}/${imageCount}/${stepCount}/${previewCount}/${cnEnabled ? 1 : 0}/${startingImageStrength ? 1 - startingImageStrength : 0}`
|
|
419
377
|
);
|
|
420
378
|
return {
|
|
421
379
|
token: r.quote.project.costInToken,
|
|
@@ -448,53 +406,6 @@ class ProjectsApi extends ApiGroup<ProjectApiEvents> {
|
|
|
448
406
|
);
|
|
449
407
|
return r.data.downloadUrl;
|
|
450
408
|
}
|
|
451
|
-
|
|
452
|
-
async getSupportedModels(forceRefresh = false) {
|
|
453
|
-
if (
|
|
454
|
-
this._supportedModels.data &&
|
|
455
|
-
!forceRefresh &&
|
|
456
|
-
Date.now() - this._supportedModels.updatedAt.getTime() < MODELS_REFRESH_INTERVAL
|
|
457
|
-
) {
|
|
458
|
-
return this._supportedModels.data;
|
|
459
|
-
}
|
|
460
|
-
const models = await this.client.socket.get<SupportedModel[]>(`/api/v1/models/list`);
|
|
461
|
-
this._supportedModels = { data: models, updatedAt: new Date() };
|
|
462
|
-
return models;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Get supported size presets for the model and network. Size presets are cached for 10 minutes.
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* ```ts
|
|
470
|
-
* const presets = await client.projects.getSizePresets('fast', 'flux1-schnell-fp8');
|
|
471
|
-
* console.log(presets);
|
|
472
|
-
* ```
|
|
473
|
-
*
|
|
474
|
-
* @param network - 'fast' or 'relaxed'
|
|
475
|
-
* @param modelId - model id (e.g. 'flux1-schnell-fp8')
|
|
476
|
-
* @param forceRefresh - force refresh cache
|
|
477
|
-
* @returns {Promise<{
|
|
478
|
-
* label: string;
|
|
479
|
-
* id: string;
|
|
480
|
-
* width: number;
|
|
481
|
-
* height: number;
|
|
482
|
-
* ratio: string;
|
|
483
|
-
* aspect: string;
|
|
484
|
-
* }[]>}
|
|
485
|
-
*/
|
|
486
|
-
async getSizePresets(network: SupernetType, modelId: string, forceRefresh = false) {
|
|
487
|
-
const key = `${network}-${modelId}`;
|
|
488
|
-
const cached = sizePresetCache.read(key);
|
|
489
|
-
if (cached && !forceRefresh) {
|
|
490
|
-
return cached;
|
|
491
|
-
}
|
|
492
|
-
const data = await this.client.socket.get<SizePreset[]>(
|
|
493
|
-
`/api/v1/size-presets/network/${network}/model/${modelId}`
|
|
494
|
-
);
|
|
495
|
-
sizePresetCache.write(key, data);
|
|
496
|
-
return data;
|
|
497
|
-
}
|
|
498
409
|
}
|
|
499
410
|
|
|
500
411
|
export default ProjectsApi;
|