@sogni-ai/sogni-client 4.0.0-alpha.21 → 4.0.0-alpha.22
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 +16 -0
- package/README.md +26 -15
- package/dist/Account/index.d.ts +15 -15
- package/dist/Account/index.js +15 -15
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js +0 -4
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/events.d.ts +10 -0
- package/dist/ApiClient/WebSocketClient/index.js +12 -2
- package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/index.js +1 -1
- package/dist/ApiClient/index.js.map +1 -1
- package/dist/Projects/Job.d.ts +12 -3
- package/dist/Projects/Job.js +50 -16
- package/dist/Projects/Job.js.map +1 -1
- package/dist/Projects/Project.d.ts +1 -0
- package/dist/Projects/Project.js +10 -3
- package/dist/Projects/Project.js.map +1 -1
- package/dist/Projects/createJobRequestMessage.js +105 -12
- package/dist/Projects/createJobRequestMessage.js.map +1 -1
- package/dist/Projects/index.d.ts +74 -5
- package/dist/Projects/index.js +337 -33
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/types/events.d.ts +5 -1
- package/dist/Projects/types/index.d.ts +113 -28
- package/dist/Projects/types/index.js +8 -0
- package/dist/Projects/types/index.js.map +1 -1
- package/dist/Projects/utils.d.ts +19 -1
- package/dist/Projects/utils.js +68 -0
- package/dist/Projects/utils.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/AuthManager/TokenAuthManager.js +0 -2
- package/dist/lib/AuthManager/TokenAuthManager.js.map +1 -1
- package/package.json +1 -1
- package/src/Account/index.ts +15 -15
- package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/index.ts +0 -4
- package/src/ApiClient/WebSocketClient/events.ts +11 -0
- package/src/ApiClient/WebSocketClient/index.ts +12 -2
- package/src/ApiClient/index.ts +1 -1
- package/src/Projects/Job.ts +50 -16
- package/src/Projects/Project.ts +12 -6
- package/src/Projects/createJobRequestMessage.ts +143 -33
- package/src/Projects/index.ts +351 -33
- package/src/Projects/types/events.ts +6 -0
- package/src/Projects/types/index.ts +141 -30
- package/src/Projects/utils.ts +66 -1
- package/src/index.ts +16 -4
- package/src/lib/AuthManager/TokenAuthManager.ts +0 -2
|
@@ -8,12 +8,20 @@ export interface SupportedModel {
|
|
|
8
8
|
id: string;
|
|
9
9
|
name: string;
|
|
10
10
|
SID: number;
|
|
11
|
+
/**
|
|
12
|
+
* Media type produced by this model: 'image' or 'video'
|
|
13
|
+
*/
|
|
14
|
+
media: 'image' | 'video';
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export interface AvailableModel {
|
|
14
18
|
id: string;
|
|
15
19
|
name: string;
|
|
16
20
|
workerCount: number;
|
|
21
|
+
/**
|
|
22
|
+
* Media type produced by this model: 'image' or 'video'
|
|
23
|
+
*/
|
|
24
|
+
media: 'image' | 'video';
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
export interface SizePreset {
|
|
@@ -29,15 +37,18 @@ export type { Sampler, Scheduler };
|
|
|
29
37
|
|
|
30
38
|
export { SupportedSamplers, SupportedSchedulers };
|
|
31
39
|
|
|
32
|
-
export type
|
|
33
|
-
|
|
34
|
-
export type InputImage = File | Buffer | Blob | boolean;
|
|
40
|
+
export type ImageOutputFormat = 'png' | 'jpg';
|
|
41
|
+
export type VideoOutputFormat = 'mp4';
|
|
35
42
|
|
|
36
|
-
export interface
|
|
43
|
+
export interface BaseProjectParams {
|
|
37
44
|
/**
|
|
38
45
|
* ID of the model to use, available models are available in the `availableModels` property of the `ProjectsApi` instance.
|
|
39
46
|
*/
|
|
40
47
|
modelId: string;
|
|
48
|
+
/**
|
|
49
|
+
* Number of media files to generate. Depending on project type, this can be number of images or number of videos.
|
|
50
|
+
*/
|
|
51
|
+
numberOfMedia: number;
|
|
41
52
|
/**
|
|
42
53
|
* Prompt for what to be created
|
|
43
54
|
*/
|
|
@@ -59,7 +70,7 @@ export interface ProjectParams {
|
|
|
59
70
|
*/
|
|
60
71
|
guidance: number;
|
|
61
72
|
/**
|
|
62
|
-
* Override current network type. Default value can be read from `
|
|
73
|
+
* Override current network type. Default value can be read from `sogni.account.currentAccount.network`
|
|
63
74
|
*/
|
|
64
75
|
network?: SupernetType;
|
|
65
76
|
/**
|
|
@@ -72,35 +83,89 @@ export interface ProjectParams {
|
|
|
72
83
|
*/
|
|
73
84
|
seed?: number;
|
|
74
85
|
/**
|
|
75
|
-
*
|
|
86
|
+
* Select which tokens to use for the project.
|
|
87
|
+
* If not specified, the Sogni token will be used.
|
|
88
|
+
*/
|
|
89
|
+
tokenType?: TokenType;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type InputMedia = File | Buffer | Blob | boolean;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Video-specific parameters for video workflows (t2v, i2v, s2v, animate).
|
|
96
|
+
* Only applicable when using video models like wan_v2.2-14b-fp8_t2v.
|
|
97
|
+
* Includes frame count, fps, shift, and reference assets (image, audio, video).
|
|
98
|
+
*/
|
|
99
|
+
export interface VideoProjectParams extends BaseProjectParams {
|
|
100
|
+
type: 'video';
|
|
101
|
+
/**
|
|
102
|
+
* Number of frames to generate
|
|
103
|
+
*/
|
|
104
|
+
frames?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Frames per second for output video
|
|
76
107
|
*/
|
|
77
|
-
|
|
108
|
+
fps?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Shift parameter for video diffusion models
|
|
111
|
+
*/
|
|
112
|
+
shift?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Reference image for WAN video workflows.
|
|
115
|
+
* Maps to: startImage (i2v), characterImage (animate), referenceImage (s2v)
|
|
116
|
+
*/
|
|
117
|
+
referenceImage?: InputMedia;
|
|
118
|
+
/**
|
|
119
|
+
* Optional end image for i2v interpolation workflows.
|
|
120
|
+
* When provided with referenceImage, the video will interpolate between the two images.
|
|
121
|
+
*/
|
|
122
|
+
referenceImageEnd?: InputMedia;
|
|
123
|
+
/**
|
|
124
|
+
* Reference audio for s2v (sound-to-video) workflows.
|
|
125
|
+
*/
|
|
126
|
+
referenceAudio?: InputMedia;
|
|
127
|
+
/**
|
|
128
|
+
* Reference video for animate workflows.
|
|
129
|
+
* Maps to: drivingVideo (animate-move), sourceVideo (animate-replace)
|
|
130
|
+
*/
|
|
131
|
+
referenceVideo?: InputMedia;
|
|
132
|
+
/**
|
|
133
|
+
* Output video width. Only used if `sizePreset` is "custom"
|
|
134
|
+
*/
|
|
135
|
+
width?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Output video height. Only used if `sizePreset` is "custom"
|
|
138
|
+
*/
|
|
139
|
+
height?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Output video format. For now only 'mp4' is supported, defaults to 'mp4'.
|
|
142
|
+
*/
|
|
143
|
+
outputFormat?: VideoOutputFormat;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface ImageProjectParams extends BaseProjectParams {
|
|
147
|
+
type: 'image';
|
|
78
148
|
/**
|
|
79
|
-
*
|
|
149
|
+
* Number of previews to generate. Note that previews affect project cost
|
|
150
|
+
*/
|
|
151
|
+
numberOfPreviews?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Starting image for img2img workflows.
|
|
80
154
|
* Supported types:
|
|
81
155
|
* `File` - file object from input[type=file]
|
|
82
156
|
* `Buffer` - Node.js buffer object with image data
|
|
83
157
|
* `Blob` - blob object with image data
|
|
84
158
|
* `true` - indicates that the image is already uploaded to the server
|
|
85
159
|
*/
|
|
86
|
-
startingImage?:
|
|
160
|
+
startingImage?: InputMedia;
|
|
87
161
|
/**
|
|
88
162
|
* How strong effect of starting image should be. From 0 to 1, default 0.5
|
|
89
163
|
*/
|
|
90
164
|
startingImageStrength?: number;
|
|
91
165
|
/**
|
|
92
166
|
* Context images for Flux Kontext model. Flux Kontext support up to 2 context images.
|
|
93
|
-
* Supported types:
|
|
94
|
-
* `File` - file object from input[type=file]
|
|
95
|
-
* `Buffer` - Node.js buffer object with image data
|
|
96
|
-
* `Blob` - blob object with image data
|
|
97
|
-
* `true` - indicates that the image is already uploaded to the server
|
|
98
|
-
*/
|
|
99
|
-
contextImages?: InputImage[];
|
|
100
|
-
/**
|
|
101
|
-
* Number of previews to generate. Note that previews affect project cost\
|
|
102
167
|
*/
|
|
103
|
-
|
|
168
|
+
contextImages?: InputMedia[];
|
|
104
169
|
/**
|
|
105
170
|
* Scheduler to use
|
|
106
171
|
*/
|
|
@@ -111,7 +176,7 @@ export interface ProjectParams {
|
|
|
111
176
|
scheduler?: Scheduler;
|
|
112
177
|
/**
|
|
113
178
|
* Size preset ID to use. You can query available size presets
|
|
114
|
-
* from `
|
|
179
|
+
* from `sogni.projects.sizePresets(network, modelId)`
|
|
115
180
|
*/
|
|
116
181
|
sizePreset?: 'custom' | string;
|
|
117
182
|
/**
|
|
@@ -127,25 +192,58 @@ export interface ProjectParams {
|
|
|
127
192
|
*/
|
|
128
193
|
controlNet?: ControlNetParams;
|
|
129
194
|
/**
|
|
130
|
-
*
|
|
131
|
-
* If not specified, the Sogni token will be used.
|
|
132
|
-
*/
|
|
133
|
-
tokenType?: TokenType;
|
|
134
|
-
/**
|
|
135
|
-
* Output image format. Can be 'png' or 'jpg'.
|
|
136
|
-
* If not specified, 'png' will be used.
|
|
195
|
+
* Output format. Can be 'png' or 'jpg'. Defaults to 'png'.
|
|
137
196
|
*/
|
|
138
|
-
outputFormat?:
|
|
197
|
+
outputFormat?: ImageOutputFormat;
|
|
139
198
|
}
|
|
140
199
|
|
|
200
|
+
export type ProjectParams = ImageProjectParams | VideoProjectParams;
|
|
201
|
+
|
|
202
|
+
export function isVideoParams(params: ProjectParams): params is VideoProjectParams {
|
|
203
|
+
return params.type === 'video';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function isImageParams(params: ProjectParams): params is ImageProjectParams {
|
|
207
|
+
return params.type === 'image';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Supported audio formats
|
|
212
|
+
*/
|
|
213
|
+
export type AudioFormat = 'm4a' | 'mp3' | 'wav';
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Supported video formats
|
|
217
|
+
*/
|
|
218
|
+
export type VideoFormat = 'mp4' | 'mov';
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Parameters for image asset URL requests (upload/download)
|
|
222
|
+
*/
|
|
141
223
|
export type ImageUrlParams = {
|
|
142
224
|
imageId: string;
|
|
143
225
|
jobId: string;
|
|
144
|
-
type:
|
|
145
|
-
|
|
226
|
+
type:
|
|
227
|
+
| 'preview'
|
|
228
|
+
| 'complete'
|
|
229
|
+
| 'startingImage'
|
|
230
|
+
| 'cnImage'
|
|
231
|
+
| 'contextImage1'
|
|
232
|
+
| 'contextImage2'
|
|
233
|
+
| 'referenceImage'
|
|
234
|
+
| 'referenceImageEnd';
|
|
146
235
|
startContentType?: string;
|
|
147
236
|
};
|
|
148
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Parameters for media asset URL requests (video/audio upload/download)
|
|
240
|
+
*/
|
|
241
|
+
export type MediaUrlParams = {
|
|
242
|
+
id?: string;
|
|
243
|
+
jobId: string;
|
|
244
|
+
type: 'complete' | 'preview' | 'referenceAudio' | 'referenceVideo';
|
|
245
|
+
};
|
|
246
|
+
|
|
149
247
|
export interface EstimateRequest {
|
|
150
248
|
/**
|
|
151
249
|
* Network to use. Can be 'fast' or 'relaxed'
|
|
@@ -223,3 +321,16 @@ export interface CostEstimation {
|
|
|
223
321
|
}
|
|
224
322
|
|
|
225
323
|
export type EnhancementStrength = 'light' | 'medium' | 'heavy';
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Video workflow types for WAN models
|
|
327
|
+
*/
|
|
328
|
+
export type VideoWorkflowType = 't2v' | 'i2v' | 's2v' | 'animate-move' | 'animate-replace' | null;
|
|
329
|
+
|
|
330
|
+
export type AssetRequirement = 'required' | 'optional' | 'forbidden';
|
|
331
|
+
|
|
332
|
+
export type VideoAssetKey =
|
|
333
|
+
| 'referenceImage'
|
|
334
|
+
| 'referenceImageEnd'
|
|
335
|
+
| 'referenceAudio'
|
|
336
|
+
| 'referenceVideo';
|
package/src/Projects/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnhancementStrength } from './types';
|
|
1
|
+
import { AssetRequirement, EnhancementStrength, VideoAssetKey, VideoWorkflowType } from './types';
|
|
2
2
|
|
|
3
3
|
export function getEnhacementStrength(strength: EnhancementStrength): number {
|
|
4
4
|
switch (strength) {
|
|
@@ -10,3 +10,68 @@ export function getEnhacementStrength(strength: EnhancementStrength): number {
|
|
|
10
10
|
return 0.35;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check if a model ID is for a video workflow.
|
|
16
|
+
* This is consistent with the `media` property returned by the models list API.
|
|
17
|
+
* Video models produce MP4 output; image models produce PNG/JPG output.
|
|
18
|
+
*/
|
|
19
|
+
export function isVideoModel(modelId: string): boolean {
|
|
20
|
+
return modelId.startsWith('wan_');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get the video workflow type from a model ID.
|
|
25
|
+
* Returns null for non-video models.
|
|
26
|
+
*/
|
|
27
|
+
export function getVideoWorkflowType(modelId: string): VideoWorkflowType {
|
|
28
|
+
if (!modelId || !modelId.startsWith('wan_')) return null;
|
|
29
|
+
if (modelId.includes('_i2v')) return 'i2v';
|
|
30
|
+
if (modelId.includes('_s2v')) return 's2v';
|
|
31
|
+
if (modelId.includes('_animate-move')) return 'animate-move';
|
|
32
|
+
if (modelId.includes('_animate-replace')) return 'animate-replace';
|
|
33
|
+
if (modelId.includes('_t2v')) return 't2v';
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Asset requirements for each video workflow type.
|
|
39
|
+
* - required: Must be provided
|
|
40
|
+
* - optional: Can be provided
|
|
41
|
+
* - forbidden: Must NOT be provided
|
|
42
|
+
*/
|
|
43
|
+
export const VIDEO_WORKFLOW_ASSETS: Record<
|
|
44
|
+
NonNullable<VideoWorkflowType>,
|
|
45
|
+
Record<VideoAssetKey, AssetRequirement>
|
|
46
|
+
> = {
|
|
47
|
+
t2v: {
|
|
48
|
+
referenceImage: 'forbidden',
|
|
49
|
+
referenceImageEnd: 'forbidden',
|
|
50
|
+
referenceAudio: 'forbidden',
|
|
51
|
+
referenceVideo: 'forbidden'
|
|
52
|
+
},
|
|
53
|
+
i2v: {
|
|
54
|
+
referenceImage: 'required',
|
|
55
|
+
referenceImageEnd: 'optional',
|
|
56
|
+
referenceAudio: 'forbidden',
|
|
57
|
+
referenceVideo: 'forbidden'
|
|
58
|
+
},
|
|
59
|
+
s2v: {
|
|
60
|
+
referenceImage: 'required',
|
|
61
|
+
referenceAudio: 'required',
|
|
62
|
+
referenceImageEnd: 'forbidden',
|
|
63
|
+
referenceVideo: 'forbidden'
|
|
64
|
+
},
|
|
65
|
+
'animate-move': {
|
|
66
|
+
referenceImage: 'required',
|
|
67
|
+
referenceVideo: 'required',
|
|
68
|
+
referenceImageEnd: 'forbidden',
|
|
69
|
+
referenceAudio: 'forbidden'
|
|
70
|
+
},
|
|
71
|
+
'animate-replace': {
|
|
72
|
+
referenceImage: 'required',
|
|
73
|
+
referenceVideo: 'required',
|
|
74
|
+
referenceImageEnd: 'forbidden',
|
|
75
|
+
referenceAudio: 'forbidden'
|
|
76
|
+
}
|
|
77
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -14,12 +14,18 @@ import Job, { JobStatus } from './Projects/Job';
|
|
|
14
14
|
import Project, { ProjectStatus } from './Projects/Project';
|
|
15
15
|
import {
|
|
16
16
|
AvailableModel,
|
|
17
|
-
|
|
17
|
+
ImageProjectParams,
|
|
18
|
+
ImageOutputFormat,
|
|
18
19
|
ProjectParams,
|
|
19
20
|
Sampler,
|
|
20
21
|
Scheduler,
|
|
21
22
|
SupportedSamplers,
|
|
22
|
-
SupportedSchedulers
|
|
23
|
+
SupportedSchedulers,
|
|
24
|
+
VideoProjectParams,
|
|
25
|
+
AudioFormat,
|
|
26
|
+
VideoFormat,
|
|
27
|
+
VideoOutputFormat,
|
|
28
|
+
VideoWorkflowType
|
|
23
29
|
} from './Projects/types';
|
|
24
30
|
// Stats API
|
|
25
31
|
import StatsApi from './Stats';
|
|
@@ -30,18 +36,24 @@ import { CookieAuthManager, TokenAuthData, TokenAuthManager } from './lib/AuthMa
|
|
|
30
36
|
import { MeData } from './Account/types';
|
|
31
37
|
|
|
32
38
|
export type {
|
|
39
|
+
AudioFormat,
|
|
33
40
|
AvailableModel,
|
|
34
41
|
ErrorData,
|
|
42
|
+
ImageProjectParams,
|
|
43
|
+
ImageOutputFormat,
|
|
35
44
|
JobStatus,
|
|
36
45
|
Logger,
|
|
37
46
|
LogLevel,
|
|
38
|
-
OutputFormat,
|
|
39
47
|
ProjectParams,
|
|
40
48
|
ProjectStatus,
|
|
41
49
|
Sampler,
|
|
42
50
|
SupernetType,
|
|
43
51
|
Scheduler,
|
|
44
|
-
TokenType
|
|
52
|
+
TokenType,
|
|
53
|
+
VideoFormat,
|
|
54
|
+
VideoOutputFormat,
|
|
55
|
+
VideoProjectParams,
|
|
56
|
+
VideoWorkflowType
|
|
45
57
|
};
|
|
46
58
|
|
|
47
59
|
export { ApiError, CurrentAccount, Job, Project, SupportedSamplers, SupportedSchedulers };
|
|
@@ -46,7 +46,6 @@ class TokenAuthManager extends AuthManagerBase<TokenAuthData | null> {
|
|
|
46
46
|
const { expiresAt } = decodeToken(token);
|
|
47
47
|
if (expiresAt > new Date()) {
|
|
48
48
|
this._updateTokens({ token, refreshToken });
|
|
49
|
-
this.emit('updated', true);
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -55,7 +54,6 @@ class TokenAuthManager extends AuthManagerBase<TokenAuthData | null> {
|
|
|
55
54
|
const { expiresAt: refreshExpiresAt } = decodeRefreshToken(refreshToken);
|
|
56
55
|
this._refreshTokenExpiresAt = refreshExpiresAt;
|
|
57
56
|
await this._renewTokenSafe();
|
|
58
|
-
this.emit('updated', true);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
clear() {
|