@sogni-ai/sogni-client 4.0.0-alpha.5 → 4.0.0-alpha.50

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 (109) hide show
  1. package/CHANGELOG.md +345 -0
  2. package/README.md +295 -58
  3. package/dist/Account/index.d.ts +18 -16
  4. package/dist/Account/index.js +42 -21
  5. package/dist/Account/index.js.map +1 -1
  6. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.d.ts +66 -0
  7. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.js +332 -0
  8. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.js.map +1 -0
  9. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.d.ts +28 -0
  10. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js +203 -0
  11. package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js.map +1 -0
  12. package/dist/ApiClient/WebSocketClient/events.d.ts +12 -0
  13. package/dist/ApiClient/WebSocketClient/index.d.ts +2 -2
  14. package/dist/ApiClient/WebSocketClient/index.js +13 -3
  15. package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
  16. package/dist/ApiClient/WebSocketClient/types.d.ts +13 -0
  17. package/dist/ApiClient/index.d.ts +4 -4
  18. package/dist/ApiClient/index.js +23 -4
  19. package/dist/ApiClient/index.js.map +1 -1
  20. package/dist/Projects/Job.d.ts +44 -4
  21. package/dist/Projects/Job.js +83 -16
  22. package/dist/Projects/Job.js.map +1 -1
  23. package/dist/Projects/Project.d.ts +18 -0
  24. package/dist/Projects/Project.js +38 -10
  25. package/dist/Projects/Project.js.map +1 -1
  26. package/dist/Projects/createJobRequestMessage.d.ts +2 -1
  27. package/dist/Projects/createJobRequestMessage.js +173 -14
  28. package/dist/Projects/createJobRequestMessage.js.map +1 -1
  29. package/dist/Projects/index.d.ts +114 -11
  30. package/dist/Projects/index.js +504 -47
  31. package/dist/Projects/index.js.map +1 -1
  32. package/dist/Projects/types/ComfySamplerParams.d.ts +0 -0
  33. package/dist/Projects/types/ComfySamplerParams.js +2 -0
  34. package/dist/Projects/types/ComfySamplerParams.js.map +1 -0
  35. package/dist/Projects/types/EstimationResponse.d.ts +2 -0
  36. package/dist/Projects/types/ModelOptions.d.ts +31 -0
  37. package/dist/Projects/types/ModelOptions.js +56 -0
  38. package/dist/Projects/types/ModelOptions.js.map +1 -0
  39. package/dist/Projects/types/ModelTiersRaw.d.ts +67 -0
  40. package/dist/Projects/types/ModelTiersRaw.js +15 -0
  41. package/dist/Projects/types/ModelTiersRaw.js.map +1 -0
  42. package/dist/Projects/types/events.d.ts +5 -1
  43. package/dist/Projects/types/index.d.ts +201 -42
  44. package/dist/Projects/types/index.js +8 -0
  45. package/dist/Projects/types/index.js.map +1 -1
  46. package/dist/Projects/utils/index.d.ts +20 -0
  47. package/dist/Projects/utils/index.js +82 -0
  48. package/dist/Projects/utils/index.js.map +1 -0
  49. package/dist/Projects/utils/samplers.d.ts +6 -0
  50. package/dist/Projects/utils/samplers.js +39 -0
  51. package/dist/Projects/utils/samplers.js.map +1 -0
  52. package/dist/Projects/utils/scheduler.d.ts +6 -0
  53. package/dist/Projects/utils/scheduler.js +30 -0
  54. package/dist/Projects/utils/scheduler.js.map +1 -0
  55. package/dist/index.d.ts +11 -3
  56. package/dist/index.js +8 -3
  57. package/dist/index.js.map +1 -1
  58. package/dist/lib/AuthManager/TokenAuthManager.js +0 -2
  59. package/dist/lib/AuthManager/TokenAuthManager.js.map +1 -1
  60. package/dist/lib/DataEntity.js +4 -2
  61. package/dist/lib/DataEntity.js.map +1 -1
  62. package/dist/lib/RestClient.js +15 -2
  63. package/dist/lib/RestClient.js.map +1 -1
  64. package/dist/lib/{utils.js → utils/index.js} +1 -1
  65. package/dist/lib/utils/index.js.map +1 -0
  66. package/dist/lib/validation.d.ts +31 -2
  67. package/dist/lib/validation.js +80 -13
  68. package/dist/lib/validation.js.map +1 -1
  69. package/package.json +4 -4
  70. package/src/Account/index.ts +39 -20
  71. package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.ts +426 -0
  72. package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/index.ts +237 -0
  73. package/src/ApiClient/WebSocketClient/events.ts +14 -0
  74. package/src/ApiClient/WebSocketClient/index.ts +15 -5
  75. package/src/ApiClient/WebSocketClient/types.ts +16 -0
  76. package/src/ApiClient/index.ts +30 -8
  77. package/src/Projects/Job.ts +97 -16
  78. package/src/Projects/Project.ts +46 -13
  79. package/src/Projects/createJobRequestMessage.ts +234 -34
  80. package/src/Projects/index.ts +533 -51
  81. package/src/Projects/types/ComfySamplerParams.ts +0 -0
  82. package/src/Projects/types/EstimationResponse.ts +2 -0
  83. package/src/Projects/types/ModelOptions.ts +92 -0
  84. package/src/Projects/types/ModelTiersRaw.ts +86 -0
  85. package/src/Projects/types/events.ts +6 -0
  86. package/src/Projects/types/index.ts +235 -45
  87. package/src/Projects/utils/index.ts +77 -0
  88. package/src/Projects/utils/samplers.ts +36 -0
  89. package/src/Projects/utils/scheduler.ts +27 -0
  90. package/src/index.ts +36 -9
  91. package/src/lib/AuthManager/TokenAuthManager.ts +0 -2
  92. package/src/lib/DataEntity.ts +4 -2
  93. package/src/lib/RestClient.ts +16 -2
  94. package/src/lib/validation.ts +90 -17
  95. package/dist/Projects/types/SamplerParams.d.ts +0 -15
  96. package/dist/Projects/types/SamplerParams.js +0 -21
  97. package/dist/Projects/types/SamplerParams.js.map +0 -1
  98. package/dist/Projects/types/SchedulerParams.d.ts +0 -13
  99. package/dist/Projects/types/SchedulerParams.js +0 -19
  100. package/dist/Projects/types/SchedulerParams.js.map +0 -1
  101. package/dist/Projects/utils.d.ts +0 -2
  102. package/dist/Projects/utils.js +0 -14
  103. package/dist/Projects/utils.js.map +0 -1
  104. package/dist/lib/utils.js.map +0 -1
  105. package/src/Projects/types/SamplerParams.ts +0 -19
  106. package/src/Projects/types/SchedulerParams.ts +0 -17
  107. package/src/Projects/utils.ts +0 -12
  108. /package/dist/lib/{utils.d.ts → utils/index.d.ts} +0 -0
  109. /package/src/lib/{utils.ts → utils/index.ts} +0 -0
File without changes
@@ -14,6 +14,8 @@ export interface Job {
14
14
  costInRenderSec: string;
15
15
  costInUSD: string;
16
16
  costInToken: string;
17
+ costInSpark: string;
18
+ costInSogni: string;
17
19
  calculatedStepCount?: number;
18
20
  }
19
21
 
@@ -0,0 +1,92 @@
1
+ import { ComfyImageTier, ImageTier, NumericDefaults, VideoTier } from './ModelTiersRaw';
2
+ import { samplerValueToAlias } from '../utils/samplers';
3
+ import { schedulerValueToAlias } from '../utils/scheduler';
4
+
5
+ interface NumRange {
6
+ min: number;
7
+ max: number;
8
+ step: number;
9
+ default: number;
10
+ }
11
+
12
+ interface Options<T> {
13
+ allowed: T[];
14
+ default: T | null;
15
+ }
16
+
17
+ interface NumOptions {
18
+ options: number[];
19
+ default: number;
20
+ }
21
+
22
+ export interface ImageModelOptions {
23
+ type: 'image';
24
+ steps: NumRange;
25
+ guidance: NumRange;
26
+ scheduler: Options<string>;
27
+ sampler: Options<string>;
28
+ }
29
+
30
+ export interface VideoModelOptions {
31
+ type: 'video';
32
+ steps: NumRange;
33
+ guidance: NumRange;
34
+ fps: Options<number>;
35
+ sampler: Options<string>;
36
+ scheduler: Options<string>;
37
+ }
38
+
39
+ export type ModelOptions = ImageModelOptions | VideoModelOptions;
40
+
41
+ function mapRange(data: NumericDefaults): NumRange {
42
+ return {
43
+ min: data.min,
44
+ max: data.max,
45
+ step: data.decimals ? Math.pow(10, 0 - data.decimals) : data.step || 1,
46
+ default: data.default
47
+ };
48
+ }
49
+
50
+ function mapOptions<T>(data: Options<T> | undefined, mapper = (value: T) => value): Options<T> {
51
+ if (!data) {
52
+ return {
53
+ allowed: [],
54
+ default: null
55
+ };
56
+ }
57
+ return {
58
+ allowed: data.allowed.map(mapper),
59
+ default: data.default !== null ? mapper(data.default) : null
60
+ };
61
+ }
62
+
63
+ export function mapImageTier(tier: ImageTier): ImageModelOptions {
64
+ return {
65
+ type: 'image',
66
+ steps: mapRange(tier.steps),
67
+ guidance: mapRange(tier.guidance),
68
+ scheduler: mapOptions(tier.scheduler, schedulerValueToAlias),
69
+ sampler: mapOptions(tier.sampler, samplerValueToAlias)
70
+ };
71
+ }
72
+
73
+ export function mapComfyImageTier(tier: ComfyImageTier): ImageModelOptions {
74
+ return {
75
+ type: 'image',
76
+ steps: mapRange(tier.steps),
77
+ guidance: mapRange(tier.guidance),
78
+ scheduler: mapOptions(tier.comfyScheduler, schedulerValueToAlias),
79
+ sampler: mapOptions(tier.comfySampler, samplerValueToAlias)
80
+ };
81
+ }
82
+
83
+ export function mapVideoTier(tier: VideoTier): VideoModelOptions {
84
+ return {
85
+ type: 'video',
86
+ steps: mapRange(tier.steps),
87
+ guidance: mapRange(tier.guidance),
88
+ scheduler: mapOptions(tier.comfyScheduler, schedulerValueToAlias),
89
+ sampler: mapOptions(tier.comfySampler, samplerValueToAlias),
90
+ fps: tier.fps
91
+ };
92
+ }
@@ -0,0 +1,86 @@
1
+ export type ModelTiersRaw = Record<string, ModelTier>;
2
+
3
+ export type ModelTier = ImageTier | VideoTier | ComfyImageTier;
4
+
5
+ export interface ComfyImageTier {
6
+ benchmark: Benchmark;
7
+ comfySampler: StringDefaults;
8
+ comfyScheduler?: StringDefaults;
9
+ defaultSize: number;
10
+ guidance: NumericDefaults;
11
+ steps: NumericDefaults;
12
+ type: 'image';
13
+ }
14
+
15
+ export function isComfyImageTier(t: ModelTier): t is ComfyImageTier {
16
+ return 'type' in t && t.type === 'image';
17
+ }
18
+
19
+ export interface StringDefaults {
20
+ allowed: string[];
21
+ default: string;
22
+ }
23
+
24
+ export interface NumericDefaults {
25
+ min: number;
26
+ max: number;
27
+ decimals?: number;
28
+ default: number;
29
+ step?: number;
30
+ }
31
+
32
+ export interface ImageTier {
33
+ benchmark: Benchmark;
34
+ guidance: NumericDefaults;
35
+ modelFeeUSD?: number;
36
+ nickname?: string;
37
+ scheduler: StringDefaults;
38
+ steps: NumericDefaults;
39
+ sampler: StringDefaults;
40
+ }
41
+
42
+ export function isImageTier(t: ModelTier): t is ImageTier {
43
+ return !Object.prototype.hasOwnProperty.call(t, 'type');
44
+ }
45
+
46
+ export interface Benchmark {
47
+ sec: number;
48
+ secContext1?: number;
49
+ secContext2?: number;
50
+ secContext3?: number;
51
+ secCN: number;
52
+ secMaxPreviews: number;
53
+ }
54
+
55
+ export interface VideoTier {
56
+ audioDuration?: DurationDefaults;
57
+ audioStart?: DurationDefaults;
58
+ benchmark: Benchmark;
59
+ comfySampler: StringDefaults;
60
+ comfyScheduler: StringDefaults;
61
+ fps: NumericOptions;
62
+ frames: NumericDefaults;
63
+ guidance: NumericDefaults;
64
+ height: NumericDefaults;
65
+ shift: NumericDefaults;
66
+ steps: NumericDefaults;
67
+ type: 'video';
68
+ videoStart?: DurationDefaults;
69
+ width: NumericDefaults;
70
+ }
71
+
72
+ export function isVideoTier(t: ModelTier): t is VideoTier {
73
+ return 'type' in t && t.type === 'video';
74
+ }
75
+
76
+ export interface DurationDefaults {
77
+ min: number;
78
+ default: number;
79
+ }
80
+
81
+ export interface NumericOptions {
82
+ allowed: number[];
83
+ default: number;
84
+ }
85
+
86
+ export default ModelTiersRaw;
@@ -48,6 +48,11 @@ export interface JobProgress extends JobEventBase {
48
48
  stepCount: number;
49
49
  }
50
50
 
51
+ export interface JobETA extends JobEventBase {
52
+ type: 'jobETA';
53
+ etaSeconds: number;
54
+ }
55
+
51
56
  export interface JobPreview extends JobEventBase {
52
57
  type: 'preview';
53
58
  url: string;
@@ -75,6 +80,7 @@ export type JobEvent =
75
80
  | JobInitiating
76
81
  | JobStarted
77
82
  | JobProgress
83
+ | JobETA
78
84
  | JobPreview
79
85
  | JobCompleted
80
86
  | JobError;
@@ -1,19 +1,26 @@
1
1
  import { SupernetType } from '../../ApiClient/WebSocketClient/types';
2
2
  import { ControlNetParams } from './ControlNetParams';
3
3
  import { TokenType } from '../../types/token';
4
- import { Sampler } from './SamplerParams';
5
- import { Scheduler } from './SchedulerParams';
6
4
 
7
5
  export interface SupportedModel {
8
6
  id: string;
9
7
  name: string;
10
8
  SID: number;
9
+ tier: string;
10
+ /**
11
+ * Media type produced by this model: 'image' or 'video'
12
+ */
13
+ media: 'image' | 'video';
11
14
  }
12
15
 
13
16
  export interface AvailableModel {
14
17
  id: string;
15
18
  name: string;
16
19
  workerCount: number;
20
+ /**
21
+ * Media type produced by this model: 'image' or 'video'
22
+ */
23
+ media: 'image' | 'video';
17
24
  }
18
25
 
19
26
  export interface SizePreset {
@@ -25,17 +32,18 @@ export interface SizePreset {
25
32
  aspect: string;
26
33
  }
27
34
 
28
- export type { Sampler, Scheduler };
29
-
30
- export type OutputFormat = 'png' | 'jpg';
31
-
32
- export type InputImage = File | Buffer | Blob | boolean;
35
+ export type ImageOutputFormat = 'png' | 'jpg';
36
+ export type VideoOutputFormat = 'mp4';
33
37
 
34
- export interface ProjectParams {
38
+ export interface BaseProjectParams {
35
39
  /**
36
40
  * ID of the model to use, available models are available in the `availableModels` property of the `ProjectsApi` instance.
37
41
  */
38
42
  modelId: string;
43
+ /**
44
+ * Number of media files to generate. Depending on project type, this can be number of images or number of videos.
45
+ */
46
+ numberOfMedia: number;
39
47
  /**
40
48
  * Prompt for what to be created
41
49
  */
@@ -49,15 +57,17 @@ export interface ProjectParams {
49
57
  */
50
58
  stylePrompt: string;
51
59
  /**
52
- * Number of steps. For most Stable Diffusion models, optimal value is 20
60
+ * Number of steps. For most Stable Diffusion models, optimal value is 20.
53
61
  */
54
- steps: number;
62
+ steps?: number;
55
63
  /**
56
- * Guidance scale. For most Stable Diffusion models, optimal value is 7.5
64
+ * Guidance scale. For most Stable Diffusion models, optimal value is 7.5.
65
+ * For video models: Regular models range 0.7-8.0, LoRA version (lightx2v) range 0.7-1.6, step 0.01.
66
+ * This maps to `guidanceScale` in the keyFrame for both image and video models.
57
67
  */
58
- guidance: number;
68
+ guidance?: number;
59
69
  /**
60
- * Override current network type. Default value can be read from `client.account.currentAccount.network`
70
+ * Override current network type. Default value can be read from `sogni.account.currentAccount.network`
61
71
  */
62
72
  network?: SupernetType;
63
73
  /**
@@ -70,46 +80,146 @@ export interface ProjectParams {
70
80
  */
71
81
  seed?: number;
72
82
  /**
73
- * Number of images to generate
83
+ * Select which tokens to use for the project.
84
+ * If not specified, the Sogni token will be used.
74
85
  */
75
- numberOfImages: number;
86
+ tokenType?: TokenType;
87
+ }
88
+
89
+ export type InputMedia = File | Buffer | Blob | boolean;
90
+
91
+ /**
92
+ * Video-specific parameters for video workflows (t2v, i2v, s2v, animate).
93
+ * Only applicable when using video models like wan_v2.2-14b-fp8_t2v.
94
+ * Includes frame count, fps, shift, and reference assets (image, audio, video).
95
+ */
96
+ export interface VideoProjectParams extends BaseProjectParams {
97
+ type: 'video';
76
98
  /**
77
- * Generate images based on the starting image.
78
- * Supported types:
79
- * `File` - file object from input[type=file]
80
- * `Buffer` - Node.js buffer object with image data
81
- * `Blob` - blob object with image data
82
- * `true` - indicates that the image is already uploaded to the server
99
+ * Number of frames to generate
100
+ * @deprecated Use duration instead
83
101
  */
84
- startingImage?: InputImage;
102
+ frames?: number;
85
103
  /**
86
- * How strong effect of starting image should be. From 0 to 1, default 0.5
104
+ * Duration of the video in seconds. Supported range 1 to 10
87
105
  */
88
- startingImageStrength?: number;
106
+ duration?: number;
107
+ /**
108
+ * Frames per second for output video
109
+ */
110
+ fps?: number;
111
+ /**
112
+ * Shift parameter for video diffusion models.
113
+ * Controls motion intensity. Range: 1.0-8.0, step 0.1.
114
+ * Default: 8.0 for regular models, 5.0 for speed lora (lightx2v) except s2v and animate which use 8.0
115
+ */
116
+ shift?: number;
117
+ /**
118
+ * TeaCache optimization threshold for T2V and I2V models.
119
+ * Range: 0.0-1.0. 0.0 = disabled.
120
+ * Recommended: 0.15 for T2V (~1.5x speedup), 0.2 for I2V (conservative quality-focused)
121
+ */
122
+ teacacheThreshold?: number;
123
+ /**
124
+ * Reference image for WAN video workflows.
125
+ * Maps to: startImage (i2v), characterImage (animate), referenceImage (s2v)
126
+ */
127
+ referenceImage?: InputMedia;
128
+ /**
129
+ * Optional end image for i2v interpolation workflows.
130
+ * When provided with referenceImage, the video will interpolate between the two images.
131
+ */
132
+ referenceImageEnd?: InputMedia;
133
+ /**
134
+ * Reference audio for s2v (sound-to-video) workflows.
135
+ */
136
+ referenceAudio?: InputMedia;
137
+ /**
138
+ * Audio start position in seconds for s2v workflows.
139
+ * Specifies where to begin reading from the audio file.
140
+ * Default: 0
141
+ */
142
+ audioStart?: number;
143
+ /**
144
+ * Audio duration in seconds for s2v workflows.
145
+ * Specifies how many seconds of audio to use.
146
+ * If not provided, defaults to 30 seconds on the server.
147
+ */
148
+ audioDuration?: number;
149
+ /**
150
+ * Reference video for animate workflows.
151
+ * Maps to: drivingVideo (animate-move), sourceVideo (animate-replace)
152
+ */
153
+ referenceVideo?: InputMedia;
154
+ /**
155
+ * Video start position in seconds for animate workflows (animate-move, animate-replace).
156
+ * Specifies where to begin reading from the reference video file.
157
+ * Default: 0
158
+ */
159
+ videoStart?: number;
160
+ /**
161
+ * Output video width. Only used if `sizePreset` is "custom"
162
+ */
163
+ width?: number;
89
164
  /**
90
- * Context images for Flux Kontext model. Flux Kontext support up to 2 context images.
165
+ * Output video height. Only used if `sizePreset` is "custom"
166
+ */
167
+ height?: number;
168
+ /**
169
+ * Sampler, available options depend on the model. Use `sogni.projects.getModelOptions(modelId)`
170
+ * to get the list of available samplers.
171
+ */
172
+ sampler?: string;
173
+ /**
174
+ * Scheduler, available options depend on the model. Use `sogni.projects.getModelOptions(modelId)`
175
+ * to get the list of available schedulers.
176
+ */
177
+ scheduler?: string;
178
+ /**
179
+ * Output video format. For now only 'mp4' is supported, defaults to 'mp4'.
180
+ */
181
+ outputFormat?: VideoOutputFormat;
182
+ }
183
+
184
+ export interface ImageProjectParams extends BaseProjectParams {
185
+ type: 'image';
186
+ /**
187
+ * Number of previews to generate. Note that previews affect project cost
188
+ */
189
+ numberOfPreviews?: number;
190
+ /**
191
+ * Starting image for img2img workflows.
91
192
  * Supported types:
92
193
  * `File` - file object from input[type=file]
93
194
  * `Buffer` - Node.js buffer object with image data
94
195
  * `Blob` - blob object with image data
95
196
  * `true` - indicates that the image is already uploaded to the server
96
197
  */
97
- contextImages?: InputImage[];
198
+ startingImage?: InputMedia;
98
199
  /**
99
- * Number of previews to generate. Note that previews affect project cost\
200
+ * How strong effect of starting image should be. From 0 to 1, default 0.5
100
201
  */
101
- numberOfPreviews?: number;
202
+ startingImageStrength?: number;
203
+ /**
204
+ * Context images for multi-reference image generation.
205
+ * Flux.2 Dev supports up to 6 context images.
206
+ * Qwen Image Edit Plus supports up to 3 context images.
207
+ * Flux Kontext supports up to 2 context images.
208
+ */
209
+ contextImages?: InputMedia[];
102
210
  /**
103
- * Scheduler to use
211
+ * Sampler, available options depend on the model. Use `sogni.projects.getModelOptions(modelId)`
212
+ * to get the list of available samplers.
104
213
  */
105
- sampler?: Sampler;
214
+ sampler?: string;
106
215
  /**
107
- * Time step spacing method
216
+ * Scheduler, available options depend on the model. Use `sogni.projects.getModelOptions(modelId)`
217
+ * to get the list of available schedulers.
108
218
  */
109
- scheduler?: Scheduler;
219
+ scheduler?: string;
110
220
  /**
111
221
  * Size preset ID to use. You can query available size presets
112
- * from `client.projects.sizePresets(network, modelId)`
222
+ * from `sogni.projects.sizePresets(network, modelId)`
113
223
  */
114
224
  sizePreset?: 'custom' | string;
115
225
  /**
@@ -125,25 +235,62 @@ export interface ProjectParams {
125
235
  */
126
236
  controlNet?: ControlNetParams;
127
237
  /**
128
- * Select which tokens to use for the project.
129
- * If not specified, the Sogni token will be used.
130
- */
131
- tokenType?: TokenType;
132
- /**
133
- * Output image format. Can be 'png' or 'jpg'.
134
- * If not specified, 'png' will be used.
238
+ * Output format. Can be 'png' or 'jpg'. Defaults to 'png'.
135
239
  */
136
- outputFormat?: OutputFormat;
240
+ outputFormat?: ImageOutputFormat;
137
241
  }
138
242
 
243
+ export type ProjectParams = ImageProjectParams | VideoProjectParams;
244
+
245
+ export function isVideoParams(params: ProjectParams): params is VideoProjectParams {
246
+ return params.type === 'video';
247
+ }
248
+
249
+ export function isImageParams(params: ProjectParams): params is ImageProjectParams {
250
+ return params.type === 'image';
251
+ }
252
+
253
+ /**
254
+ * Supported audio formats
255
+ */
256
+ export type AudioFormat = 'm4a' | 'mp3' | 'wav';
257
+
258
+ /**
259
+ * Supported video formats
260
+ */
261
+ export type VideoFormat = 'mp4' | 'mov';
262
+
263
+ /**
264
+ * Parameters for image asset URL requests (upload/download)
265
+ */
139
266
  export type ImageUrlParams = {
140
267
  imageId: string;
141
268
  jobId: string;
142
- type: 'preview' | 'complete' | 'startingImage' | 'cnImage' | 'contextImage1' | 'contextImage2';
143
- // This seems to be unused currently
269
+ type:
270
+ | 'preview'
271
+ | 'complete'
272
+ | 'startingImage'
273
+ | 'cnImage'
274
+ | 'contextImage1'
275
+ | 'contextImage2'
276
+ | 'contextImage3'
277
+ | 'contextImage4'
278
+ | 'contextImage5'
279
+ | 'contextImage6'
280
+ | 'referenceImage'
281
+ | 'referenceImageEnd';
144
282
  startContentType?: string;
145
283
  };
146
284
 
285
+ /**
286
+ * Parameters for media asset URL requests (video/audio upload/download)
287
+ */
288
+ export type MediaUrlParams = {
289
+ id?: string;
290
+ jobId: string;
291
+ type: 'complete' | 'preview' | 'referenceAudio' | 'referenceVideo';
292
+ };
293
+
147
294
  export interface EstimateRequest {
148
295
  /**
149
296
  * Network to use. Can be 'fast' or 'relaxed'
@@ -196,9 +343,9 @@ export interface EstimateRequest {
196
343
  */
197
344
  guidance?: number;
198
345
  /**
199
- * Scheduler
346
+ * Sampler
200
347
  */
201
- scheduler?: Sampler;
348
+ sampler?: string;
202
349
  /**
203
350
  * Number of context images to use (for Flux Kontext).
204
351
  * Note that this parameter is ignored if `scheduler` is not provided
@@ -206,4 +353,47 @@ export interface EstimateRequest {
206
353
  contextImages?: number;
207
354
  }
208
355
 
356
+ export interface VideoEstimateRequest {
357
+ tokenType: TokenType;
358
+ model: string;
359
+ width: number;
360
+ height: number;
361
+ duration: number;
362
+ /**
363
+ * Number of frames to generate.
364
+ * @deprecated Use duration instead
365
+ */
366
+ frames?: number;
367
+ fps: number;
368
+ steps: number;
369
+ numberOfMedia: number;
370
+ }
371
+
372
+ /**
373
+ * Represents estimation of project cost in different currency formats
374
+ */
375
+ export interface CostEstimation {
376
+ /** Cost in selected token type */
377
+ token: string;
378
+ /** Cost in USD */
379
+ usd: string;
380
+ /** Cost in Spark Points */
381
+ spark: string;
382
+ /** Cost in Sogni tokens */
383
+ sogni: string;
384
+ }
385
+
209
386
  export type EnhancementStrength = 'light' | 'medium' | 'heavy';
387
+
388
+ /**
389
+ * Video workflow types for WAN models
390
+ */
391
+ export type VideoWorkflowType = 't2v' | 'i2v' | 's2v' | 'animate-move' | 'animate-replace' | null;
392
+
393
+ export type AssetRequirement = 'required' | 'optional' | 'forbidden';
394
+
395
+ export type VideoAssetKey =
396
+ | 'referenceImage'
397
+ | 'referenceImageEnd'
398
+ | 'referenceAudio'
399
+ | 'referenceVideo';
@@ -0,0 +1,77 @@
1
+ import { AssetRequirement, EnhancementStrength, VideoAssetKey, VideoWorkflowType } from '../types';
2
+
3
+ export function getEnhacementStrength(strength: EnhancementStrength): number {
4
+ switch (strength) {
5
+ case 'light':
6
+ return 0.15;
7
+ case 'heavy':
8
+ return 0.49;
9
+ default:
10
+ return 0.35;
11
+ }
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: 'optional',
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
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Maps display name formats (from API) to lowercase aliases.
3
+ * Used to normalize the allowed sampler list so users can use consistent aliases.
4
+ */
5
+ const SamplerDisplayToAlias: Record<string, string> = {
6
+ Euler: 'euler',
7
+ 'Euler a': 'euler_a',
8
+ 'Euler Ancestral': 'euler_ancestral',
9
+ Heun: 'heun',
10
+ 'DPM++ 2M': 'dpmpp_2m',
11
+ 'DPM++ 2M SDE': 'dpmpp_2m_sde',
12
+ 'DPM++ SDE': 'dpmpp_sde',
13
+ 'DPM++ 3M SDE': 'dpmpp_3m_sde',
14
+ UniPC: 'uni_pc',
15
+ 'LCM (Latent Consistency Model)': 'lcm',
16
+ LMS: 'lms',
17
+ 'DPM 2': 'dpm_2',
18
+ 'DPM 2 Ancestral': 'dpm_2_ancestral',
19
+ 'DPM Fast': 'dpm_fast',
20
+ 'DPM Adaptive': 'dpm_adaptive',
21
+ 'DPM++ 2S Ancestral': 'dpmpp_2s_ancestral',
22
+ DDPM: 'ddpm',
23
+ 'Discrete Flow Sampler (SD3)': 'dfs_sd3',
24
+ 'Discrete Flow Scheduler (SD3)': 'dfs_sd3',
25
+ 'DPM Solver Multistep (DPM-Solver++)': 'dpm_pp',
26
+ 'PNDM (Pseudo-linear multi-step)': 'pndm_plms'
27
+ };
28
+
29
+ /**
30
+ * Convert a sampler display name to its alias.
31
+ * If already an alias or unknown, returns unchanged.
32
+ * Used to normalize API tier data for consistent validation.
33
+ */
34
+ export function samplerValueToAlias(value: string): string {
35
+ return SamplerDisplayToAlias[value] || value;
36
+ }