@sogni-ai/sogni-client 4.0.0-alpha.4 → 4.0.0-alpha.41

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 (95) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/README.md +262 -31
  3. package/dist/Account/index.d.ts +18 -16
  4. package/dist/Account/index.js +31 -20
  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 +36 -8
  25. package/dist/Projects/Project.js.map +1 -1
  26. package/dist/Projects/createJobRequestMessage.js +161 -15
  27. package/dist/Projects/createJobRequestMessage.js.map +1 -1
  28. package/dist/Projects/index.d.ts +112 -11
  29. package/dist/Projects/index.js +478 -47
  30. package/dist/Projects/index.js.map +1 -1
  31. package/dist/Projects/types/ComfySamplerParams.d.ts +28 -0
  32. package/dist/Projects/types/ComfySamplerParams.js +36 -0
  33. package/dist/Projects/types/ComfySamplerParams.js.map +1 -0
  34. package/dist/Projects/types/ComfySchedulerParams.d.ts +17 -0
  35. package/dist/Projects/types/ComfySchedulerParams.js +23 -0
  36. package/dist/Projects/types/ComfySchedulerParams.js.map +1 -0
  37. package/dist/Projects/types/EstimationResponse.d.ts +2 -0
  38. package/dist/Projects/types/ForgeSamplerParams.d.ts +27 -0
  39. package/dist/Projects/types/ForgeSamplerParams.js +39 -0
  40. package/dist/Projects/types/ForgeSamplerParams.js.map +1 -0
  41. package/dist/Projects/types/ForgeSchedulerParams.d.ts +17 -0
  42. package/dist/Projects/types/ForgeSchedulerParams.js +28 -0
  43. package/dist/Projects/types/ForgeSchedulerParams.js.map +1 -0
  44. package/dist/Projects/types/events.d.ts +5 -1
  45. package/dist/Projects/types/index.d.ts +189 -40
  46. package/dist/Projects/types/index.js +17 -0
  47. package/dist/Projects/types/index.js.map +1 -1
  48. package/dist/Projects/utils.d.ts +19 -1
  49. package/dist/Projects/utils.js +68 -0
  50. package/dist/Projects/utils.js.map +1 -1
  51. package/dist/index.d.ts +12 -4
  52. package/dist/index.js +14 -4
  53. package/dist/index.js.map +1 -1
  54. package/dist/lib/AuthManager/TokenAuthManager.js +0 -2
  55. package/dist/lib/AuthManager/TokenAuthManager.js.map +1 -1
  56. package/dist/lib/DataEntity.js +4 -2
  57. package/dist/lib/DataEntity.js.map +1 -1
  58. package/dist/lib/RestClient.js +15 -2
  59. package/dist/lib/RestClient.js.map +1 -1
  60. package/dist/lib/validation.d.ts +26 -2
  61. package/dist/lib/validation.js +96 -11
  62. package/dist/lib/validation.js.map +1 -1
  63. package/package.json +4 -4
  64. package/src/Account/index.ts +30 -19
  65. package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.ts +426 -0
  66. package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/index.ts +237 -0
  67. package/src/ApiClient/WebSocketClient/events.ts +14 -0
  68. package/src/ApiClient/WebSocketClient/index.ts +15 -5
  69. package/src/ApiClient/WebSocketClient/types.ts +16 -0
  70. package/src/ApiClient/index.ts +30 -8
  71. package/src/Projects/Job.ts +97 -16
  72. package/src/Projects/Project.ts +44 -11
  73. package/src/Projects/createJobRequestMessage.ts +211 -37
  74. package/src/Projects/index.ts +507 -51
  75. package/src/Projects/types/ComfySamplerParams.ts +34 -0
  76. package/src/Projects/types/ComfySchedulerParams.ts +21 -0
  77. package/src/Projects/types/EstimationResponse.ts +2 -0
  78. package/src/Projects/types/ForgeSamplerParams.ts +37 -0
  79. package/src/Projects/types/ForgeSchedulerParams.ts +26 -0
  80. package/src/Projects/types/events.ts +6 -0
  81. package/src/Projects/types/index.ts +227 -41
  82. package/src/Projects/utils.ts +66 -1
  83. package/src/index.ts +60 -8
  84. package/src/lib/AuthManager/TokenAuthManager.ts +0 -2
  85. package/src/lib/DataEntity.ts +4 -2
  86. package/src/lib/RestClient.ts +16 -2
  87. package/src/lib/validation.ts +111 -14
  88. package/dist/Projects/types/SamplerParams.d.ts +0 -15
  89. package/dist/Projects/types/SamplerParams.js +0 -21
  90. package/dist/Projects/types/SamplerParams.js.map +0 -1
  91. package/dist/Projects/types/SchedulerParams.d.ts +0 -13
  92. package/dist/Projects/types/SchedulerParams.js +0 -19
  93. package/dist/Projects/types/SchedulerParams.js.map +0 -1
  94. package/src/Projects/types/SamplerParams.ts +0 -19
  95. package/src/Projects/types/SchedulerParams.ts +0 -17
@@ -1,5 +1,5 @@
1
1
  import ApiGroup, { ApiConfig } from '../ApiGroup';
2
- import { AvailableModel, EnhancementStrength, EstimateRequest, ImageUrlParams, ProjectParams, SizePreset, SupportedModel } from './types';
2
+ import { AvailableModel, EnhancementStrength, EstimateRequest, ImageUrlParams, MediaUrlParams, CostEstimation, ProjectParams, SizePreset, SupportedModel, VideoEstimateRequest } from './types';
3
3
  import Project from './Project';
4
4
  import { ProjectApiEvents } from './types/events';
5
5
  import { RawProject } from './types/RawProject';
@@ -10,11 +10,26 @@ declare class ProjectsApi extends ApiGroup<ProjectApiEvents> {
10
10
  private projects;
11
11
  private _supportedModels;
12
12
  get availableModels(): AvailableModel[];
13
+ /**
14
+ * Check if a model produces video output using the cached models list.
15
+ * Uses the `media` property from the models API when available,
16
+ * falls back to model ID prefix check if models aren't loaded yet.
17
+ */
18
+ isVideoModelId(modelId: string): boolean;
13
19
  constructor(config: ApiConfig);
20
+ /**
21
+ * Retrieves a list of projects created and tracked by this SogniClient instance.
22
+ *
23
+ * Note: When a project is finished, it will be removed from this list after 30 seconds
24
+ *
25
+ * @return {Array} A copy of the array containing the tracked projects.
26
+ */
27
+ get trackedProjects(): Project[];
14
28
  private handleChangeNetwork;
15
29
  private handleSwarmModels;
16
30
  private handleJobState;
17
31
  private handleJobProgress;
32
+ private handleJobETA;
18
33
  private handleJobResult;
19
34
  private handleJobError;
20
35
  private handleProjectEvent;
@@ -28,10 +43,12 @@ declare class ProjectsApi extends ApiGroup<ProjectApiEvents> {
28
43
  waitForModels(timeout?: number): Promise<AvailableModel[]>;
29
44
  /**
30
45
  * Send new project request to the network. Returns project instance which can be used to track
31
- * progress and get resulting images.
46
+ * progress and get resulting images or videos.
32
47
  * @param data
33
48
  */
34
49
  create(data: ProjectParams): Promise<Project>;
50
+ private _processImageAssets;
51
+ private _processVideoAssets;
35
52
  /**
36
53
  * Get project by id, this API returns project data from the server only if the project is
37
54
  * completed or failed. If the project is still processing, it will throw 404 error.
@@ -50,35 +67,87 @@ declare class ProjectsApi extends ApiGroup<ProjectApiEvents> {
50
67
  private uploadCNImage;
51
68
  private uploadContextImage;
52
69
  /**
53
- * Estimate project cost
70
+ * Upload reference image for WAN video workflows
71
+ * @internal
54
72
  */
55
- estimateCost({ network, tokenType, model, imageCount, stepCount, previewCount, cnEnabled, startingImageStrength, width, height, sizePreset, guidance, scheduler, contextImages }: EstimateRequest): Promise<{
56
- token: string;
57
- usd: string;
58
- }>;
59
- estimateEnhancementCost(strength: EnhancementStrength, tokenType?: TokenType): Promise<{
73
+ private uploadReferenceImage;
74
+ /**
75
+ * Upload reference image end for i2v interpolation
76
+ * @internal
77
+ */
78
+ private uploadReferenceImageEnd;
79
+ /**
80
+ * Upload reference audio for s2v workflows
81
+ * Supported formats: mp3, m4a, wav
82
+ * @internal
83
+ */
84
+ private uploadReferenceAudio;
85
+ /**
86
+ * Upload reference video for animate workflows
87
+ * Supported formats: mp4, mov
88
+ * @internal
89
+ */
90
+ private uploadReferenceVideo;
91
+ /**
92
+ * Estimate image project cost
93
+ */
94
+ estimateCost({ network, tokenType, model, imageCount, stepCount, previewCount, cnEnabled, startingImageStrength, width, height, sizePreset, guidance, sampler, contextImages }: EstimateRequest): Promise<CostEstimation>;
95
+ /**
96
+ * Estimate image enhancement cost
97
+ * @param strength
98
+ * @param tokenType
99
+ */
100
+ estimateEnhancementCost(strength: EnhancementStrength, tokenType?: TokenType): Promise<CostEstimation>;
101
+ /**
102
+ * Estimates the cost of generating a video based on the provided parameters.
103
+ *
104
+ * @param {VideoEstimateRequest} params - The parameters required for video cost estimation. This includes:
105
+ * - tokenType: The type of token to be used for generation.
106
+ * - model: The model to be used for video generation.
107
+ * - width: The width of the video in pixels.
108
+ * - height: The height of the video in pixels.
109
+ * - frames: The total number of frames in the video.
110
+ * - fps: The frames per second for the video.
111
+ * - steps: Number of steps.
112
+ * @return {Promise<Object>} Returns an object containing the estimated costs for the video in different units:
113
+ * - token: Cost in tokens.
114
+ * - usd: Cost in USD.
115
+ * - spark: Cost in Spark.
116
+ * - sogni: Cost in Sogni.
117
+ */
118
+ estimateVideoCost(params: VideoEstimateRequest): Promise<{
60
119
  token: string;
61
120
  usd: string;
121
+ spark: string;
122
+ sogni: string;
62
123
  }>;
63
124
  /**
64
125
  * Get upload URL for image
65
126
  * @internal
66
- * @param params
67
127
  */
68
128
  uploadUrl(params: ImageUrlParams): Promise<string>;
69
129
  /**
70
130
  * Get download URL for image
71
131
  * @internal
72
- * @param params
73
132
  */
74
133
  downloadUrl(params: ImageUrlParams): Promise<string>;
134
+ /**
135
+ * Get upload URL for media (video/audio)
136
+ * @internal
137
+ */
138
+ mediaUploadUrl(params: MediaUrlParams): Promise<string>;
139
+ /**
140
+ * Get download URL for media (video/audio)
141
+ * @internal
142
+ */
143
+ mediaDownloadUrl(params: MediaUrlParams): Promise<string>;
75
144
  getSupportedModels(forceRefresh?: boolean): Promise<SupportedModel[]>;
76
145
  /**
77
146
  * Get supported size presets for the model and network. Size presets are cached for 10 minutes.
78
147
  *
79
148
  * @example
80
149
  * ```ts
81
- * const presets = await client.projects.getSizePresets('fast', 'flux1-schnell-fp8');
150
+ * const presets = await sogni.projects.getSizePresets('fast', 'flux1-schnell-fp8');
82
151
  * console.log(presets);
83
152
  * ```
84
153
  *
@@ -95,11 +164,43 @@ declare class ProjectsApi extends ApiGroup<ProjectApiEvents> {
95
164
  * }[]>}
96
165
  */
97
166
  getSizePresets(network: SupernetType, modelId: string, forceRefresh?: boolean): Promise<SizePreset[]>;
167
+ /**
168
+ * Retrieves the video asset configuration for a given video model identifier.
169
+ * Validates whether the provided model ID corresponds to a video model. If it does,
170
+ * returns the appropriate video asset configuration based on the workflow type.
171
+ *
172
+ * @example Returned object for a model that implements image to video workflow:
173
+ * ```json
174
+ * {
175
+ * "workflowType": "i2v",
176
+ * "assets": {
177
+ * "referenceImage": "required",
178
+ * "referenceImageEnd": "optional",
179
+ * "referenceAudio": "forbidden",
180
+ * "referenceVideo": "forbidden"
181
+ * }
182
+ * }
183
+ * ```
184
+ *
185
+ * @param {string} modelId - The identifier of the video model to retrieve the configuration for.
186
+ * @return {Object} The video asset configuration object where key is asset field and value is
187
+ * either `required`, `forbidden` or `optional`. Returns `null` if no rules defined for the model.
188
+ * @throws {ApiError} Throws an error if the provided model ID is not a video model.
189
+ */
190
+ getVideoAssetConfig(modelId: string): Promise<{
191
+ workflowType: null;
192
+ assets?: undefined;
193
+ } | {
194
+ workflowType: "t2v" | "i2v" | "s2v" | "animate-move" | "animate-replace";
195
+ assets: Record<import("./types").VideoAssetKey, import("./types").AssetRequirement>;
196
+ }>;
98
197
  /**
99
198
  * Get available models and their worker counts. Normally, you would get list once you connect
100
199
  * to the server, but you can also call this method to get the list of available models manually.
101
200
  * @param network
102
201
  */
103
202
  getAvailableModels(network: SupernetType): Promise<AvailableModel[]>;
203
+ getSamplers(modelId: string): Promise<("euler" | "euler_ancestral" | "heun" | "dpmpp_2m" | "dpmpp_2m_sde" | "dpmpp_sde" | "dpmpp_3m_sde" | "uni_pc" | "lcm" | "lms" | "dpm_2" | "dpm_2_ancestral" | "dpm_fast" | "dpm_adaptive" | "dpmpp_2s_ancestral" | "ddpm" | "ddim" | "uni_pc_bh2" | "res_multistep" | "res_multistep_cfg_pp")[] | ("euler" | "euler_ancestral" | "heun" | "dpmpp_2m" | "dpmpp_2m_sde" | "dpmpp_sde" | "dpmpp_3m_sde" | "uni_pc" | "lcm" | "lms" | "dpm_2" | "dpm_2_ancestral" | "dpm_fast" | "dpm_adaptive" | "dpmpp_2s_ancestral" | "ddpm" | "dfs_sd3" | "dpm_pp" | "dpm_pp_sde" | "dpm_pp_2m" | "euler_a" | "pndm_plms")[]>;
204
+ getSchedulers(modelId: string): Promise<("simple" | "normal" | "karras" | "exponential" | "sgm_uniform" | "ddim_uniform" | "beta" | "linear_quadratic" | "kl_optimal" | "ddim" | "leading" | "linear")[]>;
104
205
  }
105
206
  export default ProjectsApi;